1515 * Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
1616 * Copyright (c) 2014-2017 Research Organization for Information Science
1717 * and Technology (RIST). All rights reserved.
18+ * Copyright (c) 2018 IBM Corporation. All rights reserved.
1819 * $COPYRIGHT$
1920 *
2021 * Additional copyrights may follow
@@ -203,7 +204,7 @@ int orte_util_nidmap_create(opal_pointer_array_t *pool, char **regex)
203204 char * node ;
204205 char prefix [ORTE_MAX_NODE_PREFIX ];
205206 int i , j , n , len , startnum , nodenum , numdigits ;
206- bool found , fullname ;
207+ bool found ;
207208 char * suffix , * sfx , * nodenames ;
208209 orte_regex_node_t * ndreg ;
209210 orte_regex_range_t * range , * rng ;
@@ -264,37 +265,32 @@ int orte_util_nidmap_create(opal_pointer_array_t *pool, char **regex)
264265 }
265266 }
266267 node = nptr -> name ;
267- /* determine this node's prefix by looking for first non-alpha char */
268- fullname = false;
268+ /* determine this node's prefix by looking for first digit char */
269269 len = strlen (node );
270270 startnum = -1 ;
271271 memset (prefix , 0 , ORTE_MAX_NODE_PREFIX );
272- numdigits = 0 ;
273272 for (i = 0 , j = 0 ; i < len ; i ++ ) {
274- if (!isalpha (node [i ])) {
275- /* found a non-alpha char */
276- if (!isdigit (node [i ])) {
277- /* if it is anything but a digit, we just use
278- * the entire name
279- */
280- fullname = true;
281- break ;
282- }
273+ /* valid hostname characters are ascii letters, digits and the '-' character. */
274+ if (isdigit (node [i ])) {
283275 /* count the size of the numeric field - but don't
284276 * add the digits to the prefix
285277 */
286- numdigits ++ ;
287278 if (startnum < 0 ) {
288279 /* okay, this defines end of the prefix */
289280 startnum = i ;
290281 }
291282 continue ;
292283 }
284+ /* this must be either an alpha, a '.', or '-' */
285+ if (!isalpha (node [i ]) && '-' != node [i ] && '.' != node [i ]) {
286+ orte_show_help ("help-regex.txt" , "regex:invalid-name" , true, node );
287+ return ORTE_ERR_SILENT ;
288+ }
293289 if (startnum < 0 ) {
294290 prefix [j ++ ] = node [i ];
295291 }
296292 }
297- if (fullname || startnum < 0 ) {
293+ if (startnum < 0 ) {
298294 /* can't compress this name - just add it to the list */
299295 ndreg = OBJ_NEW (orte_regex_node_t );
300296 ndreg -> prefix = strdup (node );
@@ -305,8 +301,10 @@ int orte_util_nidmap_create(opal_pointer_array_t *pool, char **regex)
305301 nodenum = strtol (& node [startnum ], & sfx , 10 );
306302 if (NULL != sfx ) {
307303 suffix = strdup (sfx );
304+ numdigits = (int )(sfx - & node [startnum ]);
308305 } else {
309306 suffix = NULL ;
307+ numdigits = (int )strlen (& node [startnum ]);
310308 }
311309 /* is this node name already on our list? */
312310 found = false;
0 commit comments