From 9e5b11c659efb95278bca896dd6b58560825510a Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Fri, 12 Jul 2024 14:07:29 +0200 Subject: [PATCH] sendf: fix CRLF conversion of input When CRLF line end conversion was enabled (--crlf), input after the last newline in the upload buffer was not sent, if the buffer contained a newline. Reported-by: vuonganh1993 on github Fixes #14165 Closes #14169 --- lib/sendf.c | 6 ++++++ tests/data/test941 | 2 ++ tests/runtests.pl | 3 +++ tests/testutil.pm | 1 + 4 files changed, 12 insertions(+) diff --git a/lib/sendf.c b/lib/sendf.c index c80ffc640e..24b90d2ad0 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -1025,6 +1025,12 @@ static CURLcode cr_lc_read(struct Curl_easy *data, * the content length after having started the request... */ } } + + if(start < i) { /* leftover */ + result = Curl_bufq_cwrite(&ctx->buf, buf + start, i - start, &n); + if(result) + return result; + } } DEBUGASSERT(!Curl_bufq_is_empty(&ctx->buf)); diff --git a/tests/data/test941 b/tests/data/test941 index 7c87f50280..79f88a6740 100644 --- a/tests/data/test941 +++ b/tests/data/test941 @@ -32,6 +32,7 @@ converted with the --crlf option +%repeat[650 x 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789%0a]% smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -T %LOGDIR/upload%TESTNUMBER --crlf @@ -60,6 +61,7 @@ converted with the --crlf option +%repeat[650 x 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 %0a]% . diff --git a/tests/runtests.pl b/tests/runtests.pl index 059c840579..f814479820 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -1460,6 +1460,9 @@ sub singletest_check { # cut off the final newline from the final line of the upload data chomp($upload[-1]); } + for my $line (@upload) { + subbase64(\$line); + } # verify uploaded data my @out = loadarray("$logdir/upload.$testnum"); diff --git a/tests/testutil.pm b/tests/testutil.pm index 1a44083e1b..36bbe513cd 100644 --- a/tests/testutil.pm +++ b/tests/testutil.pm @@ -127,6 +127,7 @@ sub subbase64 { # decode %NN characters my ($d, $n) = ($2, $1); $d =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; + $n =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; my $all = $d x $n; $$thing =~ s/%%REPEAT%%/$all/; }