diff options
Diffstat (limited to 'src/shared/strv.c')
-rw-r--r-- | src/shared/strv.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/shared/strv.c b/src/shared/strv.c index 0df978d23b..efa648df88 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -380,13 +380,19 @@ char *strv_join_quoted(char **l) { int strv_push(char ***l, char *value) { char **c; - unsigned n; + unsigned n, m; if (!value) return 0; n = strv_length(*l); - c = realloc(*l, sizeof(char*) * (n + 2)); + + /* increase and check for overflow */ + m = n + 2; + if (m < n) + return -ENOMEM; + + c = realloc(*l, sizeof(char*) * (size_t) m); if (!c) return -ENOMEM; @@ -399,13 +405,19 @@ int strv_push(char ***l, char *value) { int strv_push_prepend(char ***l, char *value) { char **c; - unsigned n, i; + unsigned n, m, i; if (!value) return 0; n = strv_length(*l); - c = new(char*, n + 2); + + /* increase and check for overflow */ + m = n + 2; + if (m < n) + return -ENOMEM; + + c = new(char*, m); if (!c) return -ENOMEM; |