Skip to content

transfer: close connection after excess data has been read - #5440

Closed
mkauf wants to merge 1 commit into
curl:masterfrom
mkauf:excess_data_close_connection
Closed

transfer: close connection after excess data has been read#5440
mkauf wants to merge 1 commit into
curl:masterfrom
mkauf:excess_data_close_connection

Conversation

@mkauf

@mkauf mkauf commented May 21, 2020

Copy link
Copy Markdown
Contributor

For HTTP 1.x, it's a protocol error when the server sends more bytes than announced. If this happens, don't reuse the connection, because the start position of the next response is undefined.

I'm not sure whether this is also the case for other protocols, so please review carefully.

Test:

response.sh:

#!/bin/sh
printf "%s\r\n" "HTTP/1.1 200 OK"
printf "%s\r\n" "Content-Length: 13"
printf "%s\r\n" ""
printf "%s\r\n" "response 1 - excess data"
sleep 5
printf "%s\r\n" "HTTP/1.1 200 OK"
printf "%s\r\n" "Content-Length: 12"
printf "%s\r\n" ""
printf "%s\r\n" "response 2"
printf "%s\r\n" "HTTP/1.1 200 OK"
sleep 5
printf "%s\r\n" "Content-Length: 21"
printf "%s\r\n" ""
printf "%s\r\n" "response 3 - finish"

Start the test server:

./response.sh | nc -l 9090

Send three requests with curl:

curl http://127.0.0.1:9090/request1 http://127.0.0.1:9090/request2 http://127.0.0.1:9090/request3

Output:

response 1 - response 2
curl: (1) Received HTTP/0.9 when not allowed

So the second response is processed, because after reading the excess bytes, the next response line happens to be "HTTP/1.1 200 OK". The third response is not processed, because the next response line is "Content-Length: 21" - even though the size of the second response is announced correctly by the server. Whether curl processes the response depends on the position of the "sleep" command in the response script.

For HTTP 1.x, it's a protocol error when the server sends more bytes
than announced. If this happens, don't reuse the connection, because the
start position of the next response is undefined.

@bagder bagder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems entirely correct and I'm a little bit puzzled why we didn't do this already!

Did you look into adding a test case for this? I would be so good to make sure that we do right and have that verified with a test!

@mkauf

mkauf commented May 25, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I will work on a testcase, but I need some time.

@bagder

bagder commented May 26, 2020

Copy link
Copy Markdown
Member

I had a go at a test case for this in #5458

@bagder

bagder commented May 26, 2020

Copy link
Copy Markdown
Member

I could verify your fix with my test so I think it's fine to merge.

The test it self has problems so we can't merge that until it get fixed - if I can figure out a fix. Otherwise I'll just have to discard it.

@bagder

bagder commented May 27, 2020

Copy link
Copy Markdown
Member

Thanks!

@bagder bagder closed this in 3d44bfb May 27, 2020
@mkauf
mkauf deleted the excess_data_close_connection branch May 27, 2020 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants