]> granicus.if.org Git - curl/commitdiff
formpost: trying to attach a directory no longer crashes
authorDaniel Stenberg <daniel@haxx.se>
Tue, 4 Oct 2016 07:13:02 +0000 (09:13 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 4 Oct 2016 07:13:02 +0000 (09:13 +0200)
The error path would previously add a freed entry to the linked list.

Reported-by: Toby Peterson
Fixes #1053

lib/formdata.c

index 673759de9d52a011a1ea68df8028faa930175e6b..13901b3304e0e5fa925df950990d947afbb4525a 100644 (file)
@@ -863,13 +863,6 @@ static CURLcode AddFormData(struct FormData **formp,
 
   newform->type = type;
 
-  if(*formp) {
-    (*formp)->next = newform;
-    *formp = newform;
-  }
-  else
-    *formp = newform;
-
   if(size) {
     if(type != FORM_FILE)
       /* for static content as well as callback data we add the size given
@@ -889,6 +882,14 @@ static CURLcode AddFormData(struct FormData **formp,
       }
     }
   }
+
+  if(*formp) {
+    (*formp)->next = newform;
+    *formp = newform;
+  }
+  else
+    *formp = newform;
+
   return CURLE_OK;
   error:
   if(newform)