security:read_data fix bad realloc() 14/214214/1 accepted/tizen/base/20190921.035901 submit/tizen_base/20190919.235053
authorDaniel Stenberg <daniel@haxx.se>
Tue, 3 Sep 2019 20:59:32 +0000 (22:59 +0200)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 19 Sep 2019 05:20:51 +0000 (14:20 +0900)
... that could end up a double-free

CVE-2019-5481
Bug: https://curl.haxx.se/docs/CVE-2019-5481.html

Change-Id: I4eab9aceba3ad01607eb4f302200e9f949ea4312

lib/security.c

index 6165d0a..0b4ad27 100644 (file)
@@ -193,7 +193,6 @@ static CURLcode read_data(struct connectdata *conn,
                           struct krb5buffer *buf)
 {
   int len;
-  void *tmp = NULL;
   CURLcode result;
 
   result = socket_read(fd, &len, sizeof(len));
@@ -203,12 +202,11 @@ static CURLcode read_data(struct connectdata *conn,
   if(len) {
     /* only realloc if there was a length */
     len = ntohl(len);
-    tmp = Curl_saferealloc(buf->data, len);
+    buf->data = Curl_saferealloc(buf->data, len);
   }
-  if(tmp == NULL)
+  if(!len || !buf->data)
     return CURLE_OUT_OF_MEMORY;
 
-  buf->data = tmp;
   result = socket_read(fd, buf->data, len);
   if(result)
     return result;