doh: rename symbols to avoid collision with mingw-w64 headers

Collision happens when building with mingw-w64 v3 or v2 while targeting
Vista or newer. `iphlpapi.h` includes `windns.h` in this case, which
defines macros named `DNS_TYPE_*`, colliding with curl doh enums.

The issue was fixed in mingw-w64 v4:
ea95d55e33

Fixes:
```
lib/doh.h:54:3: error: expected identifier before numeric constant
   DNS_TYPE_A = 1,
   ^
```
Ref: https://github.com/curl/curl/actions/runs/16551209676/job/46806303365?pr=18009#step:10:17

This workaround seems harmless and generally good practice, but
another option is to require mingw-w64 v4.

Ref: #18009
Closes #18041
This commit is contained in:
Viktor Szakats 2025-07-27 15:09:08 +02:00
parent 6080143f9d
commit 08f97cbf5c
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
4 changed files with 50 additions and 48 deletions

View File

@ -484,7 +484,7 @@ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
data->sub_xfer_done = doh_probe_done;
/* create IPv4 DoH request */
result = doh_probe_run(data, DNS_TYPE_A,
result = doh_probe_run(data, CURL_DNS_TYPE_A,
hostname, data->set.str[STRING_DOH],
data->multi,
&dohp->probe_resp[DOH_SLOT_IPV4].probe_mid);
@ -495,7 +495,7 @@ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
#ifdef USE_IPV6
if((ip_version != CURL_IPRESOLVE_V4) && Curl_ipv6works(data)) {
/* create IPv6 DoH request */
result = doh_probe_run(data, DNS_TYPE_AAAA,
result = doh_probe_run(data, CURL_DNS_TYPE_AAAA,
hostname, data->set.str[STRING_DOH],
data->multi,
&dohp->probe_resp[DOH_SLOT_IPV6].probe_mid);
@ -514,7 +514,7 @@ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
if(!qname)
goto error;
}
result = doh_probe_run(data, DNS_TYPE_HTTPS,
result = doh_probe_run(data, CURL_DNS_TYPE_HTTPS,
qname ? qname : hostname, data->set.str[STRING_DOH],
data->multi,
&dohp->probe_resp[DOH_SLOT_HTTPS_RR].probe_mid);
@ -581,7 +581,7 @@ static void doh_store_a(const unsigned char *doh, int index,
/* silently ignore addresses over the limit */
if(d->numaddr < DOH_MAX_ADDR) {
struct dohaddr *a = &d->addr[d->numaddr];
a->type = DNS_TYPE_A;
a->type = CURL_DNS_TYPE_A;
memcpy(&a->ip.v4, &doh[index], 4);
d->numaddr++;
}
@ -593,7 +593,7 @@ static void doh_store_aaaa(const unsigned char *doh, int index,
/* silently ignore addresses over the limit */
if(d->numaddr < DOH_MAX_ADDR) {
struct dohaddr *a = &d->addr[d->numaddr];
a->type = DNS_TYPE_AAAA;
a->type = CURL_DNS_TYPE_AAAA;
memcpy(&a->ip.v6, &doh[index], 16);
d->numaddr++;
}
@ -681,29 +681,29 @@ static DOHcode doh_rdata(const unsigned char *doh,
DOHcode rc;
switch(type) {
case DNS_TYPE_A:
case CURL_DNS_TYPE_A:
if(rdlength != 4)
return DOH_DNS_RDATA_LEN;
doh_store_a(doh, index, d);
break;
case DNS_TYPE_AAAA:
case CURL_DNS_TYPE_AAAA:
if(rdlength != 16)
return DOH_DNS_RDATA_LEN;
doh_store_aaaa(doh, index, d);
break;
#ifdef USE_HTTPSRR
case DNS_TYPE_HTTPS:
case CURL_DNS_TYPE_HTTPS:
rc = doh_store_https(doh, index, d, rdlength);
if(rc)
return rc;
break;
#endif
case DNS_TYPE_CNAME:
case CURL_DNS_TYPE_CNAME:
rc = doh_store_cname(doh, dohlen, (unsigned int)index, d);
if(rc)
return rc;
break;
case DNS_TYPE_DNAME:
case CURL_DNS_TYPE_DNAME:
/* explicit for clarity; just skip; rely on synthesized CNAME */
break;
default:
@ -770,8 +770,8 @@ UNITTEST DOHcode doh_resp_decode(const unsigned char *doh,
return DOH_DNS_OUT_OF_RANGE;
type = doh_get16bit(doh, index);
if((type != DNS_TYPE_CNAME) /* may be synthesized from DNAME */
&& (type != DNS_TYPE_DNAME) /* if present, accept and ignore */
if((type != CURL_DNS_TYPE_CNAME) /* may be synthesized from DNAME */
&& (type != CURL_DNS_TYPE_DNAME) /* if present, accept and ignore */
&& (type != dnstype))
/* Not the same type as was asked for nor CNAME nor DNAME */
return DOH_DNS_UNEXPECTED_TYPE;
@ -855,9 +855,10 @@ UNITTEST DOHcode doh_resp_decode(const unsigned char *doh,
return DOH_DNS_MALFORMAT; /* something is wrong */
#ifdef USE_HTTTPS
if((type != DNS_TYPE_NS) && !d->numcname && !d->numaddr && !d->numhttps_rrs)
if((type != CURL_DNS_TYPE_NS) && !d->numcname && !d->numaddr &&
!d->numhttps_rrs)
#else
if((type != DNS_TYPE_NS) && !d->numcname && !d->numaddr)
if((type != CURL_DNS_TYPE_NS) && !d->numcname && !d->numaddr)
#endif
/* nothing stored! */
return DOH_NO_CONTENT;
@ -873,12 +874,12 @@ static void doh_show(struct Curl_easy *data,
infof(data, "[DoH] TTL: %u seconds", d->ttl);
for(i = 0; i < d->numaddr; i++) {
const struct dohaddr *a = &d->addr[i];
if(a->type == DNS_TYPE_A) {
if(a->type == CURL_DNS_TYPE_A) {
infof(data, "[DoH] A: %u.%u.%u.%u",
a->ip.v4[0], a->ip.v4[1],
a->ip.v4[2], a->ip.v4[3]);
}
else if(a->type == DNS_TYPE_AAAA) {
else if(a->type == CURL_DNS_TYPE_AAAA) {
int j;
char buffer[128] = "[DoH] AAAA: ";
size_t len = strlen(buffer);
@ -948,7 +949,7 @@ static CURLcode doh2ai(const struct dohentry *de, const char *hostname,
for(i = 0; i < de->numaddr; i++) {
size_t ss_size;
CURL_SA_FAMILY_T addrtype;
if(de->addr[i].type == DNS_TYPE_AAAA) {
if(de->addr[i].type == CURL_DNS_TYPE_AAAA) {
#ifndef USE_IPV6
/* we cannot handle IPv6 addresses */
continue;
@ -1025,12 +1026,12 @@ static CURLcode doh2ai(const struct dohentry *de, const char *hostname,
static const char *doh_type2name(DNStype dnstype)
{
switch(dnstype) {
case DNS_TYPE_A:
case CURL_DNS_TYPE_A:
return "A";
case DNS_TYPE_AAAA:
case CURL_DNS_TYPE_AAAA:
return "AAAA";
#ifdef USE_HTTPSRR
case DNS_TYPE_HTTPS:
case CURL_DNS_TYPE_HTTPS:
return "HTTPS";
#endif
default:

View File

@ -51,12 +51,12 @@ typedef enum {
} DOHcode;
typedef enum {
DNS_TYPE_A = 1,
DNS_TYPE_NS = 2,
DNS_TYPE_CNAME = 5,
DNS_TYPE_AAAA = 28,
DNS_TYPE_DNAME = 39, /* RFC6672 */
DNS_TYPE_HTTPS = 65
CURL_DNS_TYPE_A = 1,
CURL_DNS_TYPE_NS = 2,
CURL_DNS_TYPE_CNAME = 5,
CURL_DNS_TYPE_AAAA = 28,
CURL_DNS_TYPE_DNAME = 39, /* RFC6672 */
CURL_DNS_TYPE_HTTPS = 65
} DNStype;
enum doh_slot_num {

View File

@ -55,11 +55,11 @@ static CURLcode test_unit1650(char *arg)
};
static const struct dohrequest req[] = {
{"test.host.name", DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, DOH_OK },
{"test.host.name", DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, DOH_OK },
{"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",
DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
CURL_DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
};
struct dohresp {
@ -82,43 +82,43 @@ static CURLcode test_unit1650(char *arg)
static const char full49[] = DNS_FOO_EXAMPLE_COM;
static const struct dohresp resp[] = {
{"\x00\x00", 2, DNS_TYPE_A, DOH_TOO_SMALL_BUFFER, NULL },
{"\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,
DNS_TYPE_A, DOH_DNS_BAD_ID, NULL },
CURL_DNS_TYPE_A, DOH_DNS_BAD_ID, NULL },
{"\x00\x00\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
DNS_TYPE_A, DOH_DNS_BAD_RCODE, NULL },
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,
DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
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,
DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
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,
DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
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,
DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
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,
DNS_TYPE_A, DOH_OK, "anywhere.really "},
CURL_DNS_TYPE_A, DOH_OK, "anywhere.really "},
{DNS_FOO_EXAMPLE_COM, 49, DNS_TYPE_A, DOH_OK, "127.0.0.1 "},
{DNS_FOO_EXAMPLE_COM, 49, CURL_DNS_TYPE_A, DOH_OK, "127.0.0.1 "},
{"\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\x00\x37\x00\x10\x20\x20"
"\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20", 62,
DNS_TYPE_AAAA, DOH_OK,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 " },
{"\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,
DNS_TYPE_A, DOH_DNS_LABEL_LOOP, NULL},
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"
@ -129,7 +129,7 @@ static CURLcode test_unit1650(char *arg)
"\00\x04\x01\x01\x01\x01", /* RDDATA */
62 + 30,
DNS_TYPE_AAAA, DOH_OK,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 " },
/* packet with ARCOUNT == 1 */
@ -141,7 +141,7 @@ static CURLcode test_unit1650(char *arg)
"\00\x04\x01\x01\x01\x01", /* RDDATA */
62 + 30,
DNS_TYPE_AAAA, DOH_OK,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 " },
};
@ -194,7 +194,7 @@ static CURLcode test_unit1650(char *arg)
size_t o;
struct dohaddr *a;
a = &d.addr[u];
if(resp[i].type == DNS_TYPE_A) {
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);
@ -236,7 +236,8 @@ static CURLcode test_unit1650(char *arg)
struct dohentry d;
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)full49, i, DNS_TYPE_A, &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, rc);
@ -250,7 +251,7 @@ static CURLcode test_unit1650(char *arg)
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)&full49[i], sizeof(full49)-i-1,
DNS_TYPE_A, &d);
CURL_DNS_TYPE_A, &d);
if(!rc) {
/* none of them should work */
curl_mfprintf(stderr, "2 %zu: %d\n", i, rc);
@ -264,7 +265,7 @@ static CURLcode test_unit1650(char *arg)
struct dohaddr *a;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)full49, sizeof(full49)-1,
DNS_TYPE_A, &d);
CURL_DNS_TYPE_A, &d);
fail_if(d.numaddr != 1, "missing address");
a = &d.addr[0];
p = &a->ip.v4[0];

View File

@ -98,7 +98,7 @@ static CURLcode test_unit1655(char *arg)
victim.canary1 = 87; /* magic numbers, arbitrarily picked */
victim.canary2 = 35;
victim.canary3 = 41;
d = doh_req_encode(name, DNS_TYPE_A, victim.dohbuffer,
d = doh_req_encode(name, CURL_DNS_TYPE_A, victim.dohbuffer,
sizeof(struct demo), /* allow room for overflow */
&olen);
@ -130,7 +130,7 @@ static CURLcode test_unit1655(char *arg)
/* run normal cases and try to trigger buffer length related errors */
do {
DNStype dnstype = DNS_TYPE_A;
DNStype dnstype = CURL_DNS_TYPE_A;
unsigned char buffer[128];
const size_t buflen = sizeof(buffer);
const size_t magic1 = 9765;