Blame SOURCES/bz1652694-fix-buffer-overflow-http-status.patch

680b9c
From f28015671a4b04785859d1b4b1327b367b6a10e9 Mon Sep 17 00:00:00 2001
680b9c
From: Quentin Armitage <quentin@armitage.org.uk>
680b9c
Date: Tue, 24 Jul 2018 09:28:43 +0100
680b9c
Subject: [PATCH] Fix buffer overflow in extract_status_code()
680b9c
680b9c
Issue #960 identified that the buffer allocated for copying the
680b9c
HTTP status code could overflow if the http response was corrupted.
680b9c
680b9c
This commit changes the way the status code is read, avoids copying
680b9c
data, and also ensures that the status code is three digits long,
680b9c
is non-negative and occurs on the first line of the response.
680b9c
680b9c
Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
680b9c
---
680b9c
 lib/html.c | 23 +++++++++--------------
680b9c
 1 file changed, 9 insertions(+), 14 deletions(-)
680b9c
680b9c
diff --git a/lib/html.c b/lib/html.c
680b9c
index 5a3eaeac..69d3bd2d 100644
680b9c
--- a/lib/html.c
680b9c
+++ b/lib/html.c
680b9c
@@ -58,23 +58,18 @@ size_t extract_content_length(char *buffer, size_t size)
680b9c
  */
680b9c
 int extract_status_code(char *buffer, size_t size)
680b9c
 {
680b9c
-	char *buf_code;
680b9c
-	char *begin;
680b9c
 	char *end = buffer + size;
680b9c
-	size_t inc = 0;
680b9c
-	int code;
680b9c
-
680b9c
-	/* Allocate the room */
680b9c
-	buf_code = (char *)MALLOC(10);
680b9c
+	unsigned long code;
680b9c
 
680b9c
 	/* Status-Code extraction */
680b9c
-	while (buffer < end && *buffer++ != ' ') ;
680b9c
-	begin = buffer;
680b9c
-	while (buffer < end && *buffer++ != ' ')
680b9c
-		inc++;
680b9c
-	strncat(buf_code, begin, inc);
680b9c
-	code = atoi(buf_code);
680b9c
-	FREE(buf_code);
680b9c
+	while (buffer < end && *buffer != ' ' && *buffer != '\r')
680b9c
+		buffer++;
680b9c
+	buffer++;
680b9c
+	if (buffer + 3 >= end || *buffer == ' ' || buffer[3] != ' ')
680b9c
+		return 0;
680b9c
+	code = strtoul(buffer, &end, 10);
680b9c
+	if (buffer + 3 != end)
680b9c
+		return 0;
680b9c
 	return code;
680b9c
 }
680b9c
 
680b9c
-- 
680b9c
2.19.1
680b9c