]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool/var: also error when expansion result starts with NUL
authorEmanuele Torre <torreemanuele6@gmail.com>
Sat, 19 Aug 2023 16:51:16 +0000 (18:51 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 19 Aug 2023 21:50:37 +0000 (23:50 +0200)
Expansions whose output starts with NUL were being expanded to the empty
string, and not being recognised as values that contain a NUL byte, and
should error.

Closes #11694

src/var.c
tests/data/Makefile.inc
tests/data/test456 [new file with mode: 0644]

index 88f2705f684620702665fb789c711a1679399eca..a332fab19f9b3b947be371ad2e3d76e837f06ea6 100644 (file)
--- a/src/var.c
+++ b/src/var.c
@@ -307,7 +307,7 @@ ParameterError varexpand(struct GlobalConfig *global,
             vlen = curlx_dyn_len(&buf);
           }
 
-          if(value && *value) {
+          if(value && vlen > 0) {
             /* A variable might contain null bytes. Such bytes cannot be shown
                using normal means, this is an error. */
             char *nb = memchr(value, '\0', vlen);
index e13e4a73d0f00b1fcae0474300f0416a97e185e9..5d909a89342c3ef8088ce1948b37fc7c7ec427bd 100644 (file)
@@ -73,7 +73,7 @@ test426 test427 test428 test429 test430 test431 test432 test433 test434 \
 test435 test436 \
 \
 test440 test441 test442 test443 test444 test445 test446 test447 test448 \
-test449 test450 test451 test452 test453 test454 test455 \
+test449 test450 test451 test452 test453 test454 test455 test456 \
 \
 test490 test491 test492 test493 test494 test495 test496 test497 \
 \
diff --git a/tests/data/test456 b/tests/data/test456
new file mode 100644 (file)
index 0000000..1623aec
--- /dev/null
@@ -0,0 +1,33 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+variables
+</keywords>
+</info>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+Variable output starting with null byte
+</name>
+<file name="%LOGDIR/junk">
+%hex[%00]hex%hello
+</file>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER --variable what@%LOGDIR/junk --expand-data "{{what}}"
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+2
+</errorcode>
+</verify>
+</testcase>