Skip to content

Commit 2670a7f

Browse files
committed
util/info: tighten up error detection on key length
Fix CID 1435996: use the proper % type to render the size. Also use opal_output(), not fprintf(). For debug builds, abort without dumping core (dumping core is very unfriendly when running thousands of automated tests) -- the stderr output is sufficient to find the coding error. For non-debug builds, truncate the key and emit a warning that it almost certainly will not work properly. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent 2caf1bf commit 2670a7f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

opal/util/info_subscriber.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2007-2015 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2007-2018 Cisco Systems, Inc. All rights reserved
1414
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
1515
* Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights
1616
* reserved.
@@ -348,13 +348,19 @@ int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, char *key, char
348348
opal_list_t *list = NULL;
349349
opal_hash_table_t *table = &object->s_subscriber_table;
350350
opal_callback_list_item_t *callback_list_item;
351+
size_t max_len = OPAL_MAX_INFO_KEY - strlen(OPAL_INFO_SAVE_PREFIX);
351352

352-
if (strlen(key) > OPAL_MAX_INFO_KEY-strlen(OPAL_INFO_SAVE_PREFIX)) {
353-
fprintf(stderr, "DEVELOPER WARNING: Unexpected key length [%s]: "
354-
"OMPI internal callback keys are limited to %d chars\n",
355-
key, (int)(OPAL_MAX_INFO_KEY-strlen(OPAL_INFO_SAVE_PREFIX)));
353+
if (strlen(key) > max_len) {
354+
opal_output(0, "DEVELOPER WARNING: Unexpected MPI info key length [%s]: "
355+
"OMPI internal callback keys are limited to %" PRIsize_t " chars.",
356+
key, max_len);
356357
#if OPAL_ENABLE_DEBUG
357-
assert(!(strlen(key) > OPAL_MAX_INFO_KEY-strlen(OPAL_INFO_SAVE_PREFIX)));
358+
opal_output(0, "Aborting because this is a developer / debugging build. Go fix this error.");
359+
// Do not assert() / dump core. Just exit un-gracefully.
360+
exit(1);
361+
#else
362+
opal_output(0, "The \"%s\" MPI info key almost certainly will not work properly. You should inform an Open MPI developer about this.", key);
363+
key[max_len] = '\0';
358364
#endif
359365
}
360366

0 commit comments

Comments
 (0)