curl: Fix multiple security problems
[openwrt/staging/dedeckeh.git] / package / network / utils / curl / patches / 405-CVE-2019-3823.patch
1 From 39df4073e5413fcdbb5a38da0c1ce6f1c0ceb484 Mon Sep 17 00:00:00 2001
2 From: Daniel Gustafsson <daniel@yesql.se>
3 Date: Sat, 19 Jan 2019 00:42:47 +0100
4 Subject: [PATCH] smtp: avoid risk of buffer overflow in strtol
5
6 If the incoming len 5, but the buffer does not have a termination
7 after 5 bytes, the strtol() call may keep reading through the line
8 buffer until is exceeds its boundary. Fix by ensuring that we are
9 using a bounded read with a temporary buffer on the stack.
10
11 Bug: https://curl.haxx.se/docs/CVE-2019-3823.html
12 Reported-by: Brian Carpenter (Geeknik Labs)
13 CVE-2019-3823
14 ---
15 lib/smtp.c | 8 ++++++--
16 1 file changed, 6 insertions(+), 2 deletions(-)
17
18 --- a/lib/smtp.c
19 +++ b/lib/smtp.c
20 @@ -5,7 +5,7 @@
21 * | (__| |_| | _ <| |___
22 * \___|\___/|_| \_\_____|
23 *
24 - * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
25 + * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
26 *
27 * This software is licensed as described in the file COPYING, which
28 * you should have received as part of this distribution. The terms
29 @@ -207,8 +207,12 @@ static bool smtp_endofresp(struct connec
30 Section 4. Examples of RFC-4954 but some e-mail servers ignore this and
31 only send the response code instead as per Section 4.2. */
32 if(line[3] == ' ' || len == 5) {
33 + char tmpline[6];
34 +
35 result = TRUE;
36 - *resp = curlx_sltosi(strtol(line, NULL, 10));
37 + memset(tmpline, '\0', sizeof(tmpline));
38 + memcpy(tmpline, line, (len == 5 ? 5 : 3));
39 + *resp = curlx_sltosi(strtol(tmpline, NULL, 10));
40
41 /* Make sure real server never sends internal value */
42 if(*resp == 1)