diff options
author | Thomas Haller <thaller@redhat.com> | 2019-12-15 14:28:45 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-12-16 10:22:09 +0100 |
commit | 9e02a676196300370487b39cbcff4e28d6c5f27c (patch) | |
tree | af6373d1ca2b7cd64994fc9c875964267ae5277a /shared/systemd/src/basic/strv.c | |
parent | a1771c738dd2e1437bd9f7c73805fd8a1b1b3d1d (diff) | |
parent | 0d155d1821875ab0de1ebe95570e5684daeb7d52 (diff) | |
download | NetworkManager-9e02a676196300370487b39cbcff4e28d6c5f27c.tar.gz |
systemd: merge branch systemd into master
Diffstat (limited to 'shared/systemd/src/basic/strv.c')
-rw-r--r-- | shared/systemd/src/basic/strv.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/shared/systemd/src/basic/strv.c b/shared/systemd/src/basic/strv.c index aa46713264..b773254bab 100644 --- a/shared/systemd/src/basic/strv.c +++ b/shared/systemd/src/basic/strv.c @@ -195,7 +195,10 @@ int strv_extend_strv(char ***a, char **b, bool filter_duplicates) { p = strv_length(*a); q = strv_length(b); - t = reallocarray(*a, p + q + 1, sizeof(char *)); + if (p >= SIZE_MAX - q) + return -ENOMEM; + + t = reallocarray(*a, GREEDY_ALLOC_ROUND_UP(p + q + 1), sizeof(char *)); if (!t) return -ENOMEM; @@ -389,19 +392,18 @@ char *strv_join_prefix(char **l, const char *separator, const char *prefix) { int strv_push(char ***l, char *value) { char **c; - size_t n, m; + size_t n; if (!value) return 0; n = strv_length(*l); - /* Increase and check for overflow */ - m = n + 2; - if (m < n) + /* Check for overflow */ + if (n > SIZE_MAX-2) return -ENOMEM; - c = reallocarray(*l, m, sizeof(char*)); + c = reallocarray(*l, GREEDY_ALLOC_ROUND_UP(n + 2), sizeof(char*)); if (!c) return -ENOMEM; @@ -414,19 +416,19 @@ int strv_push(char ***l, char *value) { int strv_push_pair(char ***l, char *a, char *b) { char **c; - size_t n, m; + size_t n; if (!a && !b) return 0; n = strv_length(*l); - /* increase and check for overflow */ - m = n + !!a + !!b + 1; - if (m < n) + /* Check for overflow */ + if (n > SIZE_MAX-3) return -ENOMEM; - c = reallocarray(*l, m, sizeof(char*)); + /* increase and check for overflow */ + c = reallocarray(*l, GREEDY_ALLOC_ROUND_UP(n + !!a + !!b + 1), sizeof(char*)); if (!c) return -ENOMEM; @@ -856,8 +858,10 @@ int strv_extend_n(char ***l, const char *value, size_t n) { /* Adds the value n times to l */ k = strv_length(*l); + if (n >= SIZE_MAX - k) + return -ENOMEM; - nl = reallocarray(*l, k + n + 1, sizeof(char *)); + nl = reallocarray(*l, GREEDY_ALLOC_ROUND_UP(k + n + 1), sizeof(char *)); if (!nl) return -ENOMEM; |