summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
diff options
context:
space:
mode:
authordgp@users.sourceforge.net <dgp>2009-02-02 05:47:54 (GMT)
committerdgp@users.sourceforge.net <dgp>2009-02-02 05:47:54 (GMT)
commit66f9130a51ae48c2d26d833e48db99007f0878c6 (patch)
treef06c240cb542972c35da0a24fcc81e5aa5cd8a48 /generic/tclStringObj.c
parent239b2f667e6edb1779a9c4edb5b5c7d05947b7ad (diff)
downloadtcl-66f9130a51ae48c2d26d833e48db99007f0878c6.zip
tcl-66f9130a51ae48c2d26d833e48db99007f0878c6.tar.gz
tcl-66f9130a51ae48c2d26d833e48db99007f0878c6.tar.bz2
* generic/tclStringObj.c (Tcl_(Attempt)SetObjLength): Added
protections against callers asking for negative lengths. It is likely when this happens that an integer overflow is to blame. [Bug 2553906].
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index aebb2e9..f5ba669 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -33,7 +33,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.79 2009/01/21 21:29:05 dgp Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.80 2009/02/02 05:47:54 dgp Exp $ */
#include "tclInt.h"
#include "tommath.h"
@@ -763,6 +763,14 @@ Tcl_SetObjLength(
{
String *stringPtr;
+ if (length < 0) {
+ /*
+ * Setting to a negative length is nonsense. This is probably the
+ * result of overflowing the signed integer range.
+ */
+ Tcl_Panic( "Tcl_SetObjLength: negative length requested: "
+ "%d (integer overflow?)", length);
+ }
if (Tcl_IsShared(objPtr)) {
Tcl_Panic("%s called with shared object", "Tcl_SetObjLength");
}
@@ -876,6 +884,13 @@ Tcl_AttemptSetObjLength(
{
String *stringPtr;
+ if (length < 0) {
+ /*
+ * Setting to a negative length is nonsense. This is probably the
+ * result of overflowing the signed integer range.
+ */
+ return 0;
+ }
if (Tcl_IsShared(objPtr)) {
Tcl_Panic("%s called with shared object", "Tcl_AttemptSetObjLength");
}