Mesa (master): ralloc: Use strnlen() inside of strncat()

Timothy Arceri tarceri at kemper.freedesktop.org
Mon May 22 02:34:55 UTC 2017


Module: Mesa
Branch: master
Commit: cf164d9e975e2aa677b041c012cf843bd44e370a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cf164d9e975e2aa677b041c012cf843bd44e370a

Author: Vladislav Egorov <vegorov180 at gmail.com>
Date:   Sun May 21 22:49:19 2017 +0200

ralloc: Use strnlen() inside of strncat()

If the str is long or isn't null-terminated, strlen() could take a lot
of time or even crash. I don't know why was it used in the first place,
maybe for platforms without strnlen(), but strnlen() is already used
inside of ralloc_strndup(), so this change should not additionally
break anything.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/util/ralloc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/util/ralloc.c b/src/util/ralloc.c
index 7bf192e0db..953f36e6bc 100644
--- a/src/util/ralloc.c
+++ b/src/util/ralloc.c
@@ -405,12 +405,7 @@ ralloc_strcat(char **dest, const char *str)
 bool
 ralloc_strncat(char **dest, const char *str, size_t n)
 {
-   /* Clamp n to the string length */
-   size_t str_length = strlen(str);
-   if (str_length < n)
-      n = str_length;
-
-   return cat(dest, str, n);
+   return cat(dest, str, strnlen(str, n));
 }
 
 char *




More information about the mesa-commit mailing list