Tcl_ReadChars is unsafe for stacked channels
Closed / Fixed218905ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:07:37
OriginalBugID: 2623 Bug
Version: 8.2
SubmitDate: '1999-08-31'
LastModified: '1999-11-18'
Severity: CRIT
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Windows NT
Machine: X86
FixedDate: '1999-11-18'
FixedInVersion: 8.2.1
ClosedDate: '2000-10-25'
Name:
Matt Newman
CustomShell:
The above patch, plus the tclPosixStr.c patch plus a patch to fix the -translation and -eofchar bugs in GetOption code (to be submitted sortly)
Comments:
A low risk patch that urgently needs to be applied.
ObservedBehavior:
Tcl_ReadChars does not allocate a Tcl_Obj for its data, but instead uses
the existing Tcl Result OBJ. This is normally relatively safe, but bad
practice.
How ever with stacked channels the underlying channel may issue
Tcl_Eval's during the read processing, which causes a complex corruption
of the Tcl_Obj that Tcl_ReadChars is using - and because of the way it
works this almost *ALWAYS* will cause a core dump.
This behaviour was first observed whilst testing the
shortly-to-be-released TLS (aka SSL) extension - but the exposure exists
for *ALL* stacked channels that may perform Tcl_Evals.
DesiredBehavior:
No bugs - no crashs.
Patch:
Index: tclIOCmd.c
===================================================================
RCS file: /cvs/tcl/tcl8.2/generic/tclIOCmd.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 tclIOCmd.c
*** tclIOCmd.c 1999/08/19 12:32:00 1.1.1.1
--- tclIOCmd.c 1999/08/23 16:59:41
***************
*** 350,361 ****
}
}
! resultPtr = Tcl_GetObjResult(interp);
charactersRead = Tcl_ReadChars(chan, resultPtr, toRead, 0);
if (charactersRead < 0) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "error reading \"", name, "\": ",
Tcl_PosixError(interp), (char *) NULL);
return TCL_ERROR;
}
--- 350,363 ----
}
}
! resultPtr = Tcl_NewObj();
! Tcl_IncrRefCount(resultPtr);
charactersRead = Tcl_ReadChars(chan, resultPtr, toRead, 0);
if (charactersRead < 0) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "error reading \"", name, "\": ",
Tcl_PosixError(interp), (char *) NULL);
+ Tcl_DecrRefCount(resultPtr);
return TCL_ERROR;
}
***************
*** 372,377 ****
--- 374,381 ----
Tcl_SetObjLength(resultPtr, length - 1);
}
}
+ Tcl_SetObjResult(interp, resultPtr);
+ Tcl_DecrRefCount(resultPtr);
return TCL_OK;
}
PatchFiles:
generic/tclIOCmd.c
in 8.2.1
-- 11/18/1999 hobbs
welch Closed ticket [218905ffff].
[History diff]2000-10-26 08:31:15
dgp Ticket [218905ffff]: 3 changes
[History diff]2001-04-03 06:31:21
Log in (anonymous is fine) to add a comment.