diff options
author | Samuel Iglesias Gonsalvez <[email protected]> | 2015-09-29 16:10:02 +0200 |
---|---|---|
committer | Samuel Iglesias Gonsalvez <[email protected]> | 2015-09-30 08:13:07 +0200 |
commit | f3afcbecc63ec565a0386cda554d145ca908367d (patch) | |
tree | 35071a2c95ba2c99e134b949fb870fa3bc367176 /src/util/strndup.c | |
parent | 023165a734b3bae52a449ad01bc1ea5ba4384ec1 (diff) |
util: use strnlen() in strndup() implementations
If the string being copied is not NULL-terminated the result of
strlen() is undefined.
Signed-off-by: Samuel Iglesias Gonsalvez <[email protected]>
Reviewed-by: Neil Roberts <[email protected]>
Reviewed-by: Jose Fonseca <[email protected]>
Diffstat (limited to 'src/util/strndup.c')
-rw-r--r-- | src/util/strndup.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/src/util/strndup.c b/src/util/strndup.c index ca1c6f53b57..5ceb32fe474 100644 --- a/src/util/strndup.c +++ b/src/util/strndup.c @@ -35,10 +35,7 @@ strndup(const char *str, size_t max) if (!str) return NULL; - n = strlen(str); - if (n > max) - n = max; - + n = strnlen(str, max); ptr = (char *) calloc(n + 1, sizeof(char)); if (!ptr) return NULL; |