-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
header_json emits incorrect JSON with multi-value headers #10704
Labels
Comments
bch
pushed a commit
to bch/curl
that referenced
this issue
Jul 19, 2023
By letting curl_easy_header() and curl_easy_nextheader() store the header data in their own struct storage when they return a pointer to it, it makes it possible for applications to use them both in a loop. Like the curl tool does. Reported-by: Boris Okunskiy Fixes curl#10704 Closes curl#10707
bch
pushed a commit
to bch/curl
that referenced
this issue
Jul 19, 2023
Header entries with index != 0 are handled at the index 0 level so they should then be skipped when iterated over. Reported-by: Boris Okunskiy Fixes curl#10704 Closes curl#10707
bch
pushed a commit
to bch/curl
that referenced
this issue
Jul 19, 2023
To reproduce the issue in curl#10704
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did this
There is a backend that returns several multi-value headers in overlapping order:
You can see the
vary
andreferrer-policy
occurring multiple times. With-w %{header_json}
option the JSON produced becomes incorrect:Notice the
"referrer-policy": ],
. Also notice that headers between the first occurrence of the first multi-value header (vary) are also missing.Here's the cURL command to reproduce the issue (note: the token is taken from the official docs, so feel free to use it).
I managed to track it down to
headerJSON
right here:curl/src/tool_writeout_json.c
Lines 131 to 132 in a26418c
prev
pointer gets overwritten by that last call tocurl_easy_header
before breaking from the loop; therefore the next iteration of thewhile
starts frometag
(which is the next header after the last occurrence ofvary
) and therefore misses the first occurrence of another multi-value headerreferrer-policy
(along with all other headers in between the first and the last occurrence ofvary
). By the time the outer loop reachesreferrer-policy
it actually sees the second occurrence (with index1
) and that causes the method to only emit a closing bracket because the branch before it is never entered.I expected the following
JSON should be valid. All headers should be present.
curl/libcurl version
7.88.1
operating system
macOS 12.5.1
/cc @christellevs
The text was updated successfully, but these errors were encountered: