2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] 5d0f3ecfbb Fix fscanf width specifiers in copyover_recover() to prevent buffer overflow
Agent-Logs-Url: https://github.com/tbamud/tbamud/sessions/82069e78-2bd9-4ff9-9053-0d47dfae5193

Co-authored-by: welcor <357770+welcor@users.noreply.github.com>
2026-04-24 10:19:06 +00:00
copilot-swe-agent[bot] 2eb786ff0d Initial plan 2026-04-24 10:18:25 +00:00
2 changed files with 16 additions and 15 deletions
+1 -1
View File
@@ -415,7 +415,7 @@ void copyover_recover()
for (;;) { for (;;) {
fOld = TRUE; fOld = TRUE;
if (fscanf(fp, "%d %ld %s %s %s\n", &desc, &pref, name, host, guiopt) != 5) { if (fscanf(fp, "%d %ld %511s %1023s %1023s\n", &desc, &pref, name, host, guiopt) != 5) {
if(!feof(fp)) { if(!feof(fp)) {
if(ferror(fp)) if(ferror(fp))
log("SYSERR: error reading copyover file %s: %s", COPYOVER_FILE, strerror(errno)); log("SYSERR: error reading copyover file %s: %s", COPYOVER_FILE, strerror(errno));
+15 -14
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;
}
/* All other characters, including shell metacharacters, are dropped */ /* Legal character */
default: *out = *in; out++;break;
}
in++; in++;
count++;
if (count == maxlen - 1) break;
} }
*out = '\0'; *out = '\0';
} }