]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
main/stun.c: fix crash upon STUN request timeout
authorSebastien Duthil <sduthil@wazo.community>
Thu, 14 Oct 2021 15:15:30 +0000 (11:15 -0400)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 15 Oct 2021 18:40:34 +0000 (13:40 -0500)
Some ast_stun_request users do not provide a destination address when
sending to a connection-mode socket.

ASTERISK-29691

Change-Id: Idd9114c3380216ba48abfc3c68619e79ad37defc

main/stun.c

index 4e9dac18af71839f84ee0f0e4cd4c9e2acefb447..7a8e0e5f4a231d0c9e9ff9d5645e16d6845f4e37 100644 (file)
@@ -239,17 +239,24 @@ static void append_attr_address(struct stun_attr **attr, int attrval, struct soc
 
 static void handle_stun_timeout(int retry, struct sockaddr_in *dst)
 {
+       char *stun_destination = "";
+       if (dst) {
+               ast_asprintf(&stun_destination, "to '%s' ", ast_inet_ntoa(dst->sin_addr));
+       }
        if (retry < STUN_MAX_RETRIES) {
                ast_log(LOG_NOTICE,
-                       "Attempt %d to send STUN request to '%s' timed out.",
+                       "Attempt %d to send STUN request %stimed out.\n",
                        retry,
-                       ast_inet_ntoa(dst->sin_addr));
+                       stun_destination);
        } else {
                ast_log(LOG_WARNING,
-                       "Attempt %d to send STUN request to '%s' timed out."
+                       "Attempt %d to send STUN request %stimed out. "
                        "Check that the server address is correct and reachable.\n",
                        retry,
-                       ast_inet_ntoa(dst->sin_addr));
+                       stun_destination);
+       }
+       if (dst) {
+               ast_free(stun_destination);
        }
 }