Merge pull request #3864 from lifeng68/master

string utils: Make sure don't return uninitialized memory.
This commit is contained in:
Christian Brauner 2021-06-14 11:34:14 +02:00 committed by GitHub
commit 51bbca901b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -404,6 +404,9 @@ char **lxc_string_split_quoted(char *string)
if (state == 'a')
complete_word(&result, nextword, p, &result_capacity, &result_count);
if (result == NULL)
return calloc(1, sizeof(char *));
return realloc(result, (result_count + 1) * sizeof(char *));
}
@ -443,6 +446,9 @@ char **lxc_string_split_and_trim(const char *string, char _sep)
result_count++;
}
if (result == NULL)
return calloc(1, sizeof(char *));
/* if we allocated too much, reduce it */
return realloc(result, (result_count + 1) * sizeof(char *));