summaryrefslogtreecommitdiff
path: root/ares_gethostbyname.c
diff options
context:
space:
mode:
authorSteinar H. Gunderson <sesse@google.com>2007-09-29 13:52:14 +0000
committerSteinar H. Gunderson <sesse@google.com>2007-09-29 13:52:14 +0000
commitcccd9a58cd2ef71da3c2f9e8ed598771edbb2ed7 (patch)
tree2aee6b89c78314d8543c56fb5f61d74abbab2c96 /ares_gethostbyname.c
parent49162e5b67d5b27cce4f364c540b0b8b5a18f6ff (diff)
downloadc-ares-cccd9a58cd2ef71da3c2f9e8ed598771edbb2ed7.tar.gz
c-ares-cccd9a58cd2ef71da3c2f9e8ed598771edbb2ed7.tar.bz2
c-ares-cccd9a58cd2ef71da3c2f9e8ed598771edbb2ed7.zip
Be stricter about what's a valid IP address in fake_hostent. (Patch from the Google tree.)
Diffstat (limited to 'ares_gethostbyname.c')
-rw-r--r--ares_gethostbyname.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/ares_gethostbyname.c b/ares_gethostbyname.c
index 49ae53e..7a4aad6 100644
--- a/ares_gethostbyname.c
+++ b/ares_gethostbyname.c
@@ -209,7 +209,27 @@ static int fake_hostent(const char *name, int family, ares_host_callback callbac
struct in6_addr in6;
if (family == AF_INET)
- result = ((in.s_addr = inet_addr(name)) == INADDR_NONE ? 0 : 1);
+ {
+ /* It only looks like an IP address if it's all numbers and dots. */
+ int numdots = 0;
+ const char *p;
+ for (p = name; *p; p++)
+ {
+ if (!isdigit(*p) && *p != '.') {
+ return 0;
+ } else if (*p == '.') {
+ numdots++;
+ }
+ }
+
+ /* if we don't have 3 dots, it is illegal
+ * (although inet_addr doesn't think so).
+ */
+ if (numdots != 3)
+ result = 0;
+ else
+ result = ((in.s_addr = inet_addr(name)) == INADDR_NONE ? 0 : 1);
+ }
else if (family == AF_INET6)
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);