]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
string utils: Make sure don't return uninitialized memory. 3864/head
authorLiFeng <lifeng68@huawei.com>
Sat, 12 Jun 2021 06:52:46 +0000 (14:52 +0800)
committerLiFeng <lifeng68@huawei.com>
Sat, 12 Jun 2021 06:56:04 +0000 (14:56 +0800)
The function lxc_string_split_quoted and lxc_string_split_and_trim use
realloc to reduce the memory. But the result may be NULL, the the
returned memory will be uninitialized

Signed-off-by: LiFeng <lifeng68@huawei.com>
src/lxc/string_utils.c

index 9c54819a085551c217d581c8b0179286a247876a..b1d6dc9bc4ae0a1aff56242f42699f24af96c02a 100644 (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 *));