Triggers FORTIFY_SOURCE buffer overflow detection
Closed / Fixed3127687fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-12-04 23:54:57
Hi there This affects tcl8.4 only, not tcl8.5. After a rebuild of tcl8.4 in Ubuntu, gitk and other applications were failing to start (even wish8.4 wouldn't start); these would fail with: *** buffer overflow detected ***: wish terminated followed by a backtrace. This is due to the _FORTIFY_SOURCE security feature, see: https://wiki.ubuntu.com/CompilerFlags#-D_FORTIFY_SOURCE=2 https://wiki.ubuntu.com/Security/Features#Built%20with%20Fortify%20Source The original bug has details on why this occurs and is at: https://bugs.launchpad.net/ubuntu/+source/tcl8.4/+bug/683546 As a workaround, I've changed the package to build generic/tclCmdMZ.c with -U_FORTIFY_SOURCE, but ideally the structure would declare the command[] with some define for the maximum length of variable names or commands. Cheers,
loolplain2010-12-05 06:54:57
File Added - 395235: fortify-source.diff
nijtmansplain2010-12-05 15:34:51
>ideally the structure would declare the command[] with some define for the maximum length of variable names or commands. Tcl does not have a maximum length of variable names or commands, other than the amount of availalble memory... For Tcl 8.6, a solution would be to define buffer having size [0], that's the standard way of doing this. But I don't know if all the supported compilers handle that. So for Tcl 8.4/8.5 maybe the best is compile everything with -U_FORTIFY_SOURCE (Tcl8.5 this code moved to tclTrace.c). just my 2c
loolplain2010-12-05 18:41:09
Oddly, I don't hit the problem with wish8.5. Maybe a different code path? I had tried changing command[4] to command[0], but that didn't work (it would still hit FORTIFY_SOURCE protection with a max size of zero). However Kees Cook wrote to me that command[1] is how this should be defined. 8.5 > As long as you don't hit FORTIFY_SOURCE protection, I guess it's best to keep it enabled, but if you do hit it then it would be nice to only disable it in the places where it's a false positive (rather than globally). Another way to avoid the issue entirely is to have a char *command and runtime allocate it, but that might have a performance hit.
nijtmansplain2010-12-06 05:14:59
changing command[4] to command[1] has the problem that the structure will be over-allocated (sizeof might add passing characters.....) better: replace the strcpy with memcpy, as we already know the length anyway. This is faster and should not trigger the FORTIFY_SOURCE. patch attached. Does this help?
nijtmans Ticket [3127687fff]: 1 change
[History diff]2010-12-06 05:15:35
nijtmansplain2010-12-06 05:16:09
File Added - 395305: 3127687.patch
dkfplain2010-12-06 05:27:34
FWIW, I've been converting Tcl to use memcpy instead of strcpy whenever we know the length anyway (on the grounds that it might also be faster) but I don't think I've done any of that back in 8.4 (and I can't remember for 8.5...)
nijtmansplain2010-12-06 05:28:11
allow_comments - 1 This is a dup of #3048354, which was never backported to 8.4. Fix is the same. Fixed on 8.4 branch.
Log in (anonymous is fine) to add a comment.
Attachments:
- 3127687.patch [download] added by nijtmans on 2010-12-06 05:16:09. [details]
- fortify-source.diff [download] added by lool on 2010-12-05 06:54:57. [details]