← Commit list

c303355957

Jay Satiro
Jay Satiro
2026-09-01
SUCCESS Duration: 429s

Subject

tool_doswin: fix stdin data truncation

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

src/tool_doswin.c+19 -13
@@ -740,6 +740,12 @@ static DWORD WINAPI win_stdin_thread_func(void *thread_data)
ssize_t nwritten;
char buffer[BUFSIZ];
+ /* If stdin is a pipe then end-of-data signaling may differ depending on
+ how curl was built, the shell and the input. Two ways have been
+ observed:
+ - ReadFile fails with GetLastError ERROR_BROKEN_PIPE
+ - ReadFile succeeds with 0 bytes read (seen on mingw) */
+
if(!ReadFile(tdata.stdin_handle, buffer, sizeof(buffer), &n, NULL))
break;
if(n == 0)
@@ -751,6 +757,19 @@ static DWORD WINAPI win_stdin_thread_func(void *thread_data)
break;
}
+ /* wait for all data to be received by the main thread:
+ shut down the write side of our socket so that a FIN is sent "after all
+ data is sent and acknowledged by the receiver". recv is called to wait for
+ this to happen. the wait time includes time of up to 2 min (OS typical)
+ since it's possible the receiver will not reply to the FIN.
+ */
+ if(shutdown(tdata.socket_w, SHUT_WR) == 0) {
+ char buf[1024];
+ /* read until close or error while ignoring all incoming */
+ while(sread(tdata.socket_w, buf, sizeof(buf)) > 0)
+ ;
+ }
+
cleanup_tdata_sync();
return 0;
@@ -880,9 +899,6 @@ curl_socket_t win32_stdin_read_thread(void)
break;
}
- /* Hard close the socket on closesocket() */
- setsockopt(socket_r, SOL_SOCKET, SO_DONTLINGER, 0, 0);
-
/* Make the reading socket nonblocking */
if(curlx_nonblock(socket_r, TRUE)) {
errorf("curlx_nonblock() error");
@@ -930,16 +946,6 @@ curl_socket_t win32_stdin_read_thread(void)
break;
}
- if(shutdown(tdata.socket_w, SHUT_RD)) {
- errorf("shutdown error: %d", SOCKERRNO);
- break;
- }
-
- if(shutdown(socket_r, SHUT_WR)) {
- errorf("shutdown error: %d", SOCKERRNO);
- break;
- }
-
/* Make a copy of the stdin handle to be used by win_stdin_thread_func */
if(!DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE),
GetCurrentProcess(), &tdata.stdin_handle,