From f02c0a6fbf81d856ce476258bbc9b652fe033931 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Sat, 25 May 2013 16:07:18 +0800 Subject: [PATCH] Always make string copy for multi postdata. --- src/node-curl.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/node-curl.h b/src/node-curl.h index ada352d..154893c 100644 --- a/src/node-curl.h +++ b/src/node-curl.h @@ -38,7 +38,7 @@ class NodeCurlHttppost curl_httppost *next = cur->next; if (cur->contenttype) free(cur->contenttype); - if (cur->contents && cur->flags & HTTPPOST_FILENAME) + if (cur->contents) free(cur->contents); if (cur->buffer) free(cur->buffer); @@ -71,23 +71,25 @@ class NodeCurlHttppost void set(int field, char *value, long length) { + value = strndup(value, length); switch (field) { case NAME: - value = strndup(value, length); last->name = value; last->namelength = length; break; case TYPE: - value = strndup(value, length); last->contenttype = value; break; case FILE: - value = strndup(value, length); last->flags |= HTTPPOST_FILENAME; case CONTENTS: last->contents = value; last->contentslength = length; break; + default: + // `default` should never be reached. + free(value); + break; } } };