]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
strerror: repair get_winsock_error()
authorDaniel Stenberg <daniel@haxx.se>
Thu, 21 Dec 2023 16:50:29 +0000 (17:50 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 21 Dec 2023 22:17:15 +0000 (23:17 +0100)
It would try to read longer than the provided string and crash.

Follow-up to ff74cef5d4a0cf60106517a1c7384
Reported-by: calvin2021y on github
Fixes #12578
Closes #12579

lib/strerror.c

index e35193a48c282b53bb8510513875f215df570c66..a900e78d151d462dbbd2324a0a36065c9df02fd3 100644 (file)
@@ -582,11 +582,10 @@ get_winsock_error(int err, char *buf, size_t len)
 {
 #ifndef CURL_DISABLE_VERBOSE_STRINGS
   const char *p;
+  size_t alen;
 #endif
 
-  /* 41 bytes is the longest error string */
-  DEBUGASSERT(len > 41);
-  if(!len || len < 41)
+  if(!len)
     return NULL;
 
   *buf = '\0';
@@ -763,8 +762,9 @@ get_winsock_error(int err, char *buf, size_t len)
   default:
     return NULL;
   }
-  memcpy(buf, p, len - 1);
-  buf[len - 1] = '\0';
+  alen = strlen(p);
+  if(alen < len)
+    strcpy(buf, p);
   return buf;
 #endif
 }