-
Notifications
You must be signed in to change notification settings - Fork 901
Make sure to never allocate zero-length memory buffer in opal_argv_join_range #8581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…in_range This silences a warning issued by GCC 10.2.0, warning about `str[--str_len] = '\0'` writing out of bounds if str_len is 0. This also ensures that 0 is not passed to malloc, which may return NULL and lead to a unintended return value. Signed-off-by: Joseph Schuchart <[email protected]>
@@ -343,7 +343,7 @@ char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) | |||
|
|||
/* Bozo case */ | |||
|
|||
if (NULL == argv || NULL == argv[0] || (int)start > opal_argv_count(argv)) { | |||
if (NULL == argv || NULL == argv[0] || (int)start >= opal_argv_count(argv)) { | |||
return strdup(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to be consistent in this function when something didn't go as planned: either we return strdup("")
or NULL, but consistently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the point of returning NULL is the assumption that if malloc
returns NULL we're out-of-memory, so strdup
won't work either.
Good catch! ...that being said, do we use After some grep'ing, it doesn't look like we use this function anywhere. Would a better solution be just to remove this function altogether? |
Sure, I'm happy to remove it altogether. It won't hurt to keep it in case someone somewhere at some point wants that functionality though ^^ |
Your call. Looks like it's used in PMIx and we used to use it in the rsh PML (which is now PRTE). I.e., we don't use it in Open MPI anywhere. |
I'd say we leave it in, it might be handy for debugging purposes and there is no harm in having it. |
I believe I have seen this warning with PRRTE and PMIx, too @rhc54 |
Thanks - I have been tracking this PPR and plan to backport it to both of those. Appreciate you ensuring I saw it! |
Tracks open-mpi/ompi#8581 Signed-off-by: Ralph Castain <[email protected]>
Tracks open-mpi/ompi#8581 Signed-off-by: Ralph Castain <[email protected]>
Tracks open-mpi/ompi#8581 Signed-off-by: Ralph Castain <[email protected]>
Tracks open-mpi/ompi#8581 Signed-off-by: Ralph Castain <[email protected]> (cherry picked from commit f206379)
Tracks open-mpi/ompi#8581 Signed-off-by: Ralph Castain <[email protected]> (cherry picked from commit de48293)
Tracks open-mpi/ompi#8581 Signed-off-by: Ralph Castain <[email protected]> (cherry picked from commit de48293) (cherry picked from commit 037f42c)
This silences a warning issued by GCC 10.2.0, warning about
str[--str_len] = '\0'
writing out of bounds if str_len is 0:This also ensures that 0 is not passed to
malloc
, which may returnNULL
and lead to a unintended return ofNULL
instead of an empty string.The change to greater-or-equal in
(int)start >= opal_argv_count(argv)
is meant to catch the case ofargv[start] == NULL
early.Signed-off-by: Joseph Schuchart [email protected]