|
2022-01-14
| ||
| 22:53 | • Closed ticket [69218ab7bf]: TEBCResume(): buffer over-read in INST_STR_MAP p... artifact: 7faecf813a user: jan.nijtmans | |
|
2022-01-13
| ||
| 13:22 | Fix [69218ab7b]: TEBCResume(): buffer over-read in INST_STR_MAP check-in: 66f6ea11a3 user: jan.nijtmans tags: core-8-6-branch | |
|
2022-01-12
| ||
| 15:51 | • Pending ticket [69218ab7bf]: TEBCResume(): buffer over-read in INST_STR_MAP ... artifact: eb83537ba8 user: jan.nijtmans | |
| 15:50 | Fix [69218ab7b]: TEBCResume(): buffer over-read in INST_STR_MAP closed check-in: 0f45a92d03 user: jan.nijtmans tags: bug-69218ab7b | |
|
2021-12-22
| ||
| 18:45 | • New ticket [69218ab7bf] TEBCResume(): buffer over-read in INST_STR_MAP. artifact: 2cfe68c3e2 user: chrstphrchvz | |
TEBCResume(): buffer over-read in INST_STR_MAP
proc myproc {s} {
puts [string map {abc def} $s]
}
myproc {zzzzzza}
AddressSanitizer (-fsanitize=address, used with -DPURIFY, Linux x86) error:
================================================================= ==16557==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xb143d0e0 at pc 0xb7a8d726 bp 0xbfbf2438 sp 0xbfbf2008 READ of size 6 at 0xb143d0e0 thread T0 #0 0xb7a8d725 in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long) /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:860 #1 0xb7a8dd48 in __interceptor_memcmp /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:892 #2 0xb7a8dd48 in __interceptor_memcmp /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:887 #3 0xb63ddad3 in TEBCresume tcl/generic/tclExecute.c:5859 #4 0xb5d74c43 in TclNRRunCallbacks tcl/generic/tclBasic.c:4503 #5 0xb5d719e4 in Tcl_EvalObjv tcl/generic/tclBasic.c:4226 #6 0xb5d80013 in TclEvalEx tcl/generic/tclBasic.c:5372 #7 0xb653cafa in Tcl_FSEvalFileEx tcl/generic/tclIOUtil.c:1824 #8 0xb6577599 in Tcl_MainEx tcl/generic/tclMain.c:403 #9 0x447253 in main tcl/unix/tclAppInit.c:84 #10 0xb4f7998c in __libc_start_main (/usr/lib/libc.so.6+0x1e98c) #11 0x447114 in _start (tclsh8.6+0x1114) 0xb143d0e0 is located 0 bytes to the right of 32-byte region [0xb143d0c0,0xb143d0e0) allocated by thread T0 here: #0 0xb7aaf99d in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164 #1 0xb5d2b7de in TclpRealloc tcl/generic/tclAlloc.c:747 #2 0xb5dc036a in Tcl_Realloc tcl/generic/tclCkalloc.c:1147 #3 0xb665b526 in GrowUnicodeBuffer tcl/generic/tclStringObj.c:227 #4 0xb6671b61 in ExtendUnicodeRepWithString tcl/generic/tclStringObj.c:3083 #5 0xb6671602 in FillUnicodeRep tcl/generic/tclStringObj.c:3058 #6 0xb665dcb5 in Tcl_GetUnicodeFromObj tcl/generic/tclStringObj.c:725 #7 0xb63dd3aa in TEBCresume tcl/generic/tclExecute.c:5835 #8 0xb5d74c43 in TclNRRunCallbacks tcl/generic/tclBasic.c:4503 #9 0xb5d719e4 in Tcl_EvalObjv tcl/generic/tclBasic.c:4226 #10 0xb5d80013 in TclEvalEx tcl/generic/tclBasic.c:5372 #11 0xb653cafa in Tcl_FSEvalFileEx tcl/generic/tclIOUtil.c:1824 #12 0xb6577599 in Tcl_MainEx tcl/generic/tclMain.c:403 #13 0x447253 in main tcl/unix/tclAppInit.c:84 #14 0xb4f7998c in __libc_start_main (/usr/lib/libc.so.6+0x1e98c)SUMMARY: AddressSanitizer: heap-buffer-overflow /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:860 in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long) Shadow bytes around the buggy address: 0x362879c0: fd fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa 0x362879d0: fd fd fd fa fa fa fd fd fd fd fa fa 00 00 00 00 0x362879e0: fa fa 00 00 04 fa fa fa 00 00 00 fa fa fa fd fd 0x362879f0: fd fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa 0x36287a00: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fa =>0x36287a10: fa fa fd fd fd fa fa fa 00 00 00 00[fa]fa fd fd 0x36287a20: fd fa fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa 0x36287a30: 00 00 00 fa fa fa 00 00 04 fa fa fa 00 00 04 fa 0x36287a40: fa fa fd fd fd fa fa fa fd fd fd fa fa fa fd fd 0x36287a50: fd fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa 0x36287a60: fd fd fd fa fa fa fd fd fd fa fa fa fd fd fd fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd […] ==16557==ABORTING
This is caused by memcmp() being called even when the remaining portion of the operand string is shorter than the match string, present since [b6871e5b803d]. Unlike some other string comparison functions, memcmp() requires buffers to be valid for the length specified even if they differ within the valid range of the shorter buffer (I am aware some find this restriction controversial). I believe the fix is to check whether the remainder of the string is at least as long as the match string, comparable to what is done in StringMapCmd() (generic/tclCmdMZ.c) since [fab27ad2b82f] because Tcl_UniCharNcmp() and Tcl_UniCharNcasecmp() likewise assume both strings are at least the specified number of characters long.
diff --git generic/tclExecute.c generic/tclExecute.c
index 7e014d4..accdbe7 100644
--- generic/tclExecute.c
+++ generic/tclExecute.c
@@ -5855,7 +5855,9 @@ TEBCresume(
p = ustring1;
end = ustring1 + length;
for (; ustring1 < end; ustring1++) {
- if ((*ustring1 == *ustring2) && (length2==1 ||
+ if ((*ustring1 == *ustring2) &&
+ /* Fix bug hhhhhhhhhh: restrict max compare length. */
+ (end-ustring1 >= length2) && (length2==1 ||
memcmp(ustring1, ustring2, sizeof(Tcl_UniChar) * length2)
== 0)) {
if (p != ustring1) {
Fix committed [here]
Thanks for the report and patch!