File 0748-Prevent-crash-when-looking-up-cname-from-bogus-reply.patch of Package erlang

From 968e0eb8c2fb45b564424fae362aab0359c64dd9 Mon Sep 17 00:00:00 2001
From: Raimo Niskanen <raimo@erlang.org>
Date: Fri, 23 Apr 2021 16:28:43 +0200
Subject: [PATCH] Prevent crash when looking up cname from bogus reply

Do not trust that an answer contains the requested type and use
it without type checking to do a CNAME lookup.

Bug report and patch by Tomasz Motyl.
---
 lib/kernel/src/inet_db.erl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/kernel/src/inet_db.erl b/lib/kernel/src/inet_db.erl
index ff5bdd8f26..a30c552139 100644
--- a/lib/kernel/src/inet_db.erl
+++ b/lib/kernel/src/inet_db.erl
@@ -703,6 +703,14 @@ lookup_type(Domain, Type) ->
 lookup_cname(Domain) ->
     [R#dns_rr.data || R <- lookup_rr(Domain, in, ?S_CNAME) ].
 
+lookup_cname(Domain, Type) ->
+    case Type of
+     a -> [];
+     aaaa -> [];
+     cname -> lookup_cname(Domain);
+     _ -> []
+    end.
+
 %% Have to do all lookups (changes to the db) in the
 %% process in order to make it possible to refresh the cache.
 lookup_rr(Domain, Class, Type) ->
@@ -778,9 +786,10 @@ ent_gethostbyaddr(RRs, IP, AddrType, Length) ->
 		    ?dbg("gethostbyaddr found extra=~p~n", [TR]);
 	       true -> ok
 	    end,
+            Type = RR#dns_rr.type,
 	    Domain = RR#dns_rr.data,
 	    H = #hostent { h_name = Domain,
-			   h_aliases = lookup_cname(Domain),
+			   h_aliases = lookup_cname(Domain, Type),
 			   h_addr_list = [IP],
 			   h_addrtype = AddrType,
 			   h_length = Length },
-- 
2.26.2

openSUSE Build Service is sponsored by