components/curl/patches/016-CVE-2016-8618.patch
author Yiteng Zhang <yiteng.zhang@oracle.com>
Tue, 07 Feb 2017 17:11:12 -0800
branchs11u3-sru
changeset 7654 61774c5d9189
permissions -rw-r--r--
25241371 problem in LIBRARY/CURL 25241378 problem in LIBRARY/CURL 25241832 problem in LIBRARY/CURL 25241839 problem in LIBRARY/CURL 25241853 problem in LIBRARY/CURL 25241867 problem in LIBRARY/CURL 25241881 problem in LIBRARY/CURL 25241889 problem in LIBRARY/CURL 25241894 problem in LIBRARY/CURL 25241900 problem in LIBRARY/CURL 25306385 problem in LIBRARY/CURL

From 31106a073882656a2a5ab56c4ce2847e9a334c3c Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <[email protected]>
Date: Wed, 28 Sep 2016 10:15:34 +0200
Subject: [PATCH] aprintf: detect wrap-around when growing allocation

On 32bit systems we could otherwise wrap around after 2GB and allocate 0
bytes and crash.

CVE-2016-8618

Bug: https://curl.haxx.se/docs/adv_20161102D.html
Reported-by: Cure53
---
 lib/mprintf.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- lib/mprintf.c
+++ lib/mprintf.c
@@ -1034,20 +1034,23 @@ static int alloc_addbyter(int output, FILE *data)
     }
     infop->alloc = 32;
     infop->len =0;
   }
   else if(infop->len+1 >= infop->alloc) {
-    char *newptr;
+    char *newptr = NULL;
+    size_t newsize = infop->alloc*2;
 
-    newptr = realloc(infop->buffer, infop->alloc*2);
+    /* detect wrap-around or other overflow problems */
+    if(newsize > infop->alloc)
+      newptr = realloc(infop->buffer, newsize);
 
     if(!newptr) {
       infop->fail = 1;
       return -1; /* fail */
     }
     infop->buffer = newptr;
-    infop->alloc *= 2;
+    infop->alloc = newsize;
   }
 
   infop->buffer[ infop->len ] = outc;
 
   infop->len++;
-- 
2.9.3