d469b84
From eb160abce0ac45a8e070d9fa995c61a416a58ddd Mon Sep 17 00:00:00 2001
d469b84
From: Dan Fandrich <dan@coneharvesters.com>
d469b84
Date: Sat, 11 Mar 2017 10:59:34 +0100
d469b84
Subject: [PATCH 1/2] tool_writeout: fixed a buffer read overrun on --write-out
d469b84
d469b84
If a % ended the statement, the string's trailing NUL would be skipped
d469b84
and memory past the end of the buffer would be accessed and potentially
d469b84
displayed as part of the --write-out output. Added tests 1440 and 1441
d469b84
to check for this kind of condition.
d469b84
d469b84
Reported-by: Brian Carpenter
d469b84
d469b84
Upstream-commit: 1890d59905414ab84a35892b2e45833654aa5c13
d469b84
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d469b84
---
d469b84
 src/tool_writeout.c     |  2 +-
d469b84
 tests/data/Makefile.inc |  2 +-
d469b84
 tests/data/test1440     | 31 +++++++++++++++++++++++++++++++
d469b84
 tests/data/test1441     | 31 +++++++++++++++++++++++++++++++
d469b84
 4 files changed, 64 insertions(+), 2 deletions(-)
d469b84
 create mode 100644 tests/data/test1440
d469b84
 create mode 100644 tests/data/test1441
d469b84
d469b84
diff --git a/src/tool_writeout.c b/src/tool_writeout.c
d469b84
index 2fb7774..7843182 100644
d469b84
--- a/src/tool_writeout.c
d469b84
+++ b/src/tool_writeout.c
d469b84
@@ -113,7 +113,7 @@ void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
d469b84
   double doubleinfo;
d469b84
 
