...
 
Commits (1)
  • Rob Swindell's avatar
    Insure active_clients is initialized before cleanup() can be called. · 47dd4dce
    Rob Swindell authored
    Fix reported and observed crash in cleanup() (in ftp, mail, websrvr)
    when failing to create the temp directory. This was due to cleanup()
    being called before the protected integer "active_clients" was
    initialized.
    
    Also, md() needs to return the errno value (not a BOOL) since the
    caller may be in another DLL with a different errno (which likely
    has a value of 0/no error).
    47dd4dce
......@@ -6049,6 +6049,7 @@ void DLLCALL ftp_server(void* arg)
startup->shutdown_now=FALSE;
terminate_server=FALSE;
protected_uint32_init(&thread_count, 0);
protected_uint32_init(&active_clients, 0);
do {
/* Setup intelligent defaults */
......@@ -6124,8 +6125,8 @@ void DLLCALL ftp_server(void* arg)
else
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!md(scfg.temp_dir)) {
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", errno, strerror(errno), scfg.temp_dir);
if((i = md(scfg.temp_dir)) != 0) {
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", i, strerror(i), scfg.temp_dir);
cleanup(1,__LINE__);
break;
}
......@@ -6155,7 +6156,6 @@ void DLLCALL ftp_server(void* arg)
lprintf(LOG_DEBUG,"Maximum inactivity: %d seconds",startup->max_inactivity);
protected_uint32_init(&active_clients, 0);
update_clients();
strlwr(scfg.sys_id); /* Use lower-case unix-looking System ID for group name */
......
......@@ -326,13 +326,13 @@ void DLLCALL free_text(char* text[])
/****************************************************************************/
/* If the directory 'path' doesn't exist, create it. */
/****************************************************************************/
BOOL md(const char* inpath)
int md(const char* inpath)
{
char path[MAX_PATH+1];
char* p;
if(inpath[0]==0)
return(FALSE);
return EINVAL;
SAFECOPY(path,inpath);
......@@ -348,10 +348,10 @@ BOOL md(const char* inpath)
if(!isdir(path)) {
if(mkpath(path) != 0)
return FALSE;
return errno;
}
return(TRUE);
return 0;
}
/****************************************************************************/
......
......@@ -5867,7 +5867,6 @@ static void cleanup(int code)
}
lprintf(LOG_INFO, "0000 Done waiting for child threads to terminate");
}
free_cfg(&scfg);
semfile_list_free(&recycle_semfiles);
......@@ -5899,7 +5898,6 @@ static void cleanup(int code)
if(WSAInitialized && WSACleanup()!=0)
lprintf(LOG_ERR,"0000 !WSACleanup ERROR %d",ERROR_VALUE);
#endif
thread_down();
status("Down");
if(terminate_server || code) {
......@@ -6014,6 +6012,7 @@ void DLLCALL mail_server(void* arg)
SetThreadName("sbbs/mailServer");
protected_uint32_init(&thread_count, 0);
protected_uint32_init(&active_clients, 0);
do {
/* Setup intelligent defaults */
......@@ -6084,8 +6083,8 @@ void DLLCALL mail_server(void* arg)
else
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!md(scfg.temp_dir)) {
lprintf(LOG_CRIT, "!ERROR %d (%s) creating directory: %s", errno, strerror(errno), scfg.temp_dir);
if((i = md(scfg.temp_dir)) != 0) {
lprintf(LOG_CRIT, "!ERROR %d (%s) creating directory: %s", i, strerror(i), scfg.temp_dir);
cleanup(1);
return;
}
......@@ -6149,7 +6148,6 @@ void DLLCALL mail_server(void* arg)
lprintf(LOG_DEBUG,"Maximum inactivity: %u seconds",startup->max_inactivity);
protected_uint32_init(&active_clients, 0);
update_clients();
/* open a socket and wait for a client */
......
......@@ -3312,8 +3312,8 @@ sbbs_t::sbbs_t(ushort node_num, union xp_sockaddr *addr, size_t addr_len, const
else
SAFECOPY(cfg.temp_dir,"../temp");
prep_dir(cfg.ctrl_dir, cfg.temp_dir, sizeof(cfg.temp_dir));
if(!md(cfg.temp_dir))
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", errno, strerror(errno), cfg.temp_dir);
if((i = md(cfg.temp_dir)) != 0)
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", i, strerror(i), cfg.temp_dir);
if(sd==INVALID_SOCKET) { /* events thread */
if(startup->first_node==1)
SAFEPRINTF(path,"%sevent",cfg.temp_dir);
......@@ -3541,8 +3541,8 @@ bool sbbs_t::init()
return(false);
}
if(!md(cfg.temp_dir)) {
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", errno, strerror(errno), cfg.temp_dir);
if((i = md(cfg.temp_dir)) != 0) {
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", i, strerror(i), cfg.temp_dir);
return false;
}
......@@ -5124,8 +5124,9 @@ void DLLCALL bbs_thread(void* arg)
lprintf(LOG_INFO,"Verifying/creating node directories");
for(i=0;i<=scfg.sys_nodes;i++) {
if(i) {
if(!md(scfg.node_path[i-1])) {
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", errno, strerror(errno), scfg.node_path[i-1]);
int err;
if((err = md(scfg.node_path[i-1])) != 0) {
lprintf(LOG_CRIT,"!ERROR %d (%s) creating directory: %s", err, strerror(err), scfg.node_path[i-1]);
cleanup(1);
return;
}
......
......@@ -1259,8 +1259,7 @@ extern "C" {
DLLEXPORT void DLLCALL free_text(char* text[]);
DLLEXPORT ushort DLLCALL sys_timezone(scfg_t* cfg);
DLLEXPORT char * DLLCALL prep_dir(const char* base, char* dir, size_t buflen);
DLLEXPORT BOOL DLLCALL md(const char *path);
DLLEXPORT int DLLCALL md(const char *path);
/* scfgsave.c */
DLLEXPORT BOOL DLLCALL save_cfg(scfg_t* cfg, int backup_level);
......
......@@ -1837,8 +1837,8 @@ void DLLCALL services_thread(void* arg)
else
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!md(scfg.temp_dir)) {
lprintf(LOG_CRIT, "!ERROR %d (%s) creating directory: %s", errno, strerror(errno), scfg.temp_dir);
if((i = md(scfg.temp_dir)) != 0) {
lprintf(LOG_CRIT, "!ERROR %d (%s) creating directory: %s", i, strerror(i), scfg.temp_dir);
cleanup(1);
return;
}
......
......@@ -6914,7 +6914,8 @@ void DLLCALL web_server(void* arg)
http_session_t * session=NULL;
void *acc_type;
char *ssl_estr;
int lvl;
int lvl;
int i;
startup=(web_startup_t*)arg;
......@@ -6953,6 +6954,7 @@ void DLLCALL web_server(void* arg)
startup->shutdown_now=FALSE;
terminate_server=FALSE;
protected_uint32_init(&thread_count, 0);
protected_uint32_init(&active_clients,0);
do {
/* Setup intelligent defaults */
......@@ -7033,8 +7035,8 @@ void DLLCALL web_server(void* arg)
else
SAFECOPY(scfg.temp_dir,"../temp");
prep_dir(startup->ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
if(!md(scfg.temp_dir)) {
lprintf(LOG_CRIT, "!ERROR %d (%s) creating directory: %s", errno, strerror(errno), scfg.temp_dir);
if((i = md(scfg.temp_dir)) != 0) {
lprintf(LOG_CRIT, "!ERROR %d (%s) creating directory: %s", i, strerror(i), scfg.temp_dir);
cleanup(1);
return;
}
......@@ -7074,7 +7076,6 @@ void DLLCALL web_server(void* arg)
if(uptime==0)
uptime=time(NULL); /* this must be done *after* setting the timezone */
protected_uint32_init(&active_clients,0);
update_clients();
/* open a socket and wait for a client */
......