summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-12-05 15:21:27 +0100
committerDaniel Stenberg <daniel@haxx.se>2018-12-05 23:35:41 +0100
commitafb3fb123e7b83282bb8aa7cdadc49b71d727026 (patch)
treef37a1c184740610d5b0e2774aaedcf0c1a108f61
parentbae0d473f5912d38fc8da1f9850a70b015b53c9e (diff)
downloadcurl-bagder/doh-oom-memory-leak.tar.gz
doh: fix memory leak in OOM situationbagder/doh-oom-memory-leak
-rw-r--r--lib/doh.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/doh.c b/lib/doh.c
index 24546a0ac..49367def3 100644
--- a/lib/doh.c
+++ b/lib/doh.c
@@ -33,6 +33,7 @@
#include "share.h"
#include "curl_base64.h"
#include "connect.h"
+#include "strdup.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -143,8 +144,8 @@ doh_write_cb(void *contents, size_t size, size_t nmemb, void *userp)
/* suspiciously much for us */
return 0;
- mem->memory = realloc(mem->memory, mem->size + realsize);
- if(mem->memory == NULL)
+ mem->memory = Curl_saferealloc(mem->memory, mem->size + realsize);
+ if(!mem->memory)
/* out of memory! */
return 0;
@@ -524,7 +525,7 @@ UNITTEST DOHcode doh_decode(unsigned char *doh,
if(dohlen < 12)
return DOH_TOO_SMALL_BUFFER; /* too small */
- if(doh[0] || doh[1])
+ if(!doh || doh[0] || doh[1])
return DOH_DNS_BAD_ID; /* bad ID */
rcode = doh[3] & 0x0f;
if(rcode)