about summary refs log tree commit diff
path: root/src/network/lookup_name.c
diff options
context:
space:
mode:
authorAlexey Izbyshev <izbyshev@ispras.ru>2023-01-29 19:46:51 +0300
committerRich Felker <dalias@aerifal.cx>2023-02-27 10:03:06 -0500
commit9b132e556774c744f9052581d2d8d0fab417e97c (patch)
treecbb516502c92f69bb6b01c82dbb7c30fed845c56 /src/network/lookup_name.c
parent12590c8bbd04ea484cee86812e2258fbdfca0e59 (diff)
downloadmusl-9b132e556774c744f9052581d2d8d0fab417e97c.tar.gz
musl-9b132e556774c744f9052581d2d8d0fab417e97c.tar.xz
musl-9b132e556774c744f9052581d2d8d0fab417e97c.zip
prevent CNAME/PTR parsing from reading data past the response end
DNS parsing callbacks pass the response buffer end instead of the actual
response end to dn_expand, so a malformed DNS response can use message
compression to make dn_expand jump past the response end and attempt to
parse uninitialized parts of that buffer, which might succeed and return
garbage.
Diffstat (limited to 'src/network/lookup_name.c')
-rw-r--r--src/network/lookup_name.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c
index 5f6867cb..f268bcda 100644
--- a/src/network/lookup_name.c
+++ b/src/network/lookup_name.c
@@ -111,13 +111,13 @@ struct dpc_ctx {
 
 #define ABUF_SIZE 768
 
-static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
+static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet, int plen)
 {
 	char tmp[256];
 	int family;
 	struct dpc_ctx *ctx = c;
 	if (rr == RR_CNAME) {
-		if (__dn_expand(packet, (const unsigned char *)packet + ABUF_SIZE,
+		if (__dn_expand(packet, (const unsigned char *)packet + plen,
 		    data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp))
 			strcpy(ctx->canon, tmp);
 		return 0;