]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ftp: use memdup0 to store the OS from a SYST 215 response
authorDaniel Stenberg <daniel@haxx.se>
Fri, 5 Jan 2024 10:58:48 +0000 (11:58 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 6 Jan 2024 10:26:31 +0000 (11:26 +0100)
avoid malloc + direct buffer fiddle

Closes #12639

lib/ftp.c

index 65b4db98154acc0d7f929fe3bab06bd927403907..bf8b57db2672a12762d41517a2457c2eec52b44b 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -2951,23 +2951,20 @@ static CURLcode ftp_statemachine(struct Curl_easy *data,
       if(ftpcode == 215) {
         char *ptr = &data->state.buffer[4];  /* start on the first letter */
         char *os;
-        char *store;
-
-        os = malloc(nread + 1);
-        if(!os)
-          return CURLE_OUT_OF_MEMORY;
+        char *start;
 
         /* Reply format is like
            215<space><OS-name><space><commentary>
         */
         while(*ptr == ' ')
           ptr++;
-        for(store = os; *ptr && *ptr != ' ';)
-          *store++ = *ptr++;
-        *store = '\0'; /* null-terminate */
+        for(start = ptr; *ptr && *ptr != ' '; ptr++)
+          ;
+        os = Curl_memdup0(start, ptr - start);
+        if(!os)
+          return CURLE_OUT_OF_MEMORY;
 
         /* Check for special servers here. */
-
         if(strcasecompare(os, "OS/400")) {
           /* Force OS400 name format 1. */
           result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SITE NAMEFMT 1");