Files
jak-project/third-party/curl/tests/unit/unit1650.c
Alexander J. Semenuk 5d5e35fb9b fix: Windows toolchain compatibility (curl 8.21 re-vendor, endless reconfigure loop) (#4355)
## Problem

Windows builds break with a current local toolchain (Scoop LLVM 22.1.8,
CMake 4.4.0, VS 2026), in two independent ways:

1. The build stops at curl's deliberate guard: `#error "no non-blocking
method was found/used/set"` in `third-party/curl/lib/nonblock.c`.
2. From the second configure onward, `cmake --build` re-runs CMake in an
endless loop (observed 42 consecutive reconfigure cycles in a single
build). Likely the same mechanism behind the "endlessly building" VS
2026 note in `docs/setup/dev/vs.md`.

## Root cause

1. `third-party/curl/CMake/CurlTests.c` passes `int *` to
`ioctlsocket()`, whose third parameter is `u_long *`. Clang 22 promotes
`-Wincompatible-pointer-types` to a hard error in C, so the
`HAVE_IOCTLSOCKET_FIONBIO` try_compile silently fails and
`curl_config.h` never defines it. Upstream CI does not see this because
the windows-2022 runner image ships an older LLVM. GCC 14 promotes the
same warning to a hard error, which is very likely the `CurlTests.c.obj`
failure reported from MSYS2 in open-goal/jak-project#3551. Upstream curl
hit the identical problem with GCC 14 and fixed the probe in curl 8.8.0
(curl/curl#13578).
2. The root CMakeLists copies the build tree's `compile_commands.json`
into `<src>/build/` for clangd using `configure_file()`, which registers
its input as a configure dependency. CMake rewrites
`compile_commands.json` late in every generation, after
`CTestTestfile.cmake` and `cmake_install.cmake` (outputs of the same
Ninja regen rule), so once the dependency is registered the rule is
deterministically dirty and every `ninja` invocation re-runs CMake. A
pristine first configure is safe (the file does not exist yet, so the
`if(EXISTS ...)` guard skips the copy), which is why the loop looks
machine- or IDE-specific.

## Fix

1. Per review, re-vendor `third-party/curl` at the `curl-8_21_0` tag
(previously `curl-8_3_0`), which carries the upstream probe fix plus two
years of upstream development; `vendor.yaml` updated to match.
Adjustments the version jump forced:
- curl 8.15 removed the native macOS Secure Transport backend
(`CURL_USE_SECTRANSP`), so macOS now builds curl against OpenSSL like
Linux. The two macOS workflows install Homebrew `openssl@3` and export
`OPENSSL_ROOT_DIR` (keg-only), and the macOS setup docs gained the same
two lines.
- `CURL_BROTLI` / `CURL_ZSTD` switched to AUTO-detection in curl 8.10;
pinned OFF to keep the previous no-compression behavior and avoid
silently linking whatever the CI images happen to have.
- curl's new top-level `BUILD_EXAMPLES` cache option (default ON) leaked
into discord-rpc's identically named option and broke configure at a
nonexistent `examples/send-presence` directory; pinned OFF ahead of the
third-party subdirectories.

The diff is dominated by the mechanical tag-tree swap under
`third-party/curl` (linguist-vendored, collapsed in review). The
hand-written changes are `CMakeLists.txt`, the two macOS workflows,
`docs/setup/system/macos.md`, and `vendor.yaml`.
2. Swap `configure_file()` for `file(COPY ...)`: the same clangd copy
with no configure dependency registered. (`file(COPY_FILE ...
ONLY_IF_DIFFERENT)` would be cleaner still but requires CMake 3.21,
above the declared `cmake_minimum_required(VERSION 3.10)`.)

## Test plan

- [x] Fresh `cmake --preset Release-windows-clang` (LLVM 22, no cache
seeding) completes and logs `Enabled SSL backends: Schannel`; the
FIONBIO probe passes without the previous `#error`
- [x] Full Windows Release build from scratch in the branch worktree
(all 1422 targets)
- [x] goalc-test suite: 1509 passed, 0 failed
- [x] Second consecutive configure with `compile_commands.json` present:
the regen rule in `build.ninja` has no `compile_commands.json` input;
`<src>/build/compile_commands.json` is still refreshed for clangd
- [x] Repeated `ninja` invocations after a full build no longer re-run
CMake
- [x] macOS Intel and ARM CI green (first exercise of the OpenSSL
backend switch)

---

I work off a self-hosted forge, so this GitHub account is quiet; the
configure logs and ninja dirty-node traces from the investigation are
available if anyone wants the raw data.

(AI-assisted)
2026-07-27 19:19:18 -04:00

286 lines
9.9 KiB
C
Vendored
Generated

/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "doh.h"
static CURLcode test_unit1650(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_DOH
#define DNS_PREAMBLE "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00"
#define LABEL_TEST "\x04\x74\x65\x73\x74"
#define LABEL_HOST "\x04\x68\x6f\x73\x74"
#define LABEL_NAME "\x04\x6e\x61\x6d\x65"
#define DNSA_TYPE "\x01"
#define DNSAAAA_TYPE "\x1c"
#define DNSA_EPILOGUE "\x00\x00" DNSA_TYPE "\x00\x01"
#define DNSAAAA_EPILOGUE "\x00\x00" DNSAAAA_TYPE "\x00\x01"
#define DNS_Q1 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSA_EPILOGUE
#define DNS_Q2 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE
struct dohrequest {
/* input */
const char *name;
DNStype type;
/* output */
const char *packet;
size_t size;
DOHcode rc;
};
static const struct dohrequest req[] = {
{"test.host.name", CURL_DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, DOH_OK },
{"test.host.name", CURL_DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, DOH_OK },
{"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
".host.name",
CURL_DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
};
struct dohresp {
/* input */
const char *packet;
size_t size;
DNStype type;
/* output */
DOHcode rc;
const char *out;
};
#define DNS_FOO_EXAMPLE_COM \
"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f" \
"\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00" \
"\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x37\x00\x04\x7f\x00\x00" \
"\x01"
static const char full49[] = DNS_FOO_EXAMPLE_COM;
static const struct dohresp resp[] = {
{"\x00\x00", 2, CURL_DNS_TYPE_A, DOH_TOO_SMALL_BUFFER, NULL },
{"\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
CURL_DNS_TYPE_A, DOH_DNS_BAD_ID, NULL },
{"\x00\x00\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
CURL_DNS_TYPE_A, DOH_DNS_BAD_RCODE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f", 16,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00", 17,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00"
"\x00\x01\x00\x01", 21,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00"
"\x00\x01\x00\x01"
"\x04", 18,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x63\x75\x72"
"\x6c\x04\x63\x75\x72\x6c\x00\x00\x05\x00\x01\xc0\x0c\x00\x05\x00"
"\x01\x00\x00\x00\x37\x00\x11\x08\x61\x6e\x79\x77\x68\x65\x72\x65"
"\x06\x72\x65\x61\x6c\x6c\x79\x00", 56,
CURL_DNS_TYPE_A, DOH_OK, "anywhere.really (55)"},
{DNS_FOO_EXAMPLE_COM, 49, CURL_DNS_TYPE_A, DOH_OK, "127.0.0.1 (55)"},
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x61\x61\x61"
"\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
"\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\x00\x01\x37\x00\x10\x20\x20"
"\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20", 62,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 (311)" },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x63\x75\x72"
"\x6c\x04\x63\x75\x72\x6c\x00\x00\x05\x00\x01\xc0\x0c\x00\x05\x00"
"\x01\x00\x00\x00\x37\x00"
"\x07\x03\x61\x6e\x79\xc0\x27\x00", 46,
CURL_DNS_TYPE_A, DOH_DNS_LABEL_LOOP, NULL},
/* packet with NSCOUNT == 1 */
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x01\x00\x00\x04\x61\x61\x61"
"\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
"\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\x00\x00\x37\x00\x10\x20\x20"
"\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20"
LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE "\x00\x00\x00\x01"
"\00\x04\x01\x01\x01\x01", /* RDDATA */
62 + 30,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 (55)" },
/* packet with ARCOUNT == 1, and a capped TTL */
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x01\x04\x61\x61\x61"
"\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
"\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\xff\xff\x37\x00\x10\x20\x20"
"\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20"
LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE "\x00\x00\x00\x01"
"\00\x04\x01\x01\x01\x01", /* RDDATA */
62 + 30,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 (86400)" },
};
size_t size = 0;
unsigned char buffer[256];
size_t i;
unsigned char *p;
for(i = 0; i < CURL_ARRAYSIZE(req); i++) {
DOHcode rc = doh_req_encode(req[i].name, req[i].type,
buffer, sizeof(buffer), &size);
if(rc != req[i].rc) {
curl_mfprintf(stderr, "req %zu: Expected return code %d got %d\n", i,
(int)req[i].rc, (int)rc);
abort_if(rc != req[i].rc, "return code");
}
if(size != req[i].size) {
curl_mfprintf(stderr, "req %zu: Expected size %zu got %zu\n", i,
req[i].size, size);
curl_mfprintf(stderr, "DNS encode made: %s\n", hexdump(buffer, size));
abort_if(size != req[i].size, "size");
}
if(req[i].packet && memcmp(req[i].packet, buffer, size)) {
curl_mfprintf(stderr, "DNS encode made: %s\n", hexdump(buffer, size));
curl_mfprintf(stderr, "... instead of: %s\n",
hexdump((const unsigned char *)req[i].packet, size));
abort_if(req[i].packet && memcmp(req[i].packet, buffer, size),
"contents");
}
}
for(i = 0; i < CURL_ARRAYSIZE(resp); i++) {
struct dohentry d;
DOHcode rc;
char *ptr;
size_t len;
int u;
de_init(&d);
rc = doh_resp_decode((const unsigned char *)resp[i].packet, resp[i].size,
resp[i].type, &d);
if(rc != resp[i].rc) {
curl_mfprintf(stderr, "resp %zu: Expected return code %d got %d\n", i,
(int)resp[i].rc, (int)rc);
abort_if(rc != resp[i].rc, "return code");
}
len = sizeof(buffer);
ptr = (char *)buffer;
for(u = 0; u < d.numaddr; u++) {
size_t o;
struct dohaddr *a;
a = &d.addr[u];
if(resp[i].type == CURL_DNS_TYPE_A) {
p = &a->ip.v4[0];
curl_msnprintf(ptr, len, "%u.%u.%u.%u ", p[0], p[1], p[2], p[3]);
o = strlen(ptr);
len -= o;
ptr += o;
}
else {
int j;
for(j = 0; j < 16; j += 2) {
size_t l;
curl_msnprintf(ptr, len, "%s%02x%02x", j ? ":" : "", a->ip.v6[j],
a->ip.v6[j + 1]);
l = strlen(ptr);
len -= l;
ptr += l;
}
curl_msnprintf(ptr, len, " ");
len--;
ptr++;
}
}
for(u = 0; u < d.numcname; u++) {
size_t o;
curl_msnprintf(ptr, len, "%s ", curlx_dyn_ptr(&d.cname[u]));
o = strlen(ptr);
len -= o;
ptr += o;
}
curl_msnprintf(ptr, len, "(%u)", d.ttl);
de_cleanup(&d);
if(resp[i].out && strcmp((const char *)buffer, resp[i].out)) {
curl_mfprintf(stderr, "resp %zu: Expected %s got %s\n", i,
resp[i].out, buffer);
abort_if(resp[i].out && strcmp((const char *)buffer, resp[i].out),
"content");
}
}
/* pass all sizes into the decoder until full */
for(i = 0; i < sizeof(full49) - 1; i++) {
struct dohentry d;
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)full49,
i, CURL_DNS_TYPE_A, &d);
if(!rc) {
/* none of them should work */
curl_mfprintf(stderr, "%zu: %d\n", i, (int)rc);
abort_if(!rc, "error rc");
}
}
/* and try all pieces from the other end of the packet */
for(i = 1; i < sizeof(full49); i++) {
struct dohentry d;
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)&full49[i],
sizeof(full49) - i - 1, CURL_DNS_TYPE_A, &d);
if(!rc) {
/* none of them should work */
curl_mfprintf(stderr, "2 %zu: %d\n", i, (int)rc);
abort_if(!rc, "error rc");
}
}
{
DOHcode rc;
struct dohentry d;
struct dohaddr *a;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)full49,
sizeof(full49) - 1, CURL_DNS_TYPE_A, &d);
fail_if(d.numaddr != 1, "missing address");
a = &d.addr[0];
p = &a->ip.v4[0];
curl_msnprintf((char *)buffer, sizeof(buffer),
"%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
if(rc || strcmp((const char *)buffer, "127.0.0.1")) {
curl_mfprintf(stderr, "bad address decoded: %s, rc == %d\n", buffer,
(int)rc);
abort_if(rc || strcmp((const char *)buffer, "127.0.0.1"), "bad address");
}
fail_if(d.numcname, "bad cname counter");
}
#endif
UNITTEST_END_SIMPLE
}