summaryrefslogtreecommitdiffstats
path: root/generic/tclTrace.c
diff options
context:
space:
mode:
authornijtmans <nijtmans>2010-12-06 09:01:49 (GMT)
committernijtmans <nijtmans>2010-12-06 09:01:49 (GMT)
commit5686ea4acac17705c9704829c24608749acd3d12 (patch)
tree82897612b5989945d086ccb23f71868fe1a656f6 /generic/tclTrace.c
parent3a3eeca75b5436a7b68e1464811bdc3528d20cf0 (diff)
downloadtcl-5686ea4acac17705c9704829c24608749acd3d12.zip
tcl-5686ea4acac17705c9704829c24608749acd3d12.tar.gz
tcl-5686ea4acac17705c9704829c24608749acd3d12.tar.bz2
[Bug 3129448]: possible over-allocation on 64-bit platforms
Diffstat (limited to 'generic/tclTrace.c')
-rw-r--r--generic/tclTrace.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/generic/tclTrace.c b/generic/tclTrace.c
index 2e8759e..efbfbb7 100644
--- a/generic/tclTrace.c
+++ b/generic/tclTrace.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclTrace.c,v 1.60 2010/08/22 18:53:26 nijtmans Exp $
+ * RCS: @(#) $Id: tclTrace.c,v 1.61 2010/12/06 09:01:49 nijtmans Exp $
*/
#include "tclInt.h"
@@ -24,11 +24,11 @@ typedef struct {
int flags; /* Operations for which Tcl command is to be
* invoked. */
size_t length; /* Number of non-NUL chars. in command. */
- char command[4]; /* Space for Tcl command to invoke. Actual
+ char command[1]; /* Space for Tcl command to invoke. Actual
* size will be as large as necessary to hold
* command. This field must be the last in the
- * structure, so that it can be larger than 4
- * bytes. */
+ * structure, so that it can be larger than 1
+ * byte. */
} TraceVarInfo;
typedef struct {
@@ -58,11 +58,11 @@ typedef struct {
* deleted too early. Keeps track of how many
* pieces of code have a pointer to this
* structure. */
- char command[4]; /* Space for Tcl command to invoke. Actual
+ char command[1]; /* Space for Tcl command to invoke. Actual
* size will be as large as necessary to hold
* command. This field must be the last in the
- * structure, so that it can be larger than 4
- * bytes. */
+ * structure, so that it can be larger than 1
+ * byte. */
} TraceCommandInfo;
/*
@@ -464,9 +464,8 @@ TraceExecutionObjCmd(
length = (size_t) commandLength;
if ((enum traceOptions) optionIndex == TRACE_ADD) {
TraceCommandInfo *tcmdPtr = (TraceCommandInfo *)
- ckalloc((unsigned) (sizeof(TraceCommandInfo)
- - sizeof(tcmdPtr->command) + length + 1));
-
+ ckalloc((unsigned) ((TclOffset(TraceCommandInfo, command)
+ + 1) + length));
tcmdPtr->flags = flags;
tcmdPtr->stepTrace = NULL;
tcmdPtr->startLevel = 0;
@@ -701,8 +700,8 @@ TraceCommandObjCmd(
length = (size_t) commandLength;
if ((enum traceOptions) optionIndex == TRACE_ADD) {
TraceCommandInfo *tcmdPtr = (TraceCommandInfo *)
- ckalloc((unsigned) (sizeof(TraceCommandInfo)
- - sizeof(tcmdPtr->command) + length + 1));
+ ckalloc((unsigned) ((TclOffset(TraceCommandInfo, command)
+ + 1) + length));
tcmdPtr->flags = flags;
tcmdPtr->stepTrace = NULL;
@@ -902,8 +901,8 @@ TraceVariableObjCmd(
length = (size_t) commandLength;
if ((enum traceOptions) optionIndex == TRACE_ADD) {
CombinedTraceVarInfo *ctvarPtr = (CombinedTraceVarInfo *)
- ckalloc((unsigned) (sizeof(CombinedTraceVarInfo)
- + length + 1 - sizeof(ctvarPtr->traceCmdInfo.command)));
+ ckalloc((unsigned) ((TclOffset(CombinedTraceVarInfo,
+ traceCmdInfo.command) + 1) + length));
ctvarPtr->traceCmdInfo.flags = flags;
if (objv[0] == NULL) {