Skip to content

Commit 4d2cb93

Browse files
committed
Don't use opal_argv_join_range() for opal_var_dump_color_keys
The join function was initially used for convinience, to print the valid keys. This was wrong, because opal_var_dump_color_keys is not a NULL-terminated array. This commit replaces it with an asprintf loop. Thanks to Niv Shpak (@nivShpak) for reporting this and identifying the root cause. Signed-off-by: George Katevenis <[email protected]>
1 parent a8fbb4d commit 4d2cb93

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

opal/runtime/opal_params_core.c

+22-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Copyright (c) 2018-2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
2626
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
2727
* Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
28-
* Copyright (c) 2022 Computer Architecture and VLSI Systems (CARV)
28+
* Copyright (c) 2022-2023 Computer Architecture and VLSI Systems (CARV)
2929
* Laboratory, ICS Forth. All rights reserved.
3030
* $COPYRIGHT$
3131
*
@@ -240,9 +240,16 @@ int opal_register_util_params(void)
240240

241241
/* Var-dump color */
242242

243-
string = opal_argv_join_range(opal_var_dump_color_keys, 0, OPAL_VAR_DUMP_COLOR_KEY_COUNT, ',');
244-
if (NULL == string) {
245-
return OPAL_ERR_OUT_OF_RESOURCE;
243+
string = NULL;
244+
245+
for (int i = 0; i < OPAL_VAR_DUMP_COLOR_KEY_COUNT; i++) {
246+
ret = opal_asprintf(&tmp, "%s%s%s", (i > 0 ? string : ""),
247+
(i > 0 ? "," : ""), opal_var_dump_color_keys[i]);
248+
free(string);
249+
string = tmp;
250+
if (0 > ret) {
251+
return OPAL_ERR_OUT_OF_RESOURCE;
252+
}
246253
}
247254

248255
ret = opal_asprintf(&tmp, "The colors to use when dumping MCA vars with color "
@@ -474,10 +481,17 @@ static int parse_color_string(char *color_string, char **key_names,
474481
}
475482

476483
if (!key_found) {
477-
char *valid_keys = opal_argv_join_range(key_names, 0, key_count, ',');
478-
if (NULL == valid_keys) {
479-
return_code = OPAL_ERR_OUT_OF_RESOURCE;
480-
goto end;
484+
char *tmp, *valid_keys = NULL;
485+
486+
for (int i = 0; i < key_count; i++) {
487+
ret = opal_asprintf(&tmp, "%s%s%s", (i > 0 ? valid_keys : ""),
488+
(i > 0 ? "," : ""), key_names[i]);
489+
free(valid_keys);
490+
valid_keys = tmp;
491+
if (0 > ret) {
492+
return_code = OPAL_ERR_OUT_OF_RESOURCE;
493+
goto end;
494+
}
481495
}
482496

483497
opal_show_help("help-opal-runtime.txt", "mpi-params:var_dump_color:unknown-key",

0 commit comments

Comments
 (0)