* [PATCH gwproxy v1 1/2] dns: add a new restyp GWP_DNS_RESTYP_DEFAULT
2025-07-28 16:07 [PATCH gwproxy v1 0/2] Fix missing validation of restyp in dns Ahmad Gani
@ 2025-07-28 16:07 ` Ahmad Gani
2025-07-28 16:07 ` [PATCH gwproxy v1 2/2] dns: validate restyp on initialization Ahmad Gani
2025-07-28 16:14 ` [PATCH gwproxy v1 0/2] Fix missing validation of restyp in dns Ammar Faizi
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Gani @ 2025-07-28 16:07 UTC (permalink / raw)
To: Ammar Faizi; +Cc: Ahmad Gani, GNU/Weeb Mailing List
The new restyp is required to handle unspecified restyp.
Signed-off-by: Ahmad Gani <reyuki@gnuweeb.org>
---
src/gwproxy/dns.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/gwproxy/dns.h b/src/gwproxy/dns.h
index c9dea0a10d62..7d62d3f9b89e 100644
--- a/src/gwproxy/dns.h
+++ b/src/gwproxy/dns.h
@@ -31,6 +31,7 @@ struct gwp_dns_entry {
};
enum {
+ GWP_DNS_RESTYP_DEFAULT = 0,
GWP_DNS_RESTYP_IPV4_ONLY = 1,
GWP_DNS_RESTYP_IPV6_ONLY = 2,
GWP_DNS_RESTYP_PREFER_IPV4 = 3,
--
Ahmad Gani
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH gwproxy v1 2/2] dns: validate restyp on initialization
2025-07-28 16:07 [PATCH gwproxy v1 0/2] Fix missing validation of restyp in dns Ahmad Gani
2025-07-28 16:07 ` [PATCH gwproxy v1 1/2] dns: add a new restyp GWP_DNS_RESTYP_DEFAULT Ahmad Gani
@ 2025-07-28 16:07 ` Ahmad Gani
2025-07-28 16:14 ` [PATCH gwproxy v1 0/2] Fix missing validation of restyp in dns Ammar Faizi
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Gani @ 2025-07-28 16:07 UTC (permalink / raw)
To: Ammar Faizi; +Cc: Ahmad Gani, GNU/Weeb Mailing List
Return EINVAL on initialization if restyp is invalid.
And then prefer ipv4 if GWP_DNS_RESTYP_DEFAULT is used.
Fixes: 82c86a7256d6 ("gwproxy/dns: Replace the old DNS cache system with a new one.")
Signed-off-by: Ahmad Gani <reyuki@gnuweeb.org>
---
src/gwproxy/dns.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/gwproxy/dns.c b/src/gwproxy/dns.c
index f7cbcb2d6e89..b189b33127af 100644
--- a/src/gwproxy/dns.c
+++ b/src/gwproxy/dns.c
@@ -619,7 +619,8 @@ static int fetch_addr(struct gwp_dns_cache_entry *e, struct gwp_sockaddr *addr,
if (!fetch_i4(e, addr, port))
return -EHOSTUNREACH;
}
- } else if (restyp == GWP_DNS_RESTYP_PREFER_IPV4) {
+ } else if (restyp == GWP_DNS_RESTYP_PREFER_IPV4 ||
+ restyp == GWP_DNS_RESTYP_DEFAULT) {
if (!fetch_i4(e, addr, port)) {
if (!fetch_i6(e, addr, port))
return -EHOSTUNREACH;
@@ -679,11 +680,28 @@ static void free_cache(struct gwp_dns_cache *cache)
cache = NULL;
}
+static inline bool validate_restyp(int restyp)
+{
+ switch (restyp) {
+ case GWP_DNS_RESTYP_DEFAULT:
+ case GWP_DNS_RESTYP_IPV4_ONLY:
+ case GWP_DNS_RESTYP_IPV6_ONLY:
+ case GWP_DNS_RESTYP_PREFER_IPV4:
+ case GWP_DNS_RESTYP_PREFER_IPV6:
+ return true;
+ default:
+ return false;
+ }
+}
+
int gwp_dns_ctx_init(struct gwp_dns_ctx **ctx_p, const struct gwp_dns_cfg *cfg)
{
struct gwp_dns_ctx *ctx;
int r;
+ if (!validate_restyp(cfg->restyp))
+ return -EINVAL;
+
ctx = calloc(1, sizeof(*ctx));
if (!ctx)
return -ENOMEM;
--
Ahmad Gani
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH gwproxy v1 0/2] Fix missing validation of restyp in dns
2025-07-28 16:07 [PATCH gwproxy v1 0/2] Fix missing validation of restyp in dns Ahmad Gani
2025-07-28 16:07 ` [PATCH gwproxy v1 1/2] dns: add a new restyp GWP_DNS_RESTYP_DEFAULT Ahmad Gani
2025-07-28 16:07 ` [PATCH gwproxy v1 2/2] dns: validate restyp on initialization Ahmad Gani
@ 2025-07-28 16:14 ` Ammar Faizi
2 siblings, 0 replies; 4+ messages in thread
From: Ammar Faizi @ 2025-07-28 16:14 UTC (permalink / raw)
To: Ahmad Gani; +Cc: Ammar Faizi, GNU/Weeb Mailing List
On Mon, 28 Jul 2025 23:07:56 +0700, Ahmad Gani wrote:
> The dns test is buggy, when I run make test it always ended up with
> EINVAL. And it turned out restyp is not validated in the fetch_addr,
> this patch add validation in the initialization stage.
Applied, thanks!
[1/2] dns: add a new restyp GWP_DNS_RESTYP_DEFAULT
commit: 3d59d38b8d41e5bb9c6a11f2b0d3f54787c4ff97
[2/2] dns: validate restyp on initialization
commit: 398bc212124a0ce557fb7069fe976eba111983e1
Best regards,
--
Ammar Faizi
^ permalink raw reply [flat|nested] 4+ messages in thread