From 34e400fe2bffb5cc22e4017590247a1fc1712e38 Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Tue, 11 May 2004 18:41:09 +0000 Subject: [PATCH] Refuse to gethostbyname on a pure integer git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2949 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- utils.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index df068816b4..1ecbc215a5 100755 --- a/utils.c +++ b/utils.c @@ -9,6 +9,7 @@ * the GNU General Public License */ +#include #include #include @@ -120,8 +121,20 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp) { int res; int herrno; + const char *s; struct hostent *result = NULL; - + /* Although it is perfectly legitimate to lookup a pure integer, for + the sake of the sanity of people who like to name their peers as + integers, we break with tradition and refuse to look up a + pure integer */ + s = host; + while(s && *s) { + if (!isdigit(*s)) + break; + s++; + } + if (!s || !*s) + return NULL; res = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &result, &herrno); if (res || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0])