2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
d5c688188b Fix stray null write: replace sizeof(buf) with *buf = '\0' in var_subst()
Agent-Logs-Url: https://github.com/tbamud/tbamud/sessions/339cbdde-5de4-4f33-aea6-82df3efbd9c4

Co-authored-by: welcor <357770+welcor@users.noreply.github.com>
2026-04-25 14:44:04 +00:00
copilot-swe-agent[bot]
d627638f56 Initial plan 2026-04-25 14:43:35 +00:00
2 changed files with 16 additions and 15 deletions

View File

@@ -1722,5 +1722,5 @@ void var_subst(void *go, struct script_data *sc, trig_data *trig,
left -= len;
} /* else if *p .. */
} /* while *p .. */
buf[sizeof(buf) - 1] = '\0';
*buf = '\0';
}

View File

@@ -277,10 +277,7 @@ int sprintascii(char *out, bitvector_t bits)
return j;
}
/* 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. */
/* converts illegal filename chars into appropriate equivalents */
static void fix_filename(const char *str, char *outbuf, size_t maxlen)
{
const char *in = str;
@@ -288,17 +285,21 @@ static void fix_filename(const char *str, char *outbuf, size_t maxlen)
int count = 0;
while (*in) {
if (isalnum((unsigned char)*in) || *in == '_' || *in == '-' || *in == '.') {
/* Safe characters kept as-is */
*out++ = *in;
if (++count == maxlen - 1) break;
} else if (*in == ' ') {
/* Spaces become underscores */
*out++ = '_';
if (++count == maxlen - 1) break;
switch(*in) {
case ' ': *out = '_'; out++; break;
case '(': *out = '{'; out++; break;
case ')': *out = '}'; out++; break;
/* skip the following */
case '\'': break;
case '"': break;
/* Legal character */
default: *out = *in; out++;break;
}
/* All other characters, including shell metacharacters, are dropped */
in++;
count++;
if (count == maxlen - 1) break;
}
*out = '\0';
}