<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 7, 2021 at 5:32 PM Philippe Mathieu-Daudé <<a href="mailto:philmd@redhat.com">philmd@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The ALLOCA(3) man-page mentions its "use is discouraged".<br>
<br>
For now get_dns_addr_resolv_conf() is called with pointer to<br>
a in_addr/in6_addr structure, and its size. Declare a union<br>
of these structures on the stack, able to hold both of them.<br>
This allows us to remove the alloca() call, keeping the buffer<br>
on the stack.<br>
<br>
Add an assertion in the unlikely case another inet address<br>
is handled by this function.<br>
<br>
Signed-off-by: Philippe Mathieu-Daudé <<a href="mailto:philmd@redhat.com" target="_blank">philmd@redhat.com</a>><br></blockquote><div><br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
Sorry no pull-req, I don't have my 2FA token with me.<br>
</blockquote><div><br></div><div><div>Made one for you and merged it:</div><div><a href="https://gitlab.freedesktop.org/slirp/libslirp/-/merge_requests/84">https://gitlab.freedesktop.org/slirp/libslirp/-/merge_requests/84</a></div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
 src/slirp.c | 14 +++++++++-----<br>
 1 file changed, 9 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/slirp.c b/src/slirp.c<br>
index ee4ce36..5d60cb5 100644<br>
--- a/src/slirp.c<br>
+++ b/src/slirp.c<br>
@@ -249,9 +249,13 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr,<br>
     char buff2[257];<br>
     FILE *f;<br>
     int found = 0;<br>
-    void *tmp_addr = alloca(addrlen);<br>
+    union {<br>
+        struct in_addr dns_addr;<br>
+        struct in6_addr dns6_addr;<br>
+    } tmp_addr;<br>
     unsigned if_index;<br>
<br>
+    assert(sizeof(tmp_addr) >= addrlen);<br>
     f = fopen("/etc/resolv.conf", "r");<br>
     if (!f)<br>
         return -1;<br>
@@ -267,13 +271,13 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr,<br>
                 if_index = 0;<br>
             }<br>
<br>
-            if (!inet_pton(af, buff2, tmp_addr)) {<br>
+            if (!inet_pton(af, buff2, &tmp_addr)) {<br>
                 continue;<br>
             }<br>
             /* If it's the first one, set it to dns_addr */<br>
             if (!found) {<br>
-                memcpy(pdns_addr, tmp_addr, addrlen);<br>
-                memcpy(cached_addr, tmp_addr, addrlen);<br>
+                memcpy(pdns_addr, &tmp_addr, addrlen);<br>
+                memcpy(cached_addr, &tmp_addr, addrlen);<br>
                 if (scope_id) {<br>
                     *scope_id = if_index;<br>
                 }<br>
@@ -285,7 +289,7 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr,<br>
                 break;<br>
             } else if (slirp_debug & DBG_MISC) {<br>
                 char s[INET6_ADDRSTRLEN];<br>
-                const char *res = inet_ntop(af, tmp_addr, s, sizeof(s));<br>
+                const char *res = inet_ntop(af, &tmp_addr, s, sizeof(s));<br>
                 if (!res) {<br>
                     res = "  (string conversion error)";<br>
                 }<br>
-- <br>
2.26.3<br>
<br>
_______________________________________________<br>
Slirp mailing list<br>
<a href="mailto:Slirp@lists.freedesktop.org" target="_blank">Slirp@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/slirp" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/slirp</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Marc-André Lureau<br></div></div>