From 67126748f76b2417c0cdc0bd5772aac4aa1b4eb5 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Wed, 8 May 2019 20:33:19 -0500 Subject: string: check NULL before using variables everywhere --- libgcompat/string.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libgcompat/string.c b/libgcompat/string.c index 1b3673b..9852bea 100644 --- a/libgcompat/string.c +++ b/libgcompat/string.c @@ -145,11 +145,13 @@ char *__stpncpy_chk(char *dest, const char *src, size_t n, size_t destlen) */ char *__strcat_chk(char *dest, const char *src, size_t destlen) { - size_t n = strlen(src) + 1; - size_t total = strnlen(dest, destlen) + n; + size_t n; + size_t total; assert(dest != NULL); assert(src != NULL); + n = strlen(src) + 1; + total = strnlen(dest, destlen) + n; assert(destlen >= total); if (dest < src) { assert(dest + total <= src); @@ -215,10 +217,11 @@ char *__strdup(const char *string) */ char *__strncat_chk(char *dest, const char *src, size_t n, size_t destlen) { - size_t total = strnlen(dest, destlen) + n + 1; + size_t total; assert(dest != NULL); assert(src != NULL); + total = strnlen(dest, destlen) + n + 1; assert(destlen >= total); if (dest < src) { assert(dest + total <= src); -- cgit v1.2.3-70-g09d2