lib2302: fix crash due to stack overflow on MSVC and clang Windows

It fixes test 2302, 2303, 2307 with MSVC and clang on Windows.
GCC Windows builds were not affected.

Failure was caused by stack overflow due to a 1MB+ sized test struct on
stack. Replace it with dynamic allocation.

Also unignore affected tests in GHA/windows.

As seen under WINE with llvm-mingw:
```
$ wine64 libtests.exe lib2302 ws://127.0.0.1:59964/2302 > stdout2302 2> stderr2302
Test: lib2302
URL: ws://127.0.0.1:59964/2302
wine: Unhandled stack overflow at address 000000014007486A (thread 0024), starting debugger...
Unhandled exception: stack overflow in 64-bit code (0x000000014007486a).
```

Ref: #16629 (discovery)
Ref: 1bd5ac998b #16570

Closes #16630
This commit is contained in:
Viktor Szakats 2025-03-09 00:32:22 +01:00
parent 66313cc036
commit 7e282e18a5
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
2 changed files with 10 additions and 7 deletions

View file

@ -350,9 +350,6 @@ jobs:
if [ '${{ matrix.sys }}' != 'msys' ]; then
TFLAGS+=' ~612' # SFTP
fi
if [ '${{ matrix.sys }}' = 'clang64' ]; then
TFLAGS+=' ~2302 ~2303 ~2307' # permafail with clang (and also MSVC) (but works with mingw64 and ucrt64)
fi
if [ -x "$(cygpath "${SYSTEMROOT}/System32/curl.exe")" ]; then
TFLAGS+=" -ac $(cygpath "${SYSTEMROOT}/System32/curl.exe")"
fi
@ -923,7 +920,7 @@ jobs:
timeout-minutes: 10
run: |
export CURL_DIRSUFFIX='${{ matrix.type }}'
export TFLAGS='-j8 ${{ matrix.tflags }} ~2302 ~2303 ~2307'
export TFLAGS='-j8 ${{ matrix.tflags }}'
TFLAGS+=' ~2310' # flaky
PATH="$PWD/bld/lib/${{ matrix.type }}:$PATH:/c/Program Files (x86)/stunnel/bin:/c/Program Files/OpenSSH-Win64"
PATH="/c/msys64/usr/bin:$PATH"

View file

@ -28,13 +28,15 @@
struct ws_data {
CURL *easy;
char buf[1024*1024];
char *buf;
size_t blen;
size_t nwrites;
int has_meta;
int meta_flags;
};
#define LIB2302_BUFSIZE (1024 * 1024)
static void flush_data(struct ws_data *wd)
{
size_t i;
@ -66,7 +68,7 @@ static size_t add_data(struct ws_data *wd, const char *buf, size_t blen,
wd->meta_flags = meta ? meta->flags : 0;
}
if(wd->blen + blen > sizeof(wd->buf)) {
if(wd->blen + blen > LIB2302_BUFSIZE) {
return 0;
}
memcpy(wd->buf + wd->blen, buf, blen);
@ -96,13 +98,16 @@ CURLcode test(char *URL)
CURL *curl;
CURLcode res = CURLE_OK;
struct ws_data ws_data;
memset(&ws_data, 0, sizeof(ws_data));
ws_data.buf = (char *)calloc(LIB2302_BUFSIZE, 1);
if(!ws_data.buf)
return res;
global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
memset(&ws_data, 0, sizeof(ws_data));
ws_data.easy = curl;
curl_easy_setopt(curl, CURLOPT_URL, URL);
@ -118,6 +123,7 @@ CURLcode test(char *URL)
flush_data(&ws_data);
}
curl_global_cleanup();
free(ws_data.buf);
return res;
}