diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-21 04:09:23 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-21 04:09:23 +0000 |
commit | a2447d37bb8f5620bc3c4dc7446de6bbfe21524e (patch) | |
tree | bb5f711ba270c86b0d441dbb8f893f374255cfef /utils.c | |
parent | 26d558831d2f5c659417672fca8957a3ab9241be (diff) |
Be sure to avoid octal interpretations of IP's (bug #5477)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6838 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'utils.c')
-rwxr-xr-x | utils.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -171,6 +171,7 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp) { int res; int herrno; + int dots=0; const char *s; struct hostent *result = NULL; /* Although it is perfectly legitimate to lookup a pure integer, for @@ -180,12 +181,22 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp) s = host; res = 0; while(s && *s) { - if (!isdigit(*s)) + if (*s == '.') + dots++; + else if (!isdigit(*s)) break; s++; } - if (!s || !*s) + if (!s || !*s) { + /* Forge a reply for IP's to avoid octal IP's being interpreted as octal */ + if (dots != 3) + return NULL; + hp->hp.h_addr = hp->buf; + if (inet_pton(AF_INET, host, hp->hp.h_addr) > 0) + return &hp->hp; return NULL; + + } #ifdef SOLARIS result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno); |