683572
From 14d26b44a1d7eee67837ec0ea8fb0368ac6fe33e Mon Sep 17 00:00:00 2001
683572
From: Tony Cook <tony@develop-help.com>
683572
Date: Tue, 20 Aug 2019 15:43:05 +1000
683572
Subject: [PATCH] (perl #134230) don't interpret 0x, 0b when numifying strings
683572
MIME-Version: 1.0
683572
Content-Type: text/plain; charset=UTF-8
683572
Content-Transfer-Encoding: 8bit
683572
683572
Signed-off-by: Petr Písař <ppisar@redhat.com>
683572
---
683572
 numeric.c  | 9 +++++++++
683572
 t/op/int.t | 5 ++++-
683572
 2 files changed, 13 insertions(+), 1 deletion(-)
683572
683572
diff --git a/numeric.c b/numeric.c
683572
index f5eadc8173..fae2eb3c6d 100644
683572
--- a/numeric.c
683572
+++ b/numeric.c
683572
@@ -1551,6 +1551,15 @@ Perl_my_atof3(pTHX_ const char* orig, NV* value, const STRLEN len)
683572
         if ((endp = S_my_atof_infnan(aTHX_ s, negative, send, value)))
683572
             return endp;
683572
 
683572
+        /* strtold() accepts 0x-prefixed hex and in POSIX implementations,
683572
+           0b-prefixed binary numbers, which is backward incompatible
683572
+        */
683572
+        if ((len == 0 || len >= 2) && *s == '0' &&
683572
+            (isALPHA_FOLD_EQ(s[1], 'x') || isALPHA_FOLD_EQ(s[1], 'b'))) {
683572
+            *value = 0;
683572
+            return (char *)s+1;
683572
+        }
683572
+
683572
         /* If the length is passed in, the input string isn't NUL-terminated,
683572
          * and in it turns out the function below assumes it is; therefore we
683572
          * create a copy and NUL-terminate that */
683572
diff --git a/t/op/int.t b/t/op/int.t
683572
index 7e936da68d..b730ab2672 100644
683572
--- a/t/op/int.t
683572
+++ b/t/op/int.t
683572
@@ -7,7 +7,7 @@ BEGIN {
683572
     require Config;
683572
 }
683572
 
683572
-plan 17;
683572
+plan 19;
683572
 
683572
 # compile time evaluation
683572
 
683572
@@ -83,3 +83,6 @@ SKIP:
683572
         cmp_ok($x, "==", int($x), "check $x == int($x)");
683572
     }
683572
 }
683572
+
683572
+is(1+"0x10", 1, "check string '0x' prefix not treated as hex");
683572
+is(1+"0b10", 1, "check string '0b' prefix not treated as binary");
683572
-- 
683572
2.21.0
683572