summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-09-01 17:29:32 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-09-01 17:29:32 (GMT)
commit4a4571c9fe2d509639a55f8a366fd631e67a6800 (patch)
tree8a14a70bb10f79c8b764eac9b06de1e7af757fc7
parentb8db328a5dc663435c02e2b2a67f3d66e16602c9 (diff)
parentc639e72c38ffbe038a79a58991d4c5bb3e027a6f (diff)
downloadtcl-4a4571c9fe2d509639a55f8a366fd631e67a6800.zip
tcl-4a4571c9fe2d509639a55f8a366fd631e67a6800.tar.gz
tcl-4a4571c9fe2d509639a55f8a366fd631e67a6800.tar.bz2
3402540 Corrections to TclParseNumber() to make it reject invalid Nan(Hex).
[scan Inf %g] is portable; remove constraint.
-rw-r--r--ChangeLog7
-rwxr-xr-xgeneric/tclStrToD.c3
-rw-r--r--tests/binary.test17
-rw-r--r--tests/scan.test4
4 files changed, 29 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 746955a..06ece36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-09-01 Don Porter <dgp@users.sourceforge.net>
+
+ * generic/tclStrToD.c: [Bug 3402540] Corrections to TclParseNumber()
+ * tests/binary.test: to make it reject invalid Nan(Hex) strings.
+
+ * tests/scan.test: [scan Inf %g] is portable; remove constraint.
+
2011-08-30 Donal K. Fellows <dkf@users.sf.net>
* generic/tclInterp.c (SlaveCommandLimitCmd, SlaveTimeLimitCmd):
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index a55ee83..f666e08 100755
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -1101,7 +1101,10 @@ TclParseNumber(
d = 10 + c - 'a';
} else if (c >= 'A' && c <= 'F') {
d = 10 + c - 'A';
+ } else {
+ goto endgame;
}
+ numSigDigs++;
significandWide = (significandWide << 4) + d;
state = sNANHEX;
break;
diff --git a/tests/binary.test b/tests/binary.test
index 8b2880b..6c00508 100644
--- a/tests/binary.test
+++ b/tests/binary.test
@@ -2381,6 +2381,23 @@ test binary-63.4 {NaN} ieeeFloatingPoint {
format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
} 0x7ff3123456789abc
+# Make sure TclParseNumber() rejects invalid nan-hex formats [Bug 3402540]
+test binary-63.5 {NaN} -constraints ieeeFloatingPoint -body {
+ binary format q Nan(
+} -returnCodes error -match glob -result {expected floating-point number*}
+test binary-63.6 {NaN} -constraints ieeeFloatingPoint -body {
+ binary format q Nan()
+} -returnCodes error -match glob -result {expected floating-point number*}
+test binary-63.7 {NaN} -constraints ieeeFloatingPoint -body {
+ binary format q Nan(g)
+} -returnCodes error -match glob -result {expected floating-point number*}
+test binary-63.8 {NaN} -constraints ieeeFloatingPoint -body {
+ binary format q Nan(1,2)
+} -returnCodes error -match glob -result {expected floating-point number*}
+test binary-63.9 {NaN} -constraints ieeeFloatingPoint -body {
+ binary format q Nan(1234567890abcd)
+} -returnCodes error -match glob -result {expected floating-point number*}
+
test binary-64.1 {NaN} -constraints ieeeFloatingPoint -body {
binary scan [binary format w 0x7ff8000000000000] q d
set d
diff --git a/tests/scan.test b/tests/scan.test
index 84f22b4..97ad5eb 100644
--- a/tests/scan.test
+++ b/tests/scan.test
@@ -753,11 +753,11 @@ testConstraint ieeeFloatingPoint [testIEEE]
# scan infinities - not working
-test scan-14.1 {infinity} ieeeFloatingPoint {
+test scan-14.1 {infinity} {
scan Inf %g d
set d
} Inf
-test scan-14.2 {infinity} ieeeFloatingPoint {
+test scan-14.2 {infinity} {
scan -Inf %g d
set d
} -Inf