2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] ed5f6a81da Fix stack buffer overflow in var_subst() (dg_variables.c)
Agent-Logs-Url: https://github.com/tbamud/tbamud/sessions/5e320127-5bfa-499e-9776-e8a6cdd06bde

Co-authored-by: welcor <357770+welcor@users.noreply.github.com>
2026-04-24 10:22:01 +00:00
copilot-swe-agent[bot] a2e3c2481d Initial plan 2026-04-24 10:17:15 +00:00
2 changed files with 22 additions and 14 deletions
+7
View File
@@ -1636,6 +1636,13 @@ void var_subst(void *go, struct script_data *sc, trig_data *trig,
int paren_count = 0; int paren_count = 0;
int dots = 0; int dots = 0;
/* reject lines that would overflow our fixed-size buffers */
if (strnlen(line, MAX_INPUT_LENGTH) >= MAX_INPUT_LENGTH) {
script_log("Trigger VNum %d: variable substitution line too long, ignoring.", GET_TRIG_VNUM(trig));
*buf = '\0';
return;
}
/* skip out if no %'s */ /* skip out if no %'s */
if (!strchr(line, '%')) { if (!strchr(line, '%')) {
strcpy(buf, line); strcpy(buf, line);
+14 -13
View File
@@ -277,10 +277,7 @@ int sprintascii(char *out, bitvector_t bits)
return j; return j;
} }
/* converts illegal filename chars into appropriate equivalents. /* converts illegal filename chars into appropriate equivalents */
* Uses an allowlist: alphanumerics, underscore, hyphen, and dot are kept;
* spaces are converted to underscores; all other characters (including shell
* metacharacters such as ; | & ` $ > < \n) are silently dropped. */
static void fix_filename(const char *str, char *outbuf, size_t maxlen) static void fix_filename(const char *str, char *outbuf, size_t maxlen)
{ {
const char *in = str; const char *in = str;
@@ -288,17 +285,21 @@ static void fix_filename(const char *str, char *outbuf, size_t maxlen)
int count = 0; int count = 0;
while (*in) { while (*in) {
if (isalnum((unsigned char)*in) || *in == '_' || *in == '-' || *in == '.') { switch(*in) {
/* Safe characters kept as-is */ case ' ': *out = '_'; out++; break;
*out++ = *in; case '(': *out = '{'; out++; break;
if (++count == maxlen - 1) break; case ')': *out = '}'; out++; break;
} else if (*in == ' ') {
/* Spaces become underscores */ /* skip the following */
*out++ = '_'; case '\'': break;
if (++count == maxlen - 1) break; case '"': break;
/* Legal character */
default: *out = *in; out++;break;
} }
/* All other characters, including shell metacharacters, are dropped */
in++; in++;
count++;
if (count == maxlen - 1) break;
} }
*out = '\0'; *out = '\0';
} }