From: Emanuele Torre Date: Sat, 19 Aug 2023 16:51:16 +0000 (+0200) Subject: tool/var: also error when expansion result starts with NUL X-Git-Tag: curl-8_3_0~132 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70f1b540f39173c01468d4fe439ba91b7d776847;p=thirdparty%2Fcurl.git tool/var: also error when expansion result starts with NUL 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 --- diff --git a/src/var.c b/src/var.c index 88f2705f68..a332fab19f 100644 --- 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); diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index e13e4a73d0..5d909a8934 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -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 index 0000000000..1623aecaf7 --- /dev/null +++ b/tests/data/test456 @@ -0,0 +1,33 @@ + + + +HTTP +variables + + + +# +# Client-side + + +http + + +Variable output starting with null byte + + +%hex[%00]hex%hello + + +http://%HOSTIP:%HTTPPORT/%TESTNUMBER --variable what@%LOGDIR/junk --expand-data "{{what}}" + + + +# +# Verify data after the test has been "shot" + + +2 + + +