Skip to content
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

curl tries to read from stdin when POSTing with -C #11081

Closed
Smackd0wn opened this issue May 7, 2023 · 4 comments
Closed

curl tries to read from stdin when POSTing with -C #11081

Smackd0wn opened this issue May 7, 2023 · 4 comments
Assignees

Comments

@Smackd0wn
Copy link

I did this

curl -v httpbin.org/post --data foobar -C 3

I expected the following

Not sure what to expect (POST data "bar", maybe?), but surely not the current behavior:

$ curl -v httpbin.org/post --data foobar -C3
*   Trying 34.235.32.249:80...
* Connected to httpbin.org (34.235.32.249) port 80 (#0)

and now it blocks forever, because it tries to read from stdin, seen from the strace log

lseek(0, 3, SEEK_SET)                   = -1 ESPIPE (Illegal seek)
read(0,

Now if I feed some data into stdin, say yes | curl -v httpbin.org/post --data foobar -C 3, curl will POST the string "foo", not "bar" or "y\ny".

$  yes|curl -v httpbin.org/post --data foobar -C3
*   Trying 34.235.32.249:80...
* Connected to httpbin.org (34.235.32.249) port 80 (#0)
> POST /post HTTP/1.1
> Host: httpbin.org
> Content-Range: bytes 3-5/6
> User-Agent: curl/8.0.1
> Accept: */*
> Content-Length: 3
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
< Date: Sun, 07 May 2023 17:05:37 GMT
< Content-Type: application/json
< Content-Length: 458
< Connection: keep-alive
< Server: gunicorn/19.9.0
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
<
{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "foo": ""
  },
  "headers": {
    "Accept": "*/*",
    "Content-Length": "3",
    "Content-Range": "bytes 3-5/6",
    "Content-Type": "application/x-www-form-urlencoded",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.0.1",
    "X-Amzn-Trace-Id": "Root=1-XXX"
  },
  "json": null,
  "origin": "XXX",
  "url": "http://httpbin.org/post"
}
* Connection #0 to host httpbin.org left intact

curl/libcurl version

curl 8.0.1 (x86_64-pc-linux-gnu) libcurl/8.0.1 OpenSSL/3.0.7 zlib/1.2.13 brotli/1.0.9 zstd/1.5.2 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.10.0 nghttp2/1.51.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

operating system

Linux arch 5.15.86-1-lts #1 SMP Sun, 01 Jan 2023 16:03:00 +0000 x86_64 GNU/Linux

@Smackd0wn
Copy link
Author

Actually it might be useful to PUT some partial data to a server, like
https://stackoverflow.com/questions/716680/difference-between-content-range-and-range-headers/6711496

@bagder
Copy link
Member

bagder commented May 7, 2023

Actually it might be useful to PUT some partial data to a server, like

There is no standard for doing "partial" uploads with HTTP PUT.

@bagder
Copy link
Member

bagder commented May 7, 2023

--data cannot be used with --continue-at. It should refuse to accept that combination.

bagder added a commit that referenced this issue May 7, 2023
The code assumes that such a resume is wanting to continue an upload
using the read callback, and since POSTFIELDS is done without callback
libcurl will just misbehave.

This combo will make the transfer fail with CURLE_BAD_FUNCTION_ARGUMENT
with an explanation in the error message.

Reported-by: Smackd0wn on github
Fixes #11081
bagder added a commit that referenced this issue May 7, 2023
libcurl assumes that a --continue-at resumption is done to continue an
upload using the read callback and neither --data nor --form use
that and thus won't do what the user wants. Whatever the user wants
with this strange combination.

Add test 426 to verify.

Reported-by: Smackd0wn on github
Fixes #11081
@bagder bagder linked a pull request May 7, 2023 that will close this issue
@Smackd0wn
Copy link
Author

I see. Thank you for the fix!

@bagder bagder closed this as completed in fb7886b May 8, 2023
bagder added a commit that referenced this issue May 8, 2023
libcurl assumes that a --continue-at resumption is done to continue an
upload using the read callback and neither --data nor --form use
that and thus won't do what the user wants. Whatever the user wants
with this strange combination.

Add test 426 to verify.

Reported-by: Smackd0wn on github
Fixes #11081
Closes #11083
bch pushed a commit to bch/curl that referenced this issue Jul 19, 2023
The code assumes that such a resume is wanting to continue an upload
using the read callback, and since POSTFIELDS is done without callback
libcurl will just misbehave.

This combo will make the transfer fail with CURLE_BAD_FUNCTION_ARGUMENT
with an explanation in the error message.

Reported-by: Smackd0wn on github
Fixes curl#11081
Closes curl#11083
bch pushed a commit to bch/curl that referenced this issue Jul 19, 2023
libcurl assumes that a --continue-at resumption is done to continue an
upload using the read callback and neither --data nor --form use
that and thus won't do what the user wants. Whatever the user wants
with this strange combination.

Add test 426 to verify.

Reported-by: Smackd0wn on github
Fixes curl#11081
Closes curl#11083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants