lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Sat, 31 Mar 2012 19:40:23 +0400
From:	Sergey Fionov <fionov@...il.com>
To:	netdev@...r.kernel.org
Subject: [PATCH iputils] ping,ping6: Fallback to numeric addresses while exiting

When user presses Ctrl-C ping waits for pr_addr() to be finished and
then exits. With poor connection it may result in stuck at
gethostbyaddr().

This patch changes handling of exit signals. After setting "exiting"
flag we longjmp() from gethostbyaddr() and print numeric addresses.
---
 ping.c        |    7 ++++++-
 ping6.c       |    6 +++++-
 ping_common.c |    4 ++++
 ping_common.h |    4 ++++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/ping.c b/ping.c
index eacb29d..ddce1fe 100644
--- a/ping.c
+++ b/ping.c
@@ -1160,12 +1160,17 @@ pr_addr(__u32 addr)
 	struct hostent *hp;
 	static char buf[4096];

-	if ((options & F_NUMERIC) ||
+	in_pr_addr = !setjmp(pr_addr_jmp);
+
+	if (exiting || (options & F_NUMERIC) ||
 	    !(hp = gethostbyaddr((char *)&addr, 4, AF_INET)))
 		sprintf(buf, "%s", inet_ntoa(*(struct in_addr *)&addr));
 	else
 		snprintf(buf, sizeof(buf), "%s (%s)", hp->h_name,
 			 inet_ntoa(*(struct in_addr *)&addr));
+
+	in_pr_addr = 0;
+
 	return(buf);
 }

diff --git a/ping6.c b/ping6.c
index c5ff881..f5beaf2 100644
--- a/ping6.c
+++ b/ping6.c
@@ -1538,9 +1538,13 @@ char * pr_addr(struct in6_addr *addr)
 {
 	struct hostent *hp = NULL;

-	if (!(options&F_NUMERIC))
+	in_pr_addr = !setjmp(pr_addr_jmp);
+
+	if (!(exiting || options&F_NUMERIC))
 		hp = gethostbyaddr((__u8*)addr, sizeof(struct in6_addr), AF_INET6);

+	in_pr_addr = 0;
+
 	return hp ? hp->h_name : pr_addr_n(addr);
 }

diff --git a/ping_common.c b/ping_common.c
index 82320b1..b45b5c8 100644
--- a/ping_common.c
+++ b/ping_common.c
@@ -30,6 +30,8 @@ struct timeval start_time, cur_time;
 volatile int exiting;
 volatile int status_snapshot;
 int confirm = 0;
+int in_pr_addr = 0;		/* pr_addr() is executing */
+jmp_buf pr_addr_jmp;

 /* Stupid workarounds for bugs/missing functionality in older linuces.
  * confirm_flag fixes refusing service of kernels without MSG_CONFIRM.
@@ -248,6 +250,8 @@ void common_options(int ch)
 static void sigexit(int signo)
 {
 	exiting = 1;
+	if (in_pr_addr)
+		longjmp(pr_addr_jmp, 0);
 }

 static void sigstatus(int signo)
diff --git a/ping_common.h b/ping_common.h
index 730cf9b..2262f91 100644
--- a/ping_common.h
+++ b/ping_common.h
@@ -16,6 +16,7 @@
 #include <errno.h>
 #include <string.h>
 #include <netdb.h>
+#include <setjmp.h>

 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -206,3 +207,6 @@ extern int gather_statistics(__u8 *ptr, int icmplen,
 			     int csfailed, struct timeval *tv, char *from,
 			     void (*pr_reply)(__u8 *ptr, int cc));
 extern void print_timestamp(void);
+
+extern int in_pr_addr;
+extern jmp_buf pr_addr_jmp;
-- 
1.7.8.5
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