diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-08-23 12:07:22 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-08-23 12:07:22 (GMT) |
commit | b3f490fa84391bd5d1cd9ff82d6235e527a22c28 (patch) | |
tree | 3b39a4abf553fc24d1fe25b10cb3b153c4653403 | |
parent | 79503b8aa18649d94ee9a98f1386d7f58787a408 (diff) | |
download | tcl-b3f490fa84391bd5d1cd9ff82d6235e527a22c28.zip tcl-b3f490fa84391bd5d1cd9ff82d6235e527a22c28.tar.gz tcl-b3f490fa84391bd5d1cd9ff82d6235e527a22c28.tar.bz2 |
[Bug 3496014] Protect Tcl_SetByteArrayObj for invalid values
(Backported from Tcl 8.6)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | generic/tclBinary.c | 7 |
2 files changed, 11 insertions, 1 deletions
@@ -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); |