d469b84
   while(ptr && *ptr) {
d469b84
-    if('%' == *ptr) {
d469b84
+    if('%' == *ptr && ptr[1]) {
d469b84
       if('%' == ptr[1]) {
d469b84
         /* an escaped %-letter */
d469b84
         fputc('%', stream);
d469b84
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
d469b84
index 8251ab9..2e70895 100644
d469b84
--- a/tests/data/Makefile.inc
d469b84
+++ b/tests/data/Makefile.inc
d469b84
@@ -151,7 +151,7 @@ test1408 test1409 test1410 test1411 test1412 test1413 test1414 test1415 \
d469b84
 test1416 test1417 test1418 test1419 test1420 test1421 test1422 test1423 \
d469b84
 test1424 \
d469b84
 test1428 test1429 test1430 test1431 test1432 test1433 test1434 test1435 \
d469b84
-test1436 test1437 test1438 test1439 \
d469b84
+test1436 test1437 test1438 test1439 test1440 test1441 \
d469b84
 \
d469b84
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
d469b84
 test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
d469b84
diff --git a/tests/data/test1440 b/tests/data/test1440
d469b84
new file mode 100644
d469b84
index 0000000..7ed0c4d
d469b84
--- /dev/null
d469b84
+++ b/tests/data/test1440
d469b84
@@ -0,0 +1,31 @@
d469b84
+<testcase>
d469b84
+<info>
d469b84
+<keywords>
d469b84
+--write-out
d469b84
+</keywords>
d469b84
+</info>
d469b84
+# Server-side
d469b84
+<reply>
d469b84
+</reply>
d469b84
+
d469b84
+# Client-side
d469b84
+<client>
d469b84
+<server>
d469b84
+file
d469b84
+</server>
d469b84
+
d469b84
+<name>
d469b84
+Check --write-out with trailing %{
d469b84
+</name>
d469b84
+<command>
d469b84
+file://localhost/%PWD/log/ --write-out '%{'
d469b84
+</command>
d469b84
+</client>
d469b84
+
d469b84
+# Verify data
d469b84
+<verify>
d469b84
+<stdout nonewline="yes">
d469b84
+%{
d469b84
+</stdout>
d469b84
+</verify>
d469b84
+</testcase>
d469b84
diff --git a/tests/data/test1441 b/tests/data/test1441
d469b84
new file mode 100644
d469b84
index 0000000..6e253a6
d469b84
--- /dev/null
d469b84
+++ b/tests/data/test1441
d469b84
@@ -0,0 +1,31 @@
d469b84
+<testcase>
d469b84
+<info>
d469b84
+<keywords>
d469b84
+--write-out
d469b84
+</keywords>
d469b84
+</info>
d469b84
+# Server-side
d469b84
+<reply>
d469b84
+</reply>
d469b84
+
d469b84
+# Client-side
d469b84
+<client>
d469b84
+<server>
d469b84
+file
d469b84
+</server>
d469b84
+
d469b84
+<name>
d469b84
+Check --write-out with trailing %
d469b84
+</name>
d469b84
+<command>
d469b84
+file://localhost/%PWD/log/ --write-out '%'
d469b84
+</command>
d469b84
+</client>
d469b84
+
d469b84
+# Verify data
d469b84
+<verify>
d469b84
+<stdout nonewline="yes">
d469b84
+%
d469b84
+</stdout>
d469b84
+</verify>
d469b84
+</testcase>
d469b84
-- 
d469b84
2.9.3
d469b84
d469b84
d469b84
From 67bee1434a17065da7db3fc2915c494f289f46de Mon Sep 17 00:00:00 2001
d469b84
From: Daniel Stenberg <daniel@haxx.se>
d469b84
Date: Fri, 24 Mar 2017 10:14:21 +0100
d469b84
Subject: [PATCH 2/2] curl: check for end of input in writeout backslash
d469b84
 handling
d469b84
d469b84
Reported-by: Brian Carpenter
d469b84
d469b84
Added test 1442 to verify
d469b84
d469b84
Upstream-commit: 8e65877870c1fac920b65219adec720df810aab9
d469b84
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d469b84
---
d469b84
 src/tool_writeout.c     |  4 ++--
d469b84
 tests/data/Makefile.inc |  2 +-
d469b84
 tests/data/test1442     | 35 +++++++++++++++++++++++++++++++++++
d469b84
 3 files changed, 38 insertions(+), 3 deletions(-)
d469b84
 create mode 100644 tests/data/test1442
d469b84
d469b84
diff --git a/src/tool_writeout.c b/src/tool_writeout.c
d469b84
index 7843182..5d92bd2 100644
d469b84
--- a/src/tool_writeout.c
d469b84
+++ b/src/tool_writeout.c
d469b84
@@ -5,7 +5,7 @@
d469b84
  *                            | (__| |_| |  _ <| |___
d469b84
  *                             \___|\___/|_| \_\_____|
d469b84
  *
d469b84
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
d469b84
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
d469b84
  *
d469b84
  * This software is licensed as described in the file COPYING, which
d469b84
  * you should have received as part of this distribution. The terms
d469b84
@@ -341,7 +341,7 @@ void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
d469b84
         }
d469b84
       }
d469b84
     }
d469b84
-    else if('\\' == *ptr) {
d469b84
+    else if('\\' == *ptr && ptr[1]) {
d469b84
       switch(ptr[1]) {
d469b84
       case 'r':
d469b84
         fputc('\r', stream);
d469b84
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
d469b84
index 2e70895..267ff6a 100644
d469b84
--- a/tests/data/Makefile.inc
d469b84
+++ b/tests/data/Makefile.inc
d469b84
@@ -151,7 +151,7 @@ test1408 test1409 test1410 test1411 test1412 test1413 test1414 test1415 \
d469b84
 test1416 test1417 test1418 test1419 test1420 test1421 test1422 test1423 \
d469b84
 test1424 \
d469b84
 test1428 test1429 test1430 test1431 test1432 test1433 test1434 test1435 \
d469b84
-test1436 test1437 test1438 test1439 test1440 test1441 \
d469b84
+test1436 test1437 test1438 test1439 test1440 test1441 test1442 \
d469b84
 \
d469b84
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
d469b84
 test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
d469b84
diff --git a/tests/data/test1442 b/tests/data/test1442
d469b84
new file mode 100644
d469b84
index 0000000..255a4c9
d469b84
--- /dev/null
d469b84
+++ b/tests/data/test1442
d469b84
@@ -0,0 +1,35 @@
d469b84
+<testcase>
d469b84
+<info>
d469b84
+<keywords>
d469b84
+--write-out
d469b84
+FILE
d469b84
+</keywords>
d469b84
+</info>
d469b84
+# Server-side
d469b84
+<reply>
d469b84
+</reply>
d469b84
+
d469b84
+# Client-side
d469b84
+<client>
d469b84
+<server>
d469b84
+file
d469b84
+</server>
d469b84
+
d469b84
+<name>
d469b84
+Check --write-out with trailing \
d469b84
+</name>
d469b84
+<command>
d469b84
+file://localhost/%PWD/log/non-existent-file.txt --write-out '\'
d469b84
+</command>
d469b84
+</client>
d469b84
+
d469b84
+# Verify data
d469b84
+<verify>
d469b84
+<errorcode>
d469b84
+37
d469b84
+</errorcode>
d469b84
+<stdout nonewline="yes">
d469b84
+\
d469b84
+</stdout>
d469b84
+</verify>
d469b84
+</testcase>
d469b84
-- 
d469b84
2.9.3
d469b84