Commits (2)
  • Rob Swindell's avatar
    Fix CID 174496: Integer handling issues (BAD_SHIFT) · bf1cae28
    Rob Swindell authored
    Don't repeat call atoi() unnecessarily.
    bf1cae28
  • Rob Swindell's avatar
    Fix DIZ extraction/use for FTP uploads · b1449b27
    Rob Swindell authored
    1. Was not setting f->dir to the correct directory number, so only ftp-uploads to the *first* directory (dirnum = 0) would extract DIZ files of uploaded files.
    
    Removing the 'dirnum' parameter to addfile() since that implied that you did not have to initialize the 'dir' element of the passed file_t, but you do: to get the correct file path for file size/date detection and the DIZ extraction.
    
    2. Was getting heap-corruption when freeing the imported/formatted DIZ text on Windows once the above problem was fixed: can't free() in one DLL memory that was allocated in another DLL. Created and now using free_diz() to free the memory allocated in read_diz().
    
    format_diz() handles a NULL 'lines' argument correctly/gracefully, so no need for the NULL lines check in sbbs_t::uploadfile().
    
    Added FTP server log messages for successful file upload or update by user.
    b1449b27
......@@ -108,7 +108,7 @@ bool get_file_diz(file_t* f, char* ext, size_t maxlen)
printf("Parsing DIZ: %s\n", diz_fpath);
char* lines = read_diz(diz_fpath, NULL);
format_diz(lines, ext, maxlen, 0, false);
free(lines);
free_diz(lines);
remove(diz_fpath);
if(mode&ASCII_ONLY)
......
......@@ -239,8 +239,9 @@ bool sbbs_t::movefile(smb_t* smb, file_t* f, int newdir)
return false;
}
f->dir = newdir;
newfile.dfield = NULL; // addfile() ends up realloc'ing dfield (in smb_addmsg)
bool result = addfile(&cfg, newdir, &newfile, newfile.extdesc, newfile.metadata, /* client: */NULL);
bool result = addfile(&cfg, &newfile, newfile.extdesc, newfile.metadata, /* client: */NULL);
free(newfile.dfield);
if(!result)
return false;
......
......@@ -725,12 +725,12 @@ int file_sauce_hfields(file_t* f, struct sauce_charinfo* info)
return SMB_SUCCESS;
}
bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, const char* metadata, client_t* client)
bool addfile(scfg_t* cfg, file_t* f, const char* extdesc, const char* metadata, client_t* client)
{
char fpath[MAX_PATH + 1];
smb_t smb;
if(smb_open_dir(cfg, &smb, dirnum) != SMB_SUCCESS)
if(smb_open_dir(cfg, &smb, f->dir) != SMB_SUCCESS)
return false;
getfilepath(cfg, f, fpath);
......@@ -1112,6 +1112,11 @@ char* read_diz(const char* path, struct sauce_charinfo* sauce)
return buf;
}
void free_diz(char* buf)
{
free(buf);
}
char* format_diz(const char* src, char* dest, size_t maxlen, int width, bool ice)
{
if(src == NULL) {
......
......@@ -55,7 +55,7 @@ DLLEXPORT time_t getfiletime(scfg_t*, file_t*);
DLLEXPORT ulong gettimetodl(scfg_t*, file_t*, uint rate_cps);
DLLEXPORT ulong getuserxfers(scfg_t*, const char* from, uint to);
DLLEXPORT bool hashfile(scfg_t*, file_t*);
DLLEXPORT bool addfile(scfg_t*, uint dirnum, file_t*, const char* extdesc, const char* metadata, client_t*);
DLLEXPORT bool addfile(scfg_t*, file_t*, const char* extdesc, const char* metadata, client_t*);
DLLEXPORT bool removefile(scfg_t*, uint dirnum, const char* filename);
DLLEXPORT char* format_filename(const char* fname, char* buf, size_t, bool pad);
DLLEXPORT bool safest_filename(const char* fname);
......@@ -63,6 +63,7 @@ DLLEXPORT bool illegal_filename(const char* fname);
DLLEXPORT bool allowed_filename(scfg_t*, const char* fname);
DLLEXPORT bool extract_diz(scfg_t*, file_t*, str_list_t diz_fname, char* path, size_t);
DLLEXPORT char* read_diz(const char* path, struct sauce_charinfo*);
DLLEXPORT void free_diz(char*);
DLLEXPORT char* format_diz(const char* src, char* dest, size_t maxlen, int width, bool ice_color);
DLLEXPORT char* prep_file_desc(const char *src, char* dst);
DLLEXPORT int file_client_hfields(file_t*, client_t*);
......
......@@ -1014,6 +1014,7 @@ static void receive_thread(void* arg)
if(xfer.dir>=0) {
memset(&f,0,sizeof(f));
f.dir = xfer.dir;
smb_hfield_str(&f, SMB_FILENAME, getfname(xfer.filename));
smb_hfield_str(&f, SENDER, xfer.user->alias);
......@@ -1039,7 +1040,7 @@ static void receive_thread(void* arg)
lprintf(LOG_DEBUG,"%04d <%s> DATA Parsing DIZ: %s",xfer.ctrl_sock, xfer.user->alias,tmp);
char* lines = read_diz(tmp, &sauce);
format_diz(lines, extdesc, sizeof(extdesc), sauce.width, sauce.ice_color);
free(lines);
free_diz(lines);
if(!fdesc[0]) { /* use for normal description */
prep_file_desc(extdesc, fdesc); /* strip control chars and dupe chars */
}
......@@ -1052,12 +1053,18 @@ static void receive_thread(void* arg)
if(f.desc == NULL)
smb_new_hfield_str(&f, SMB_FILEDESC, fdesc);
if(filedat) {
if(!updatefile(&scfg, &f))
if(updatefile(&scfg, &f))
lprintf(LOG_INFO,"%04d <%s> DATA updated file: %s"
,xfer.ctrl_sock, xfer.user->alias, f.name);
else
lprintf(LOG_ERR,"%04d <%s> !DATA ERROR updating file (%s) in database"
,xfer.ctrl_sock, xfer.user->alias, f.name);
/* need to update the index here */
} else {
if(!addfile(&scfg, xfer.dir, &f, extdesc, /* metatdata: */NULL, xfer.client))
if(addfile(&scfg, &f, extdesc, /* metatdata: */NULL, xfer.client))
lprintf(LOG_INFO,"%04d <%s> DATA uploaded file: %s"
,xfer.ctrl_sock, xfer.user->alias, f.name);
else
lprintf(LOG_ERR,"%04d <%s> !DATA ERROR adding file (%s) to database"
,xfer.ctrl_sock, xfer.user->alias, f.name);
}
......
......@@ -1143,7 +1143,7 @@ static void get_diz(scfg_t* scfg, file_t* file, char** extdesc)
char* lines = read_diz(diz_fpath, &sauce);
if(lines != NULL) {
format_diz(lines, extbuf, sizeof(extbuf), sauce.width, sauce.ice_color);
free(lines);
free_diz(lines);
free(*extdesc);
*extdesc = strdup(extbuf);
file_sauce_hfields(file, &sauce);
......
......@@ -875,7 +875,8 @@ int sbbs_t::listfileinfo(uint dirnum, const char *filespec, long mode)
sprintf(str,text[AddToOfflineDirQ]
,f->name,cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->sname);
if(yesno(str)) {
addfile(&cfg, i, f, f->extdesc, f->metadata, /* client: */NULL);
f->dir = i;
addfile(&cfg, f, f->extdesc, f->metadata, /* client: */NULL);
}
}
}
......
......@@ -666,8 +666,9 @@ void tevents_cfg()
,str,50,K_EDIT);
cfg.event[i]->months=0;
for(p=str;*p;p++) {
if(atoi(p)) {
cfg.event[i]->months|=(1<<(atoi(p)-1));
int num = atoi(p);
if(num > 0) {
cfg.event[i]->months|=(1<<(num-1));
while(*p && IS_DIGIT(*p))
p++;
} else {
......
......@@ -148,9 +148,8 @@ bool sbbs_t::uploadfile(file_t* f)
lprintf(LOG_DEBUG, "Parsing DIZ: %s", str);
char* lines = read_diz(str, &sauce);
if(lines != NULL)
format_diz(lines, ext, sizeof(ext), sauce.width, sauce.ice_color);
free(lines);
format_diz(lines, ext, sizeof(ext), sauce.width, sauce.ice_color);
free_diz(lines);
file_sauce_hfields(f, &sauce);
if(f->desc == NULL || f->desc[0] == 0) {
......@@ -174,7 +173,7 @@ bool sbbs_t::uploadfile(file_t* f)
smb_hfield_bin(f, SMB_COST, length);
smb_hfield_str(f, SENDER, useron.alias);
bprintf(text[FileNBytesReceived],f->name, u64toac(length,tmp));
if(!addfile(&cfg, f->dir, f, ext, /* metadata: */NULL, &client))
if(!addfile(&cfg, f, ext, /* metadata: */NULL, &client))
return false;
safe_snprintf(str,sizeof(str),"uploaded %s to %s %s"
......