]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: on_transaction_stream_error() may free multiple transactions
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 14 Jan 2024 00:40:27 +0000 (09:40 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 15 Jan 2024 10:36:14 +0000 (10:36 +0000)
Fixes #30928.

src/resolve/resolved-dns-transaction.c

index 307630f3c7a1618a5ee99852f7c645cf497b0025..a99f8e8a587f09d8eeacfa3553c7ac233729d849 100644 (file)
@@ -638,9 +638,20 @@ static int on_stream_complete(DnsStream *s, int error) {
                 }
         }
 
-        if (error != 0)
-                LIST_FOREACH(transactions_by_stream, t, s->transactions)
+        if (error != 0) {
+                /* First, detach the stream from the server. Otherwise, transactions attached to this stream
+                 * may be restarted by on_transaction_stream_error() below with this stream. */
+                dns_stream_detach(s);
+
+                /* Do not use LIST_FOREACH() here, as
+                 *     on_transaction_stream_error()
+                 *         -> dns_transaction_complete_errno()
+                 *             -> dns_transaction_free()
+                 * may free multiple transactions in the list. */
+                DnsTransaction *t;
+                while ((t = s->transactions))
                         on_transaction_stream_error(t, error);
+        }
 
         return 0;
 }