Fix Tcl_TraceVar() / tcl_eggstr() modifying original tcl variable
Found by: DasBrain Patch by: michaelortmann Fixes: #1544
One-line summary:
Fix Tcl_TraceVar() / tcl_eggstr()
Additional description (if needed): This bug affects eggdrop since the dawn of time.
Eggdrop uses Tcl_TraceVar() when a tcl variable is set. In callback function tcl_eggstr() it truncates strings to their maximum length. The Bug is, that it modifies the original string here: https://github.com/eggheads/eggdrop/blob/0f5599e1fafa97454dc7a8b147c6076638e95ba8/src/tcl.c#L287
This PR fixes this, by modifying the destination string, when the original is copied to the destination here: https://github.com/eggheads/eggdrop/blob/0f5599e1fafa97454dc7a8b147c6076638e95ba8/src/tcl.c#L299 via replacing that strcpy() with a strlcpy().
There are a few special variables / handlers here: https://github.com/eggheads/eggdrop/blob/0f5599e1fafa97454dc7a8b147c6076638e95ba8/src/tcl.c#L288-L298
It would make this PR too complex to also look into those and fix those cases. So this PR will fix all variables but the following 3:
botnetnick
logfile_suffix
firewall
Test cases demonstrating functionality (if applicable): eggdrop.conf:
set dasbrain's-awesome-configuration-template-name tcl9eggdrop
putlog "DBG: dasbrain's-awesome-configuration-template-name: ${dasbrain's-awesome-configuration-template-name}"
set username ${dasbrain's-awesome-configuration-template-name}
putlog "DBG: Username: $username"
putlog "DBG: dasbrain's-awesome-configuration-template-name: ${dasbrain's-awesome-configuration-template-name}"
Before:
DBG: dasbrain's-awesome-configuration-template-name: tcl9eggdrop
DBG: Username: tcl9eggdro
DBG: dasbrain's-awesome-configuration-template-name: tcl9eggdro
After:
DBG: dasbrain's-awesome-configuration-template-name: tcl9eggdrop
DBG: Username: tcl9eggdro
DBG: dasbrain's-awesome-configuration-template-name: tcl9eggdrop