Skip to content

Commit 72baf57

Browse files
authored
Merge pull request #4748 from sam6258/regx_patch_3.0
nidmap reverse prefix patch
2 parents dea7b67 + 28d49dc commit 72baf57

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

orte/util/help-regex.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# All rights reserved.
1313
# Copyright (c) 2014 Research Organization for Information Science
1414
# and Technology (RIST). All rights reserved.
15+
# Copyright (c) 2017 Intel, Inc. All rights reserved.
1516
# $COPYRIGHT$
1617
#
1718
# Additional copyrights may follow
@@ -68,3 +69,18 @@ digits in the names:
6869
regexp: %s
6970

7071
Please contact the Open MPI help list for assistance.
72+
#
73+
[regex:invalid-name]
74+
While trying to create a regular expression of the node names
75+
used in this application, the regex parser has detected the
76+
presence of an illegal character in the following node name:
77+
78+
node: %s
79+
80+
Node names must be composed of a combination of ascii letters,
81+
digits, dots, and the hyphen ('-') character. See the following
82+
for an explanation:
83+
84+
https://en.wikipedia.org/wiki/Hostname
85+
86+
Please correct the error and try again.

orte/util/nidmap.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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

Comments
 (0)