Skip to content

Fix Tcl_TraceVar() / tcl_eggstr() modifying original tcl variable#1733

Open
michaelortmann wants to merge 2 commits into
eggheads:developfrom
michaelortmann:fix.tcl.tracevar
Open

Fix Tcl_TraceVar() / tcl_eggstr() modifying original tcl variable#1733
michaelortmann wants to merge 2 commits into
eggheads:developfrom
michaelortmann:fix.tcl.tracevar

Conversation

@michaelortmann

@michaelortmann michaelortmann commented Jan 9, 2025

Copy link
Copy Markdown
Member

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:

s[abs(st->max)] = 0;

This PR fixes this, by modifying the destination string, when the original is copied to the destination here:

strcpy(st->str, s);
via replacing that strcpy() with a strlcpy().

There are a few special variables / handlers here:

eggdrop/src/tcl.c

Lines 288 to 298 in 0f5599e

if (st->str == botnetnick)
botnet_change(s);
else if (st->str == logfile_suffix)
logsuffix_change(s);
else if (st->str == firewall) {
splitc(firewall, s, ':');
if (!firewall[0])
strcpy(firewall, s);
else
firewallport = atoi(s);
} else

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
WARNING: Value for username truncated to 10 chars
DBG: Username: tcl9eggdro
DBG: dasbrain's-awesome-configuration-template-name: tcl9eggdro

After:

DBG: dasbrain's-awesome-configuration-template-name: tcl9eggdrop
WARNING: Value for username truncated to 10 chars
DBG: Username: tcl9eggdro
DBG: dasbrain's-awesome-configuration-template-name: tcl9eggdrop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Username truncation affects the original variable.

1 participant