From bd64b0d72a5796a7617a9aa2ee67498b48221abd Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson Date: Sat, 27 Nov 2010 19:09:24 +0100 Subject: [PATCH] ping: Discard single octets as host name. --- ChangeLog | 5 +++++ ping/libping.c | 9 +++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9623bc7..edcbc68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2010-11-27 Mats Erik Andersson + * ping/libping.c (ping_set_dest): Detect a numerical host and + abort if it consists of a single octet. + +2010-11-27 Mats Erik Andersson + * src/inetd.c (pidfile_option): New variable. (pid_file): New variable. (argp_options): Add an option for replacing path of PID file. diff --git a/ping/libping.c b/ping/libping.c index 52590ba..3bff875 100644 --- a/ping/libping.c +++ b/ping/libping.c @@ -260,6 +260,15 @@ ping_set_dest (PING * ping, char *host) { struct sockaddr_in *s_in = &ping->ping_dest.ping_sockaddr; s_in->sin_family = AF_INET; + if (strspn (host, ".0123456789") == strlen (host)) + { + /* Numerical IPv4 address. */ + if (strchr (host, '.') == NULL) + /* Only one octet. Discard. */ + return 1; + /* The resolver expands `10.6' to the address 10.0.0.6, + * which is productive and sensible. */ + } if (inet_aton (host, &s_in->sin_addr)) ping->ping_hostname = strdup (host); else -- 1.7.2.3