From: Terry Wilson Date: Tue, 18 Oct 2011 23:42:09 +0000 (+0000) Subject: Don't resolve numeric hosts or contact unresolved hosts X-Git-Tag: 10.0.0-rc1~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa0c65619d4d5a936af607f1948bdf1e6755b58a;p=thirdparty%2Fasterisk.git Don't resolve numeric hosts or contact unresolved hosts If a SIP dial string contains a numeric hostname that is not a peer name, don't try to resolve it as it is unlikely that someone really means Dial(SIP/0.0.4.26) when Dial(SIP/1050) is called. Also, make sure that create_addr returns -1 if an address isn't resolved so that we don't attempt to send SIP requests to an address that doesn't resolve. (closes issue ASTERISK-17146, ASTERISK-17716) Review: https://reviewboard.asterisk.org/r/1532/ ........ Merged revisions 341314 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@341315 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 09e19ecaa8..63e95051aa 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -265,6 +265,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/data.h" #include "asterisk/aoc.h" #include "asterisk/message.h" +#include "asterisk/pval.h" #include "sip/include/sip.h" #include "sip/include/globals.h" #include "sip/include/config_parser.h" @@ -5311,6 +5312,12 @@ static int create_addr(struct sip_pvt *dialog, const char *opeer, struct ast_soc dialog->relatedpeer = sip_ref_peer(peer, "create_addr: setting dialog's relatedpeer pointer"); sip_unref_peer(peer, "create_addr: unref peer from sip_find_peer hashtab lookup"); return res; + } else if (is_int(peername)) { + /* Although an IPv4 hostname *could* be represented as a 32-bit integer, it is uncommon and + * it makes dialing SIP/${EXTEN} for a peer that isn't defined resolve to an IP that is + * almost certainly not intended. It is much better to just reject purely numeric hostnames */ + ast_log(LOG_WARNING, "Purely numeric hostname (%s), and not a peer--rejecting!\n", peername); + return -1; } else { dialog->rtptimeout = global_rtptimeout; dialog->rtpholdtimeout = global_rtpholdtimeout; @@ -5352,6 +5359,7 @@ static int create_addr(struct sip_pvt *dialog, const char *opeer, struct ast_soc if (ast_sockaddr_resolve_first(&dialog->sa, hostn, 0)) { ast_log(LOG_WARNING, "No such host: %s\n", peername); + return -1; } if (srv_ret > 0) {