diff mbox

[iputils,v2] ping: always accept . delimiter with -i number parsing

Message ID 1464842814-30690-1-git-send-email-vapier@gentoo.org
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Mike Frysinger June 2, 2016, 4:46 a.m. UTC
Always allow #.# format for the -i flag even when the current locale
uses a different separator.  Locale de_DE which uses #,# normally.

Simple testcase:
$ make USE_IDN=1
$ LANG=de_DE.UTF8 ./ping -i 0.5 localhost
$ LANG=de_DE.UTF8 ./ping -i 0,5 localhost

Reported-by: Sergey Fionov <fionov@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 ping_common.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Hideaki Yoshifuji June 2, 2016, 8:28 a.m. UTC | #1
Hi,

Mike Frysinger wrote:
> Always allow #.# format for the -i flag even when the current locale
> uses a different separator.  Locale de_DE which uses #,# normally.
> 
> Simple testcase:
> $ make USE_IDN=1
> $ LANG=de_DE.UTF8 ./ping -i 0.5 localhost
> $ LANG=de_DE.UTF8 ./ping -i 0,5 localhost
> 
> Reported-by: Sergey Fionov <fionov@gmail.com>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---

Applied, thanks.
diff mbox

Patch

diff --git a/ping_common.c b/ping_common.c
index 62f53a6..6054a91 100644
--- a/ping_common.c
+++ b/ping_common.c
@@ -269,11 +269,28 @@  void common_options(int ch)
 		double dbl;
 		char *ep;
 
+#ifdef USE_IDN
+		int try_c_loc = 0;
+ retry_c_loc:
+#endif
+
 		errno = 0;
 		dbl = strtod(optarg, &ep);
 
+#ifdef USE_IDN
+		if (try_c_loc)
+			setlocale(LC_ALL, "");
+#endif
+
 		if (errno || *ep != '\0' ||
 		    !finite(dbl) || dbl < 0.0 || dbl >= (double)INT_MAX / 1000 - 1.0) {
+#ifdef USE_IDN
+			if (!try_c_loc) {
+				try_c_loc = 1;
+				setlocale(LC_ALL, "C");
+				goto retry_c_loc;
+			}
+#endif
 			fprintf(stderr, "ping: bad timing interval\n");
 			exit(2);
 		}