Commit eb8114bd authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Allow maximum uploaded filename length to be configured

Default to 64 characters. Maximum value is 65535 characters, but filenames larger than 64 characters may be problematic (e.g. searching for them, displaying them, security concerns), so only increase with caution. Shorter values are fine, but 0 will just revert back to the default.
parent 7ccc618a
Pipeline #2566 passed with stage
in 9 minutes and 16 seconds
......@@ -1304,7 +1304,7 @@ bool illegal_filename(const char *fname)
bool allowed_filename(scfg_t* cfg, const char *fname)
{
size_t len = strlen(fname);
if(len < 1)
if(len < 1 || len > cfg->filename_maxlen)
return false;
if(cfg->file_misc & FM_SAFEST)
......
......@@ -75,7 +75,8 @@ void xfer_opts()
SAFEPRINTF2(str, "Most %s, %scluding Spaces"
,cfg.file_misc & FM_EXASCII ? "CP437" : "ASCII"
,cfg.file_misc & FM_SPACES ? "In" : "Ex");
sprintf(opt[i++], "%-33.33s%s", "Allow Filename Characters", str);
sprintf(opt[i++], "%-33.33s%u characters", "Allowed Filename Length", cfg.filename_maxlen);
sprintf(opt[i++], "%-33.33s%s", "Allowed Filename Characters", str);
strcpy(opt[i++],"Viewable Files...");
strcpy(opt[i++],"Testable Files...");
strcpy(opt[i++],"Download Events...");
......@@ -201,6 +202,24 @@ void xfer_opts()
,ultoa(cfg.leech_sec,tmp,10),3,K_EDIT|K_NUMBER);
cfg.leech_sec=atoi(tmp);
break;
case __COUNTER__:
uifc.helpbuf=
"`Maximum Uploaded Filename Length Allowed:`\n"
"\n"
"This value is the maximum length of filenames allowed to be uploaded.\n"
"\n"
"Only 64 characters of filenames are indexed (searchable) and sometimes\n"
"(depending on the terminal) only 64 or fewer characters of a filename\n"
"may be displayed to a user. For these reasons, `64` characters is a\n"
"reasonable maximum filename length to enforce (and thus, the default).\n"
"\n"
"The absolute maximum filename length supported is `65535` characters."
;
uifc.input(WIN_MID|WIN_SAV,0,0
,"Maximum Uploaded Filename Length Allowed (in characters)"
,ultoa(cfg.filename_maxlen,tmp,10), 5, K_EDIT|K_NUMBER);
cfg.filename_maxlen=atoi(tmp);
break;
case __COUNTER__: /* Uploaded Filename characters allowed */
i = 0;
strcpy(opt[i++], "Safest Subset Only (A-Z, a-z, 0-9, -, _, and .)");
......
......@@ -462,6 +462,7 @@ typedef struct
int32_t msg_misc; /* Global Message-Related Settings (upper 16-bits default to on) */
int32_t file_misc; /* File Misc Settings */
int32_t xtrn_misc; /* External Programs Misc Settings */
uint16_t filename_maxlen; /* Maximum filename length */
char node_comspec[LEN_CMD+1]; /* DOS COMMAND.COM to use */
char node_editor[LEN_CMD+1]; /* Local text editor command line to use */
......
......@@ -57,8 +57,11 @@ BOOL read_file_cfg(scfg_t* cfg, char* error, size_t maxerrlen)
get_int(cfg->leech_pct,instream);
get_int(cfg->leech_sec,instream);
get_int(cfg->file_misc,instream);
get_int(cfg->filename_maxlen, instream);
if(cfg->filename_maxlen == 0)
cfg->filename_maxlen = SMB_FILEIDX_NAMELEN;
for(i=0;i<30;i++)
for(i=0;i<29;i++)
get_int(n,instream);
/**************************/
......
......@@ -660,8 +660,9 @@ BOOL write_file_cfg(scfg_t* cfg, int backup_level)
put_int(cfg->leech_pct,stream);
put_int(cfg->leech_sec,stream);
put_int(cfg->file_misc,stream);
put_int(cfg->filename_maxlen, stream);
n=0;
for(i=0;i<30;i++)
for(i=0;i<29;i++)
put_int(n,stream);
/* Extractable File Types */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment