GH680: Reuse strnlen() in strndup()
authorDmitry-Me <wipedout@yandex.ru>
Mon, 15 Feb 2016 07:12:40 +0000 (10:12 +0300)
committerRich Salz <rsalz@openssl.org>
Fri, 26 Feb 2016 16:26:56 +0000 (11:26 -0500)
Signed-off-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
crypto/o_str.c

index b200060917f4cbe780339f1a4bf2eac7a245527a..b01128cdb379d89b4a60174dca7eae29b77f5e6f 100644 (file)
@@ -133,17 +133,13 @@ char *CRYPTO_strdup(const char *str, const char* file, int line)
 
 char *CRYPTO_strndup(const char *str, size_t s, const char* file, int line)
 {
-    const char *cp;
     size_t maxlen;
     char *ret;
 
     if (str == NULL)
         return NULL;
 
-    /* Get length. */
-    for (cp = str, maxlen = s; maxlen-- != 0 && *cp != '\0'; ++cp)
-        continue;
-    maxlen = cp - str;
+    maxlen = OPENSSL_strnlen(str, s)
 
     ret = CRYPTO_malloc(maxlen + 1, file, line);
     if (ret) {