summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-08-23 12:07:22 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-08-23 12:07:22 (GMT)
commit77e356e2cee812b76dd325d0f34ad239eb75f82a (patch)
tree3b39a4abf553fc24d1fe25b10cb3b153c4653403
parent843b8497d3c972540e5b12b26ae3055d9df4bf77 (diff)
downloadtcl-77e356e2cee812b76dd325d0f34ad239eb75f82a.zip
tcl-77e356e2cee812b76dd325d0f34ad239eb75f82a.tar.gz
tcl-77e356e2cee812b76dd325d0f34ad239eb75f82a.tar.bz2
[Bug 3496014] Protect Tcl_SetByteArrayObj for invalid values
(Backported from Tcl 8.6)
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclBinary.c7
2 files changed, 11 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b1c9079..74ff19b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-08-23 Jan Nijtmans <nijtmans@users.sf.net>
+
+ * generic/tclBinary.c: [Bug 3496014] (Backport from Tcl 8.6) Protect
+ Tcl_SetByteArrayObj for invalid values.
+
2012-08-20 Don Porter <dgp@users.sourceforge.net>
* generic/tclPathObj.c: [Bug 3559678] Fix bad filename normalization
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index f321b28..8c95305 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -273,10 +273,15 @@ Tcl_SetByteArrayObj(
TclFreeIntRep(objPtr);
Tcl_InvalidateStringRep(objPtr);
+ if (length < 0) {
+ length = 0;
+ }
byteArrayPtr = (ByteArray *) ckalloc(BYTEARRAY_SIZE(length));
byteArrayPtr->used = length;
byteArrayPtr->allocated = length;
- memcpy(byteArrayPtr->bytes, bytes, (size_t) length);
+ if (length && bytes) {
+ memcpy(byteArrayPtr->bytes, bytes, (size_t) length);
+ }
objPtr->typePtr = &tclByteArrayType;
SET_BYTEARRAY(objPtr, byteArrayPtr);