From 3aef0c58f9614b4dd1b9eb4201238789cd9022fa Mon Sep 17 00:00:00 2001 From: pooryorick Date: Tue, 14 Mar 2023 20:27:04 +0000 Subject: Further fix for issue [ea69b0258a9833cb], crash when using a channel transformation on TCP client socket. --- generic/tclIO.c | 30 +++++++++++++++++++++++------- generic/tclIO.h | 3 +++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 715f8c7..55b6bdc 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -1699,6 +1699,7 @@ Tcl_CreateChannel( statePtr->scriptRecordPtr = NULL; statePtr->bufSize = CHANNELBUFFER_DEFAULT_SIZE; statePtr->timer = NULL; + statePtr->timerChanPtr = NULL; statePtr->csPtrR = NULL; statePtr->csPtrW = NULL; statePtr->outputStage = NULL; @@ -3093,7 +3094,13 @@ CloseChannel( * Cancel any outstanding timer. */ - Tcl_DeleteTimerHandler(statePtr->timer); + if (statePtr->timer != NULL) { + Tcl_DeleteTimerHandler(statePtr->timer); + statePtr->timer = NULL; + TclChannelRelease((Tcl_Channel)statePtr->timerChanPtr); + statePtr->timerChanPtr = NULL; + } + /* * Mark the channel as deleted by clearing the type structure. @@ -3912,7 +3919,12 @@ Tcl_ClearChannelHandlers( * Cancel any outstanding timer. */ - Tcl_DeleteTimerHandler(statePtr->timer); + if (statePtr->timer != NULL) { + Tcl_DeleteTimerHandler(statePtr->timer); + statePtr->timer = NULL; + TclChannelRelease((Tcl_Channel)statePtr->timerChanPtr); + statePtr->timerChanPtr = NULL; + } /* * Remove any references to channel handlers for this channel that may be @@ -8552,8 +8564,9 @@ UpdateInterest( if (!statePtr->timer) { TclChannelPreserve((Tcl_Channel)chanPtr); + statePtr->timerChanPtr = chanPtr; statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, - ChannelTimerProc, chanPtr); + ChannelTimerProc, chanPtr); } } } @@ -8582,11 +8595,13 @@ ChannelTimerProc( ClientData clientData) { Channel *chanPtr = (Channel *)clientData; + /* State info for channel */ ChannelState *statePtr = chanPtr->state; - /* State info for channel */ if (chanPtr->typePtr == NULL) { - TclChannelRelease((Tcl_Channel)chanPtr); + statePtr->timer = NULL; + TclChannelRelease((Tcl_Channel)statePtr->timerChanPtr); + statePtr->timerChanPtr = NULL; } else { if (!GotFlag(statePtr, CHANNEL_NEED_MORE_DATA) && (statePtr->interestMask & TCL_READABLE) @@ -8598,14 +8613,15 @@ ChannelTimerProc( */ statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, - ChannelTimerProc,chanPtr); + ChannelTimerProc,chanPtr); Tcl_Preserve(statePtr); Tcl_NotifyChannel((Tcl_Channel) chanPtr, TCL_READABLE); Tcl_Release(statePtr); } else { statePtr->timer = NULL; UpdateInterest(chanPtr); - TclChannelRelease((Tcl_Channel)chanPtr); + TclChannelRelease((Tcl_Channel)statePtr->timerChanPtr); + statePtr->timerChanPtr = NULL; } } } diff --git a/generic/tclIO.h b/generic/tclIO.h index eccc7a9..03bbce8 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -188,6 +188,9 @@ typedef struct ChannelState { * handlers ("fileevent") on this channel. */ int bufSize; /* What size buffers to allocate? */ Tcl_TimerToken timer; /* Handle to wakeup timer for this channel. */ + Channel *timerChanPtr; /* Needed in order to decrement the refCount of + the right channel when the timer is + deleted. */ struct CopyState *csPtrR; /* State of background copy for which channel * is input, or NULL. */ struct CopyState *csPtrW; /* State of background copy for which channel -- cgit v0.12 From 6ded4b92be27dd73c424f6d524d1a0578621c126 Mon Sep 17 00:00:00 2001 From: pooryorick Date: Wed, 15 Mar 2023 08:42:11 +0000 Subject: Further fix for issue [ea69b0258a9833cb], crash when using a channel transformation on TCP client socket. --- generic/tclIO.c | 52 ++++++++++++++++++++++++++++++++++++---------------- generic/tclIO.h | 3 +++ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 58137a5..08c52a7 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -165,6 +165,7 @@ static int CheckForDeadChannel(Tcl_Interp *interp, static void CheckForStdChannelsBeingClosed(Tcl_Channel chan); static void CleanupChannelHandlers(Tcl_Interp *interp, Channel *chanPtr); +static void CleanupTimerHandler(ChannelState *statePtr); static int CloseChannel(Tcl_Interp *interp, Channel *chanPtr, int errorCode); static int CloseChannelPart(Tcl_Interp *interp, Channel *chanPtr, @@ -172,6 +173,7 @@ static int CloseChannelPart(Tcl_Interp *interp, Channel *chanPtr, static int CloseWrite(Tcl_Interp *interp, Channel *chanPtr); static void CommonGetsCleanup(Channel *chanPtr); static int CopyData(CopyState *csPtr, int mask); +static void DeleteTimerHandler(ChannelState *statePtr); static int MoveBytes(CopyState *csPtr); static void MBCallback(CopyState *csPtr, Tcl_Obj *errObj); @@ -1730,6 +1732,7 @@ Tcl_CreateChannel( statePtr->scriptRecordPtr = NULL; statePtr->bufSize = CHANNELBUFFER_DEFAULT_SIZE; statePtr->timer = NULL; + statePtr->timerChanPtr = NULL; statePtr->csPtrR = NULL; statePtr->csPtrW = NULL; statePtr->outputStage = NULL; @@ -3187,8 +3190,8 @@ CloseChannel( /* * Cancel any outstanding timer. */ + DeleteTimerHandler(statePtr); - Tcl_DeleteTimerHandler(statePtr->timer); /* * Mark the channel as deleted by clearing the type structure. @@ -3540,7 +3543,7 @@ Tcl_Close( /* * Cancel any outstanding timer. */ - Tcl_DeleteTimerHandler(statePtr->timer); + DeleteTimerHandler(statePtr); /* * Invoke the registered close callbacks and delete their records. @@ -4015,8 +4018,7 @@ Tcl_ClearChannelHandlers( /* * Cancel any outstanding timer. */ - - Tcl_DeleteTimerHandler(statePtr->timer); + DeleteTimerHandler(statePtr); /* * Remove any references to channel handlers for this channel that may be @@ -8805,8 +8807,9 @@ UpdateInterest( if (!statePtr->timer) { TclChannelPreserve((Tcl_Channel)chanPtr); + statePtr->timerChanPtr = chanPtr; statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, - ChannelTimerProc, chanPtr); + ChannelTimerProc, chanPtr); } } } @@ -8816,6 +8819,7 @@ UpdateInterest( && GotFlag(statePtr, CHANNEL_NONBLOCKING)) { TclChannelPreserve((Tcl_Channel)chanPtr); + statePtr->timerChanPtr = chanPtr; statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, ChannelTimerProc,chanPtr); } @@ -8846,7 +8850,6 @@ ChannelTimerProc( void *clientData) { Channel *chanPtr = (Channel *)clientData; - /* State info for channel */ ChannelState *statePtr = chanPtr->state; @@ -8857,7 +8860,7 @@ ChannelTimerProc( */ if (chanPtr->typePtr == NULL) { - TclChannelRelease((Tcl_Channel)chanPtr); + CleanupTimerHandler(statePtr); } else { Tcl_Preserve(statePtr); statePtr->timer = NULL; @@ -8870,35 +8873,52 @@ ChannelTimerProc( * before UpdateInterest gets called by Tcl_NotifyChannel. */ statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, - ChannelTimerProc,chanPtr); + ChannelTimerProc,chanPtr); Tcl_NotifyChannel((Tcl_Channel) chanPtr, TCL_WRITABLE); } else { /* The channel may have just been closed from within Tcl_NotifyChannel */ if (!GotFlag(statePtr, CHANNEL_INCLOSE)) { if (!GotFlag(statePtr, CHANNEL_NEED_MORE_DATA) - && (statePtr->interestMask & TCL_READABLE) - && (statePtr->inQueueHead != NULL) - && IsBufferReady(statePtr->inQueueHead)) { + && (statePtr->interestMask & TCL_READABLE) + && (statePtr->inQueueHead != NULL) + && IsBufferReady(statePtr->inQueueHead)) { /* * Restart the timer in case a channel handler reenters the event loop * before UpdateInterest gets called by Tcl_NotifyChannel. */ statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, - ChannelTimerProc,chanPtr); + ChannelTimerProc,chanPtr); Tcl_NotifyChannel((Tcl_Channel) chanPtr, TCL_READABLE); } else { - TclChannelRelease((Tcl_Channel)chanPtr); + CleanupTimerHandler(statePtr); UpdateInterest(chanPtr); } } else { - TclChannelRelease((Tcl_Channel)chanPtr); + CleanupTimerHandler(statePtr); } } - Tcl_Release(statePtr); } - +} + +static void +DeleteTimerHandler( + ChannelState *statePtr +) +{ + if (statePtr->timer != NULL) { + Tcl_DeleteTimerHandler(statePtr->timer); + CleanupTimerHandler(statePtr); + } +} +static void +CleanupTimerHandler( + ChannelState *statePtr +){ + TclChannelRelease((Tcl_Channel)statePtr->timerChanPtr); + statePtr->timer = NULL; + statePtr->timerChanPtr = NULL; } /* diff --git a/generic/tclIO.h b/generic/tclIO.h index 689067f..bfaf416 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -188,6 +188,9 @@ typedef struct ChannelState { * handlers ("fileevent") on this channel. */ Tcl_Size bufSize; /* What size buffers to allocate? */ Tcl_TimerToken timer; /* Handle to wakeup timer for this channel. */ + Channel *timerChanPtr; /* Needed in order to decrement the refCount of + the right channel when the timer is + deleted. */ struct CopyState *csPtrR; /* State of background copy for which channel * is input, or NULL. */ struct CopyState *csPtrW; /* State of background copy for which channel -- cgit v0.12 From ea9a0277a2229f37c66c9a1e6ed1fb3e3e0a2f11 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 15 Mar 2023 09:11:22 +0000 Subject: ckfree -> Tcl_Free --- generic/tclTest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index fcb9ff4..f7854ac 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -2205,7 +2205,7 @@ static int UtfExtWrapper( Tcl_SetObjResult(interp, Tcl_NewListObj(3, resultObjs)); } - ckfree(bufPtr); + Tcl_Free(bufPtr); Tcl_FreeEncoding(encoding); /* Free returned reference */ return result; } -- cgit v0.12 From 6bd8763c2db23d253082f9e4d79e53e60a77e856 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 15 Mar 2023 12:53:03 +0000 Subject: Misspelled constraint created testing noise. --- tests/encoding.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/encoding.test b/tests/encoding.test index bac80c9..dc50f24 100644 --- a/tests/encoding.test +++ b/tests/encoding.test @@ -768,7 +768,7 @@ test encoding-bug-183a1adcc0-4 {Bug [183a1adcc0] Buffer overflow Tcl_UtfToExtern } -result [list 0 [list nospace {} \x00\x00\xff]] test encoding-bug-183a1adcc0-5 {Bug [183a1adcc0] Buffer overflow Tcl_UtfToExternal} -constraints { - testencoding ucs-2 + testencoding ucs2 } -body { # Note - buffers are initialized to \xff list [catch {testencoding Tcl_UtfToExternal unicode A {start end} {} 4} result] $result -- cgit v0.12 From e0e09638fece9ca63daad3b3675dc7bfb1ede7d3 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 15 Mar 2023 16:21:53 +0000 Subject: Remove _LARGEFILE_SOURCE64 usage. See [d690400d07] --- unix/configure | 105 ---------------------------------------------------- unix/tcl.m4 | 3 -- unix/tclConfig.h.in | 3 -- 3 files changed, 111 deletions(-) diff --git a/unix/configure b/unix/configure index 94ecfc6..2ebb2ea 100755 --- a/unix/configure +++ b/unix/configure @@ -9318,111 +9318,6 @@ _ACEOF tcl_flags="$tcl_flags _LARGEFILE64_SOURCE" fi - - if test "${tcl_cv_flag__largefile_source64+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -char *p = (char *)open64; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - tcl_cv_flag__largefile_source64=no -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#define _LARGEFILE_SOURCE64 1 -#include -int -main () -{ -char *p = (char *)open64; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - tcl_cv_flag__largefile_source64=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -tcl_cv_flag__largefile_source64=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi - - if test "x${tcl_cv_flag__largefile_source64}" = "xyes" ; then - -cat >>confdefs.h <<\_ACEOF -#define _LARGEFILE_SOURCE64 1 -_ACEOF - - tcl_flags="$tcl_flags _LARGEFILE_SOURCE64" - fi - if test "x${tcl_flags}" = "x" ; then echo "$as_me:$LINENO: result: none" >&5 echo "${ECHO_T}none" >&6 diff --git a/unix/tcl.m4 b/unix/tcl.m4 index 6cee92c..d9d0a71 100644 --- a/unix/tcl.m4 +++ b/unix/tcl.m4 @@ -2472,7 +2472,6 @@ AC_DEFUN([SC_TCL_LINK_LIBS], [ # Might define the following vars: # _ISOC99_SOURCE # _LARGEFILE64_SOURCE -# _LARGEFILE_SOURCE64 # #-------------------------------------------------------------------- @@ -2496,8 +2495,6 @@ AC_DEFUN([SC_TCL_EARLY_FLAGS],[ [char *p = (char *)strtoll; char *q = (char *)strtoull;]) SC_TCL_EARLY_FLAG(_LARGEFILE64_SOURCE,[#include ], [struct stat64 buf; int i = stat64("/", &buf);]) - SC_TCL_EARLY_FLAG(_LARGEFILE_SOURCE64,[#include ], - [char *p = (char *)open64;]) if test "x${tcl_flags}" = "x" ; then AC_MSG_RESULT([none]) else diff --git a/unix/tclConfig.h.in b/unix/tclConfig.h.in index 0b7ed35..6d559d1 100644 --- a/unix/tclConfig.h.in +++ b/unix/tclConfig.h.in @@ -463,9 +463,6 @@ /* Add the _LARGEFILE64_SOURCE flag when building */ #undef _LARGEFILE64_SOURCE -/* Add the _LARGEFILE_SOURCE64 flag when building */ -#undef _LARGEFILE_SOURCE64 - /* # needed in sys/socket.h Should OS/390 do the right thing with sockets? */ #undef _OE_SOCKETS -- cgit v0.12 From 70cf69246f83c91f78fd4de65ac48fa39aa634d4 Mon Sep 17 00:00:00 2001 From: pooryorick Date: Wed, 15 Mar 2023 20:13:22 +0000 Subject: New script used in the "valgrind_each" target in Makefile.in --- tools/valgrind_check_success | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tools/valgrind_check_success diff --git a/tools/valgrind_check_success b/tools/valgrind_check_success new file mode 100644 index 0000000..24830d5 --- /dev/null +++ b/tools/valgrind_check_success @@ -0,0 +1,30 @@ +#! /usr/bin/env tclsh + + +proc main {sourcetype source} { + switch $sourcetype { + file { + set chan [open $source] + try { + set data [read $chan] + } finally { + close $chan + } + } + string { + set data $source + } + default { + error [list {wrong # args}] + } + } + set found [regexp -inline -all {blocks are\ + (?:(?:(?:definitely|indirectly|possibly) lost)|still reachable)} $data] + if {[llength $found]} { + puts 0 + } else { + puts 1 + } + flush stdout +} +main {*}$argv -- cgit v0.12 From 5846b1666f9fda4d12d9cc46f8bd2050b1ed4ef4 Mon Sep 17 00:00:00 2001 From: pooryorick Date: Thu, 16 Mar 2023 08:15:03 +0000 Subject: Make valgrind_foreach target in Makefile.in properly handle interrupted tests. --- unix/Makefile.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unix/Makefile.in b/unix/Makefile.in index da057d8..e092a2d 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -956,7 +956,8 @@ testresults/valgrind/%.result: ${TCL_EXE} ${TCLTEST_EXE} @mkdir -p testresults/valgrind $(SHELL_ENV) $(VALGRIND) $(VALGRINDARGS) ./${TCLTEST_EXE} \ $(TOP_DIR)/tests/all.tcl -singleproc 1 -constraints valgrind \ - -file $(basename $(notdir $@)) > $@ 2>&1 + -file $(basename $(notdir $@)) > $@.tmp 2>&1 + @mv $@.tmp $@ .PRECIOUS: testresults/valgrind/%.result @@ -966,7 +967,7 @@ testresults/valgrind/%.success: testresults/valgrind/%.result @printf '\n >&2' @status=$$(./${TCLTEST_EXE} $(TOP_DIR)/tools/valgrind_check_success \ file $(basename $@).result); \ - if [ "$$status" -eq 1 ]; then exit 0; else exit 1; fi + if [ "$$status" -eq 1 ]; then touch $@; exit 0; else exit 1; fi valgrind_each: $(addprefix testresults/valgrind/,$(addsuffix .success,$(notdir\ $(wildcard $(TOP_DIR)/tests/*.test)))) -- cgit v0.12 From e019e5bd1d3ddb51539ca9e4872e6c9d310dd390 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 16 Mar 2023 11:29:14 +0000 Subject: Fix (minor) warning on 32-bit platforms --- generic/tclTest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 668a05a..15eaa56 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -2119,7 +2119,7 @@ static int UtfExtWrapper( /* Assumes state is integer if not "" */ Tcl_WideInt wide; if (Tcl_GetWideIntFromObj(interp, objv[5], &wide) == TCL_OK) { - encState = (Tcl_EncodingState) wide; + encState = (Tcl_EncodingState)(size_t)wide; encStatePtr = &encState; } else if (Tcl_GetCharLength(objv[5]) == 0) { encStatePtr = NULL; @@ -2209,7 +2209,7 @@ static int UtfExtWrapper( } result = TCL_OK; resultObjs[1] = - encStatePtr ? Tcl_NewWideIntObj((Tcl_WideInt)encState) : Tcl_NewObj(); + encStatePtr ? Tcl_NewWideIntObj((Tcl_WideInt)(size_t)encState) : Tcl_NewObj(); resultObjs[2] = Tcl_NewByteArrayObj(bufPtr, dstLen); if (srcReadVar) { if (Tcl_ObjSetVar2(interp, -- cgit v0.12 From 1eefaec4712a22b1cea12961deb534381158010e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 16 Mar 2023 11:38:20 +0000 Subject: Minor cleanup (Thanks, Gustaf!) --- generic/tclLiteral.c | 4 ++-- generic/tclProc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c index 24e99fc..c3f0f7d 100644 --- a/generic/tclLiteral.c +++ b/generic/tclLiteral.c @@ -179,8 +179,8 @@ TclCreateLiteral( const char *bytes, /* The start of the string. Note that this is * not a NUL-terminated string. */ size_t length, /* Number of bytes in the string. */ - size_t hash, /* The string's hash. If -1, it will be - * computed here. */ + size_t hash, /* The string's hash. If the value is + * TCL_INDEX_NONE, it will be computed here. */ int *newPtr, Namespace *nsPtr, int flags, diff --git a/generic/tclProc.c b/generic/tclProc.c index c8a304a..a472a2d 100644 --- a/generic/tclProc.c +++ b/generic/tclProc.c @@ -1298,7 +1298,7 @@ InitLocalCache( *namePtr = NULL; } else { *namePtr = TclCreateLiteral(iPtr, localPtr->name, - localPtr->nameLength, /* hash */ (size_t) -1, + localPtr->nameLength, /* hash */ TCL_INDEX_NONE, &isNew, /* nsPtr */ NULL, 0, NULL); Tcl_IncrRefCount(*namePtr); } -- cgit v0.12 From 1a6f1d5c40570e83189a91e4301d9e89369ce00e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 16 Mar 2023 15:12:17 +0000 Subject: Add some undocumented stub functions. Those can prevent a crash like [http://paste.tclers.tk/5763|this] example, when compiled with 8.7 headers but running it in Tcl 8.6. --- generic/tcl.decls | 16 +++++++++++++-- generic/tclDecls.h | 30 +++++++++++++++++++--------- generic/tclPlatDecls.h | 19 ++++++++++-------- generic/tclStubInit.c | 54 +++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 95 insertions(+), 24 deletions(-) diff --git a/generic/tcl.decls b/generic/tcl.decls index d20a945..7f734c6 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -2326,6 +2326,18 @@ declare 630 { # ----- BASELINE -- FOR -- 8.6.0 ----- # +# TIP #481 (undocumented stub entries) +declare 651 { + char *TclGetStringFromObj_(Tcl_Obj *objPtr, size_t *lengthPtr) +} +declare 652 { + unsigned short *TclGetUnicodeFromObj_(Tcl_Obj *objPtr, size_t *lengthPtr) +} +# Only available in Tcl 8.x, NULL in Tcl 9.0 +declare 653 { + unsigned char *TclGetByteArrayFromObj_(Tcl_Obj *objPtr, size_t *numBytesPtr) +} + declare 687 { void TclUnusedStubEntry(void) } @@ -2355,7 +2367,7 @@ declare 1 win { char *Tcl_WinTCharToUtf(const TCHAR *str, int len, Tcl_DString *dsPtr) } declare 3 win { - void TclUnusedStubEntry(void) + void TclWinConvertError_(unsigned errCode) } ################################ @@ -2372,7 +2384,7 @@ declare 1 macosx { int hasResourceFile, int maxPathLen, char *libraryPath) } declare 2 macosx { - void TclUnusedStubEntry(void) + void TclMacOSXNotifierAddRunLoopMode_(const void *runLoopMode) } ############################################################################## diff --git a/generic/tclDecls.h b/generic/tclDecls.h index 6c109de..551a5b6 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -1835,9 +1835,15 @@ EXTERN void Tcl_ZlibStreamSetCompressionDictionary( /* Slot 648 is reserved */ /* Slot 649 is reserved */ /* Slot 650 is reserved */ -/* Slot 651 is reserved */ -/* Slot 652 is reserved */ -/* Slot 653 is reserved */ +/* 651 */ +EXTERN char * TclGetStringFromObj_(Tcl_Obj *objPtr, + size_t *lengthPtr); +/* 652 */ +EXTERN unsigned short * TclGetUnicodeFromObj_(Tcl_Obj *objPtr, + size_t *lengthPtr); +/* 653 */ +EXTERN unsigned char * TclGetByteArrayFromObj_(Tcl_Obj *objPtr, + size_t *numBytesPtr); /* Slot 654 is reserved */ /* Slot 655 is reserved */ /* Slot 656 is reserved */ @@ -2559,9 +2565,9 @@ typedef struct TclStubs { void (*reserved648)(void); void (*reserved649)(void); void (*reserved650)(void); - void (*reserved651)(void); - void (*reserved652)(void); - void (*reserved653)(void); + char * (*tclGetStringFromObj_) (Tcl_Obj *objPtr, size_t *lengthPtr); /* 651 */ + unsigned short * (*tclGetUnicodeFromObj_) (Tcl_Obj *objPtr, size_t *lengthPtr); /* 652 */ + unsigned char * (*tclGetByteArrayFromObj_) (Tcl_Obj *objPtr, size_t *numBytesPtr); /* 653 */ void (*reserved654)(void); void (*reserved655)(void); void (*reserved656)(void); @@ -3908,9 +3914,12 @@ extern const TclStubs *tclStubsPtr; /* Slot 648 is reserved */ /* Slot 649 is reserved */ /* Slot 650 is reserved */ -/* Slot 651 is reserved */ -/* Slot 652 is reserved */ -/* Slot 653 is reserved */ +#define TclGetStringFromObj_ \ + (tclStubsPtr->tclGetStringFromObj_) /* 651 */ +#define TclGetUnicodeFromObj_ \ + (tclStubsPtr->tclGetUnicodeFromObj_) /* 652 */ +#define TclGetByteArrayFromObj_ \ + (tclStubsPtr->tclGetByteArrayFromObj_) /* 653 */ /* Slot 654 is reserved */ /* Slot 655 is reserved */ /* Slot 656 is reserved */ @@ -3984,6 +3993,9 @@ extern const TclStubs *tclStubsPtr; #undef Tcl_SeekOld #undef Tcl_TellOld +#undef TclGetStringFromObj_ +#undef TclGetUnicodeFromObj_ +#undef TclGetByteArrayFromObj_ #undef Tcl_PkgPresent #define Tcl_PkgPresent(interp, name, version, exact) \ diff --git a/generic/tclPlatDecls.h b/generic/tclPlatDecls.h index cb420fd..46181a1 100644 --- a/generic/tclPlatDecls.h +++ b/generic/tclPlatDecls.h @@ -59,7 +59,7 @@ EXTERN char * Tcl_WinTCharToUtf(const TCHAR *str, int len, Tcl_DString *dsPtr); /* Slot 2 is reserved */ /* 3 */ -EXTERN void TclUnusedStubEntry(void); +EXTERN void TclWinConvertError_(unsigned errCode); #endif /* WIN */ #ifdef MAC_OSX_TCL /* MACOSX */ /* 0 */ @@ -73,7 +73,8 @@ EXTERN int Tcl_MacOSXOpenVersionedBundleResources( int hasResourceFile, int maxPathLen, char *libraryPath); /* 2 */ -EXTERN void TclUnusedStubEntry(void); +EXTERN void TclMacOSXNotifierAddRunLoopMode_( + const void *runLoopMode); #endif /* MACOSX */ typedef struct TclPlatStubs { @@ -84,12 +85,12 @@ typedef struct TclPlatStubs { TCHAR * (*tcl_WinUtfToTChar) (const char *str, int len, Tcl_DString *dsPtr); /* 0 */ char * (*tcl_WinTCharToUtf) (const TCHAR *str, int len, Tcl_DString *dsPtr); /* 1 */ void (*reserved2)(void); - void (*tclUnusedStubEntry) (void); /* 3 */ + void (*tclWinConvertError_) (unsigned errCode); /* 3 */ #endif /* WIN */ #ifdef MAC_OSX_TCL /* MACOSX */ int (*tcl_MacOSXOpenBundleResources) (Tcl_Interp *interp, const char *bundleName, int hasResourceFile, int maxPathLen, char *libraryPath); /* 0 */ int (*tcl_MacOSXOpenVersionedBundleResources) (Tcl_Interp *interp, const char *bundleName, const char *bundleVersion, int hasResourceFile, int maxPathLen, char *libraryPath); /* 1 */ - void (*tclUnusedStubEntry) (void); /* 2 */ + void (*tclMacOSXNotifierAddRunLoopMode_) (const void *runLoopMode); /* 2 */ #endif /* MACOSX */ } TclPlatStubs; @@ -111,16 +112,16 @@ extern const TclPlatStubs *tclPlatStubsPtr; #define Tcl_WinTCharToUtf \ (tclPlatStubsPtr->tcl_WinTCharToUtf) /* 1 */ /* Slot 2 is reserved */ -#define TclUnusedStubEntry \ - (tclPlatStubsPtr->tclUnusedStubEntry) /* 3 */ +#define TclWinConvertError_ \ + (tclPlatStubsPtr->tclWinConvertError_) /* 3 */ #endif /* WIN */ #ifdef MAC_OSX_TCL /* MACOSX */ #define Tcl_MacOSXOpenBundleResources \ (tclPlatStubsPtr->tcl_MacOSXOpenBundleResources) /* 0 */ #define Tcl_MacOSXOpenVersionedBundleResources \ (tclPlatStubsPtr->tcl_MacOSXOpenVersionedBundleResources) /* 1 */ -#define TclUnusedStubEntry \ - (tclPlatStubsPtr->tclUnusedStubEntry) /* 2 */ +#define TclMacOSXNotifierAddRunLoopMode_ \ + (tclPlatStubsPtr->tclMacOSXNotifierAddRunLoopMode_) /* 2 */ #endif /* MACOSX */ #endif /* defined(USE_TCL_STUBS) */ @@ -128,6 +129,8 @@ extern const TclPlatStubs *tclPlatStubsPtr; /* !END!: Do not edit above this line. */ #undef TclUnusedStubEntry +#undef TclMacOSXNotifierAddRunLoopMode_ +#undef TclWinConvertError_ #ifdef MAC_OSX_TCL /* MACOSX */ #undef Tcl_MacOSXOpenBundleResources #define Tcl_MacOSXOpenBundleResources(a,b,c,d,e) Tcl_MacOSXOpenVersionedBundleResources(a,b,NULL,c,d,e) diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index ee0412a..565dd8c 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -59,6 +59,7 @@ #define TclBN_mp_tc_or TclBN_mp_or #define TclBN_mp_tc_xor TclBN_mp_xor #define TclStaticPackage Tcl_StaticPackage +#define TclMacOSXNotifierAddRunLoopMode_ TclMacOSXNotifierAddRunLoopMode #define TclUnusedStubEntry 0 /* See bug 510001: TclSockMinimumBuffers needs plat imp */ @@ -138,12 +139,55 @@ static const char *TclGetStartupScriptFileName(void) return Tcl_GetString(path); } +#define TclGetStringFromObj_ getStringFromObj +static char * +TclGetStringFromObj_( + Tcl_Obj *objPtr, + size_t *lengthPtr) +{ + int length; + char *result = Tcl_GetStringFromObj(objPtr, &length); + *lengthPtr = (size_t)length; + return result; +} + +#define TclGetUnicodeFromObj_ getUnicodeFromObj +static unsigned short * +TclGetUnicodeFromObj_( + Tcl_Obj *objPtr, + size_t *lengthPtr) +{ + int length; + Tcl_UniChar *result = Tcl_GetUnicodeFromObj(objPtr, &length); + *lengthPtr = (size_t)length; + return result; +} + +#define TclGetByteArrayFromObj_ getByteArrayFromObj +static unsigned char * +TclGetByteArrayFromObj_( + Tcl_Obj *objPtr, + size_t *numBytesPtr) +{ + int numBytes; + unsigned char *result = Tcl_GetByteArrayFromObj(objPtr, &numBytes); + *numBytesPtr = (size_t)numBytes; + return result; +} + + #if defined(_WIN32) || defined(__CYGWIN__) #undef TclWinNToHS #define TclWinNToHS winNToHS static unsigned short TclWinNToHS(unsigned short ns) { return ntohs(ns); } +#define TclWinConvertError_ winConvertError +static void +TclWinConvertError_(unsigned errCode) { + return TclWinConvertError(errCode); +} + #endif #define TclpCreateTempFile_ TclpCreateTempFile @@ -865,12 +909,12 @@ static const TclPlatStubs tclPlatStubs = { Tcl_WinUtfToTChar, /* 0 */ Tcl_WinTCharToUtf, /* 1 */ 0, /* 2 */ - TclUnusedStubEntry, /* 3 */ + TclWinConvertError_, /* 3 */ #endif /* WIN */ #ifdef MAC_OSX_TCL /* MACOSX */ Tcl_MacOSXOpenBundleResources, /* 0 */ Tcl_MacOSXOpenVersionedBundleResources, /* 1 */ - TclUnusedStubEntry, /* 2 */ + TclMacOSXNotifierAddRunLoopMode_, /* 2 */ #endif /* MACOSX */ }; @@ -1644,9 +1688,9 @@ const TclStubs tclStubs = { 0, /* 648 */ 0, /* 649 */ 0, /* 650 */ - 0, /* 651 */ - 0, /* 652 */ - 0, /* 653 */ + TclGetStringFromObj_, /* 651 */ + TclGetUnicodeFromObj_, /* 652 */ + TclGetByteArrayFromObj_, /* 653 */ 0, /* 654 */ 0, /* 655 */ 0, /* 656 */ -- cgit v0.12 From 527e79c3a8b0d8df5cce3676a94700785584ef06 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Thu, 16 Mar 2023 17:54:12 +0000 Subject: Fix passing of encoding state in testencoding Tcl_UtfToExternal --- generic/tclTest.c | 26 ++++++++++++++------------ tests/utfext.test | 5 +++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index eb19d18..459461f 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -2020,8 +2020,7 @@ static int UtfExtWrapper( Tcl_Interp *interp, UtfTransformFn *transformer, int objc, Tcl_Obj *const objv[]) { Tcl_Encoding encoding; - int encStateValue; /* Assumes Tcl_EncodingState points to integer!!! */ - Tcl_EncodingState encState; + Tcl_EncodingState encState, *encStatePtr; Tcl_Size srcLen, bufLen; const unsigned char *bytes; unsigned char *bufPtr; @@ -2085,13 +2084,16 @@ static int UtfExtWrapper( } /* Assumes state is integer if not "" */ - if (Tcl_GetIntFromObj(interp, objv[5], &encStateValue) == TCL_OK) { - encState = (Tcl_EncodingState)&encStateValue; + Tcl_WideInt wide; + if (Tcl_GetWideIntFromObj(interp, objv[5], &wide) == TCL_OK) { + encState = (Tcl_EncodingState) wide; + encStatePtr = &encState; } else if (Tcl_GetCharLength(objv[5]) == 0) { - encState = NULL; + encStatePtr = NULL; } else { return TCL_ERROR; } + if (Tcl_GetIntFromObj(interp, objv[6], &dstLen) != TCL_OK) { return TCL_ERROR; } @@ -2126,7 +2128,7 @@ static int UtfExtWrapper( "TCL_ENCODING_CHAR_LIMIT set in flags.", TCL_STATIC); return TCL_ERROR; } - if (Tcl_GetIntFromObj(interp, dstCharsVar, &dstChars) != TCL_OK) { + if (Tcl_GetIntFromObj(interp, valueObj, &dstChars) != TCL_OK) { return TCL_ERROR; } } else { @@ -2138,11 +2140,11 @@ static int UtfExtWrapper( memset(bufPtr, 0xFF, dstLen); /* Need to check nul terminator */ memmove(bufPtr + dstLen, "\xAB\xCD\xEF\xAB", 4); /* overflow detection */ bytes = Tcl_GetByteArrayFromObj(objv[3], &srcLen); /* Last! to avoid shimmering */ - result = (*transformer)(interp, encoding, (const char *) bytes, srcLen, flags, - &encState, (char *) bufPtr, dstLen, - srcReadVar ? &srcRead : NULL, - &dstWrote, - dstCharsVar ? &dstChars : NULL); + result = (*transformer)(interp, encoding, (const char *)bytes, srcLen, flags, + encStatePtr, (char *) bufPtr, dstLen, + srcReadVar ? &srcRead : NULL, + &dstWrote, + dstCharsVar ? &dstChars : NULL); if (memcmp(bufPtr + bufLen - 4, "\xAB\xCD\xEF\xAB", 4)) { Tcl_SetResult(interp, "Tcl_ExternalToUtf wrote past output buffer", @@ -2172,7 +2174,7 @@ static int UtfExtWrapper( } result = TCL_OK; resultObjs[1] = - encState ? Tcl_NewIntObj(encStateValue) : Tcl_NewObj(); + encStatePtr ? Tcl_NewWideIntObj((Tcl_WideInt)encState) : Tcl_NewObj(); resultObjs[2] = Tcl_NewByteArrayObj(bufPtr, dstLen); if (srcReadVar) { if (Tcl_ObjSetVar2(interp, diff --git a/tests/utfext.test b/tests/utfext.test index 175e3fa..b980800 100644 --- a/tests/utfext.test +++ b/tests/utfext.test @@ -88,6 +88,11 @@ test xx-bufferoverflow {buffer overflow Tcl_ExternalToUtf} -body { testencoding Tcl_UtfToExternal utf-16 A {start end} {} 1 } -result [list nospace {} \xFF] +# Another bug - char limit not obeyed +# % set cv 2 +# % testencoding Tcl_ExternalToUtf utf-8 abcdefgh {start end noterminate charlimit} {} 20 rv wv cv +# nospace {} abcÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ + ::tcltest::cleanupTests return -- cgit v0.12 From aa14feed8b03a78ef20b0989d17b44b7e734243e Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Thu, 16 Mar 2023 18:15:46 +0000 Subject: Missed two tests. Blast it :-( --- tests/encoding.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/encoding.test b/tests/encoding.test index 1be6fed..35340a6 100644 --- a/tests/encoding.test +++ b/tests/encoding.test @@ -872,10 +872,10 @@ test encoding-24.37 {Parse invalid utf-8 with -profile tcl8} -body { } -result \uD800 test encoding-24.38.1 {Try to generate invalid utf-8} -body { encoding convertto -profile tcl8 utf-8 \uD800 -} -returnCodes 1 -result {unexpected character at index 0: 'U+00D800'} +} -result \xED\xA0\x80 test encoding-24.38.2 {Try to generate invalid utf-8} -body { encoding convertto -profile strict utf-8 \uD800 -} -result \xED\xA0\x80 +} -returnCodes 1 -result {unexpected character at index 0: 'U+00D800'} test encoding-24.39 {Try to generate invalid utf-8 with -profile strict} -body { encoding convertto -profile strict utf-8 \uD800 } -returnCodes 1 -result {unexpected character at index 0: 'U+00D800'} -- cgit v0.12