mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-26 17:10:11 +01:00
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 <siglesias@igalia.com> Reviewed-by: Neil Roberts <neil@linux.intel.com> Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
This commit is contained in:
parent
023165a734
commit
f3afcbecc6
2 changed files with 2 additions and 8 deletions
|
|
@ -359,10 +359,7 @@ ralloc_strndup(const void *ctx, const char *str, size_t max)
|
|||
if (unlikely(str == NULL))
|
||||
return NULL;
|
||||
|
||||
n = strlen(str);
|
||||
if (n > max)
|
||||
n = max;
|
||||
|
||||
n = strnlen(str, max);
|
||||
ptr = ralloc_array(ctx, char, n + 1);
|
||||
memcpy(ptr, str, n);
|
||||
ptr[n] = '\0';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue