summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclBinary.c5
-rw-r--r--tests/binary.test21
3 files changed, 24 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 02203eb..cf19417 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-12-29 Pat Thoyts <patthoyts@users.sourceforge.net>
+
+ * generic/tclBinary.c: Handle completely invalid input to the decode
+ * tests/binary.test: methods [Bug 2922555].
+
2009-12-28 Donal K. Fellows <dkf@users.sf.net>
* unix/Makefile.in (trace-shell, trace-test): [FRQ 1083288]: Added
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index 75b3ca2..042cbed 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBinary.c,v 1.58 2009/12/11 23:10:47 nijtmans Exp $
+ * RCS: @(#) $Id: tclBinary.c,v 1.59 2009/12/29 01:43:23 patthoyts Exp $
*/
#include "tclInt.h"
@@ -2309,6 +2309,7 @@ BinaryDecodeHex(
*cursor++ = UCHAR(value);
value = 0;
}
+ if (cut > size) cut = size;
Tcl_SetByteArrayLength(resultObj, cursor - begin - cut);
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
@@ -2515,6 +2516,7 @@ BinaryDecodeUu(
*cursor++ = (((d[2] - 0x20) & 0x3f) << 6)
| (((d[3] - 0x20) & 0x3f));
}
+ if (cut > size) cut = size;
Tcl_SetByteArrayLength(resultObj, cursor - begin - cut);
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
@@ -2620,6 +2622,7 @@ BinaryDecode64(
*cursor++ = UCHAR((value >> 8) & 0xff);
*cursor++ = UCHAR(value & 0xff);
}
+ if (cut > size) cut = size;
Tcl_SetByteArrayLength(resultObj, cursor - begin - cut);
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
diff --git a/tests/binary.test b/tests/binary.test
index c01cdde..c6b6941 100644
--- a/tests/binary.test
+++ b/tests/binary.test
@@ -10,7 +10,7 @@
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: binary.test,v 1.39 2009/02/22 17:45:21 ferrieux Exp $
+# RCS: @(#) $Id: binary.test,v 1.40 2009/12/29 01:43:23 patthoyts Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
@@ -2473,6 +2473,9 @@ test binary-71.9 {binary decode hex} -body {
set r [binary decode hex "6"]
list [string length $r] $r
} -result {0 {}}
+test binary-71.10 {binary decode hex} -body {
+ string length [binary decode hex " "]
+} -result 0
test binary-72.1 {binary encode base64} -body {
binary encode base64
@@ -2621,6 +2624,9 @@ test binary-73.23 {binary decode base64} -body {
set r [binary decode base64 YWJj]
list [string length $r] $r
} -result {3 abc}
+test binary-73.24 {binary decode base64} -body {
+ string length [binary decode base64 " "]
+} -result 0
test binary-74.1 {binary encode uuencode} -body {
binary encode uuencode
@@ -2668,19 +2674,19 @@ test binary-75.3 {binary decode uuencode} -body {
test binary-75.4 {binary decode uuencode} -body {
binary decode uuencode [string repeat "86)C" 20]
} -result [string repeat abc 20]
-test binary-75.5 {binary encode uuencode} -body {
+test binary-75.5 {binary decode uuencode} -body {
binary decode uuencode "``\$\"`P0``0(#"
} -result "\0\1\2\3\4\0\1\2\3"
-test binary-75.6 {binary encode uuencode} -body {
+test binary-75.6 {binary decode uuencode} -body {
string length [binary decode uuencode {`}]
} -result 0
-test binary-75.7 {binary encode uuencode} -body {
+test binary-75.7 {binary decode uuencode} -body {
string length [binary decode uuencode {``}]
} -result 1
-test binary-75.8 {binary encode uuencode} -body {
+test binary-75.8 {binary decode uuencode} -body {
string length [binary decode uuencode {```}]
} -result 2
-test binary-75.9 {binary encode uuencode} -body {
+test binary-75.9 {binary decode uuencode} -body {
string length [binary decode uuencode {````}]
} -result 3
test binary-75.10 {binary decode uuencode} -body {
@@ -2726,6 +2732,9 @@ test binary-75.25 {binary decode uuencode} -body {
set s "04)\#z"
binary decode uuencode $s
} -returnCodes error -match glob -result {invalid uuencode character "z" at position 4}
+test binary-75.26 {binary decode uuencode} -body {
+ string length [binary decode uuencode " "]
+} -result 0
# cleanup
::tcltest::cleanupTests