aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-03-31 21:01:18 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-03-31 21:01:18 +0000
commit4d9e24d1e48280b4dd25489a501d65e71fff476b (patch)
treeef0ee8e8ca4904b7e00d90a4fa8d4402fbc21dec
parent1f236ba108ab282a950fd09a3eefed83fe9b234d (diff)
Better deal with NULL pointers.
CID 3 and 4 from the coverity.com scan.
-rw-r--r--lib/formdata.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/formdata.c b/lib/formdata.c
index a5118b389..e9db070c9 100644
--- a/lib/formdata.c
+++ b/lib/formdata.c
@@ -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 */