diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-02-21 12:24:30 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-02-21 12:24:30 -0800 |
commit | 1e664661cf35d22641521a1c4c22db1d071323aa (patch) | |
tree | e5cb01072992f1c17985a0d613069015320d07e1 | |
parent | 8ff41d060344af4d045bdd79bb826231d6739c7f (diff) |
settings: fixup win32 strndup
Using strlen on the input string isn't safe; it may be unterminated
-rw-r--r-- | src/settings.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/settings.c b/src/settings.c index 02c8e8d..aa256c5 100644 --- a/src/settings.c +++ b/src/settings.c @@ -13,7 +13,11 @@ char * strndup(const char *s, size_t n) size_t len; char *buf; - len = MIN(strlen(s), n); + for (len = 0; len < n; len++) { + if (!s[len]) + break; + } + buf = calloc(len + 1, sizeof(char)); if (!buf) return NULL; |