Overview
| Artifact ID: | 3ea7a42c2faa62a560de6a892372fcf3b739c0891cc31a5ce393e96b07e49a5d |
|---|---|
| Ticket: | de243b694daaf06e6a0fbcbeb7279c326c25551c
Several trim mechanisms cause segfault / wrong check for NTS |
| User & Date: | sebres on 2018-03-13 18:57:57 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
I noticed segfaults in case of TclTrim (left/right) for non-NTS string representation (I know, this is almost unexpected, but may happen using some modules). Very strange is that it may cause segfault even by validity check of the NTS-string (to avoid segfault)! which is IMHO do not proper implemented: Even to protect a non-usage of such non-NTS string, Tcl checks currently using access of byte, that may be out of range (so causes access violation instead of panic): <code><pre> if ((bytes[numBytes] != '\0') || (trim[numTrim] != '\0')) { Tcl_Panic("TclTrimRight works only on null-terminated strings"); } </pre></code> I repeat again, I know that non-NTS is not "good" at all, but if nevertheless occurred, this one - `bytes[numBytes]` is unexpected as proper validity check for NTS (even because instead of panic you can get segfault). Thus rewritten now using more safe variant (implemented without panic, using new function TclUtfWellFormedEnd, that can do the same check, but without access of bytes outside of bounds). A branch [sebres-8-5-fix-trim-on-mailformed] fixes this. This checks the end-character is well-formed utf8-sequence now (and if not, does in-place call of trim on proper string representation, which contains a NTS zero-byte at end). Additionally: - both work well now on non-NTS strings (without null character at end) without panic; - additionally fixed wrong offsets (trim-length if last char was malformed in case of out of range), for example if this character (like `\xC0\x00` will recognized as 2 bytes char and trimmed with too long offset, results previously in negative length); - new function TclTrim introduced (as safe combination of TclTrimLeft/TclTrimRight). Please review and merge in 8.6 and trunk. - is_private changed to: "0"
- login: "sebres"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Severe"
- status changed to: "Open"
- submitter changed to: "sebres"
- subsystem changed to: "44. UTF-8 Strings"
- title changed to:
Several trim mechanisms cause segfault / wrong check for NTS
- type changed to: "Bug"