]> granicus.if.org Git - curl/commitdiff
Better deal with NULL pointers.
authorDaniel Stenberg <daniel@haxx.se>
Sat, 31 Mar 2007 21:01:18 +0000 (21:01 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 31 Mar 2007 21:01:18 +0000 (21:01 +0000)
CID 3 and 4 from the coverity.com scan.

lib/formdata.c

index a5118b3893aa764f569a4bc3bd76ec14aff0308e..e9db070c9710605be4e3461e349061a6c25b61da 100644 (file)
@@ -282,13 +282,15 @@ static const char * ContentTypeForFilename (const char *filename,
        text/plain so we don't actually need to set this: */
     contenttype = HTTPPOST_CONTENTTYPE_DEFAULT;
 
-  for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
-    if(strlen(filename) >= strlen(ctts[i].extension)) {
-      if(strequal(filename +
-                  strlen(filename) - strlen(ctts[i].extension),
-                  ctts[i].extension)) {
-        contenttype = ctts[i].type;
-        break;
+  if(filename) { /* in case a NULL was passed in */
+    for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
+      if(strlen(filename) >= strlen(ctts[i].extension)) {
+        if(strequal(filename +
+                    strlen(filename) - strlen(ctts[i].extension),
+                    ctts[i].extension)) {
+          contenttype = ctts[i].type;
+          break;
+        }
       }
     }
   }
@@ -315,10 +317,14 @@ static char *memdup(const char *src, size_t buffer_length)
 
   if (buffer_length)
     length = buffer_length;
-  else {
+  else if(src) {
     length = strlen(src);
     add = TRUE;
   }
+  else
+    /* no length and a NULL src pointer! */
+    return strdup((char *)"");
+
   buffer = (char*)malloc(length+add);
   if (!buffer)
     return NULL; /* fail */