about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2022-06-03 11:03:00 -0400
committerRich Felker <dalias@aerifal.cx>2022-06-03 11:03:00 -0400
commit6c858d6fd4df8b5498ef2cae66c8f3c3eff1587b (patch)
tree0db4e25788d0be57296f645cd51e10b9713a0a94
parent8974ef2124118e4ed8cad7ee0534b36e5c584c4e (diff)
downloadmusl-6c858d6fd4df8b5498ef2cae66c8f3c3eff1587b.tar.gz
musl-6c858d6fd4df8b5498ef2cae66c8f3c3eff1587b.tar.xz
musl-6c858d6fd4df8b5498ef2cae66c8f3c3eff1587b.zip
ensure distinct query id for parallel A and AAAA queries in resolver
assuming a reasonable realtime clock, res_mkquery is highly unlikely
to generate the same query id twice in a row, but it's possible with a
very low-resolution system clock or under extreme delay of forward
progress. when it happens, res_msend fails to wait for both answers,
and instead stops listening after getting two answers to the same
query (A or AAAA).

to avoid this, increment one byte of the second query's id if it
matches the first query's. don't bother checking if the second byte is
also equal, since it doesn't matter; we just need to ensure that at
least one byte is distinct.
-rw-r--r--src/network/lookup_name.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c
index aa558c19..b5232ce8 100644
--- a/src/network/lookup_name.c
+++ b/src/network/lookup_name.c
@@ -155,6 +155,9 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
 			if (qlens[nq] == -1)
 				return EAI_NONAME;
 			qbuf[nq][3] = 0; /* don't need AD flag */
+			/* Ensure query IDs are distinct. */
+			if (nq && qbuf[nq][0] == qbuf[0][0])
+				qbuf[nq][0]++;
 			nq++;
 		}
 	}