CQ adjastement
All checks were successful
Altlinux build / build-alt (push) Successful in 2m39s
Archlinux build / build-arch (push) Successful in 3m7s
Archlinux build / make-test (push) Successful in 1m2s
Debian build / build-ubuntu (push) Successful in 4m0s

This commit is contained in:
Alexey Khromov 2025-04-20 00:50:35 +03:00
parent 5a036bb150
commit ff329a7602
25 changed files with 184 additions and 131 deletions

View File

@ -259,12 +259,16 @@ int main(int argc, char *argv[], char *envp[])
mainenv[0] = NULL; mainenv[0] = NULL;
i=0; i=0;
if ( envp[0] ) {
while (envp[i]) { while (envp[i]) {
mainenv[i] = malloc(strlen(envp[i])+2); mainenv[i] = malloc(strlen(envp[i])+2);
if ( mainenv[i] ) {
strcpy(mainenv[i], envp[i]); strcpy(mainenv[i], envp[i]);
mainenv[++i] = NULL; mainenv[++i] = NULL;
DEB((D_FREE, "Program ENV: %s\n", mainenv[(i-1)])); DEB((D_FREE, "Program ENV: %s\n", mainenv[(i-1)]));
} }
}
}
memset(&opts, '\0', sizeof(s_bforce_opts)); memset(&opts, '\0', sizeof(s_bforce_opts));

View File

@ -662,7 +662,7 @@ static int proc_domain(s_domain *dest, char *value)
if( p_path[strlen(p_path)-1] == DIRSEPCHR ) if( p_path[strlen(p_path)-1] == DIRSEPCHR )
dest->path = xstrcpy(p_path); dest->path = xstrcpy(p_path);
else else
dest->path = string_concat(p_path, DIRSEPSTR, NULL); dest->path = string_concat(p_path, DIRSEPSTR, '\0');
return(PROC_RC_OK); return(PROC_RC_OK);
} }
else else
@ -751,7 +751,7 @@ static int proc_path(s_string *dest, char *value)
if( value[strlen(value)-1] == DIRSEPCHR ) if( value[strlen(value)-1] == DIRSEPCHR )
dest->str = xstrcpy(value); dest->str = xstrcpy(value);
else else
dest->str = string_concat(value, DIRSEPSTR, NULL); dest->str = string_concat(value, DIRSEPSTR, '\0');
return(PROC_RC_OK); return(PROC_RC_OK);
} }
@ -1004,7 +1004,7 @@ static int proc_filebox(s_filebox *dest, char *value)
if( p_path[strlen(p_path)-1] == DIRSEPCHR ) if( p_path[strlen(p_path)-1] == DIRSEPCHR )
dest->path = xstrcpy(p_path); dest->path = xstrcpy(p_path);
else else
dest->path = string_concat(p_path, DIRSEPSTR, NULL); dest->path = string_concat(p_path, DIRSEPSTR, '\0');
dest->flavor = flavor; dest->flavor = flavor;
return rc; return rc;
} }

View File

@ -1035,7 +1035,7 @@ int daemon_run(const char *confname, const char *incname, bool quit)
/* /*
* Check rescan timer * Check rescan timer
*/ */
if( !timer_running(timer_rescan) || timer_expired(timer_rescan) ) if( timer_expired(timer_rescan) )
{ {
(void)daemon_rescan_sysqueue(&daemon_sys_queue, (void)daemon_rescan_sysqueue(&daemon_sys_queue,
daemon_queues); daemon_queues);
@ -1045,7 +1045,7 @@ int daemon_run(const char *confname, const char *incname, bool quit)
/* /*
* Check alive timer * Check alive timer
*/ */
if( !timer_running(timer_alive) || timer_expired(timer_alive) ) if( timer_expired(timer_alive) )
{ {
daemon_alive_message(&daemon_sys_queue); daemon_alive_message(&daemon_sys_queue);
timer_set(&timer_alive, DAEMON_ALIVE_TIMER); timer_set(&timer_alive, DAEMON_ALIVE_TIMER);

View File

@ -955,7 +955,7 @@ yydestruct (char *yymsg,
{ {
YY_USE (yyvaluep); YY_USE (yyvaluep);
if (!yymsg) if (!yymsg)
yymsg = "Deleting"; yymsg = "Deleting"; // cppcheck_suppress uselessAssignmentPtrArg
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
@ -1067,8 +1067,9 @@ yysetstate:
data in use in that stack, in bytes. This used to be a data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */ be undefined if yyoverflow is a macro. */
yyoverflow (YY_("memory exhausted"), yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * YYSIZEOF (*yyssp), &yyss1, yysize * YYSIZEOF (*yyssp), // cppcheck_suppress syntaxError
&yyvs1, yysize * YYSIZEOF (*yyvsp), &yyvs1, yysize * YYSIZEOF (*yyvsp),
&yyls1, yysize * YYSIZEOF (*yylsp), &yyls1, yysize * YYSIZEOF (*yylsp),
&yystacksize); &yystacksize);
@ -1088,7 +1089,7 @@ yysetstate:
yy_state_t *yyss1 = yyss; yy_state_t *yyss1 = yyss;
union yyalloc *yyptr = union yyalloc *yyptr =
YY_CAST (union yyalloc *, YY_CAST (union yyalloc *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); // cppcheck_suppress sizeofwithnumericparameter
if (! yyptr) if (! yyptr)
YYNOMEM; YYNOMEM;
YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyss_alloc, yyss);

View File

@ -200,9 +200,18 @@ static void req_proc_ext(s_freq *freq, char *reqname)
char srfname[L_tmpnam+5]; char srfname[L_tmpnam+5];
char rspname[L_tmpnam+5]; char rspname[L_tmpnam+5];
char *comline = NULL; char *comline = NULL;
char *chunk;
if( tmpnam(srfname) ) chunk = xmalloc(L_tmpnam+1);
if ( chunk )
{ {
getrandname(chunk, L_tmpnam);
chunk[L_tmpnam]='\0';
strnxcpy(srfname, chunk, L_tmpnam);
free(chunk);
//if( tmpnam(srfname) )
//{
strncpy(rspname, srfname, L_tmpnam+4); strncpy(rspname, srfname, L_tmpnam+4);
rspname[L_tmpnam+4] = '\0'; rspname[L_tmpnam+4] = '\0';
strcat(srfname, ".srf"); strcat(srfname, ".srf");

View File

@ -116,7 +116,7 @@ static pid_t lock_read_pid(const char *lckname)
if( len == sizeof(pid) || sscanf(buf, "%d", &pid) != 1 || pid == 0 ) if( len == sizeof(pid) || sscanf(buf, "%d", &pid) != 1 || pid == 0 )
{ {
/* We found binary lock file? */ /* We found binary lock file? */
pid = *((int *)buf); pid = *((u_int *)buf);
#ifndef LOCK_BINARY #ifndef LOCK_BINARY
log("warning: found binary lock file %s", lckname); log("warning: found binary lock file %s", lckname);
#endif #endif
@ -197,12 +197,15 @@ static int lock_create(const char *lckname, const char *tmpname)
int rc, fd; int rc, fd;
int tries; int tries;
#ifdef LOCK_BINARY #ifdef LOCK_BINARY
pid_t pid; pid_t pid;
#else #else
char buf[32]; char buf[32];
#endif #endif
ASSERT(lckname != NULL && tmpname != NULL); ASSERT(lckname != NULL && tmpname != NULL);
if( (fd = open(tmpname, O_CREAT | O_RDWR, 0644)) < 0 ) if( (fd = open(tmpname, O_CREAT | O_RDWR, 0644)) < 0 )
@ -299,7 +302,6 @@ int port_checklock(const char *lockdir, const s_modemport *modemport)
rc = lock_check(lckname); rc = lock_check(lckname);
if( lckname )
free(lckname); free(lckname);
return rc; return rc;
@ -312,20 +314,24 @@ int port_lock(const char *lockdir, const s_modemport *modemport)
{ {
int rc; int rc;
char *lckname; char *lckname;
char *tmpname, *p_tmpname; char *tmpname, *p_tmpname, *chunk;
if( *lockdir ) if( *lockdir )
tmpname = xstrcpy(lockdir); tmpname = xstrcpy(lockdir);
else else
tmpname = xstrcpy(BFORCE_LOCK_DIR); tmpname = xstrcpy(BFORCE_LOCK_DIR);
tmpname = xstrcat(tmpname, "bfXXXXXX"); //tmpname = xstrcat(tmpname, "bfXXXXXX");
if( (p_tmpname = mktemp(tmpname)) == NULL ) chunk = xmalloc(7);
{ getrandname(chunk,6);
logerr("can't generate unique file name from \"%s\"", tmpname); p_tmpname = string_concat(tmpname, "bf", chunk, '\0');
free(tmpname); return 1;
} //if( (p_tmpname = mktemp(tmpname)) == NULL )
//{
// logerr("can't generate unique file name from \"%s\"", tmpname);
// free(tmpname); return 1;
//}
if( (lckname = lock_getname(lockdir, modemport)) == NULL ) if( (lckname = lock_getname(lockdir, modemport)) == NULL )
{ {
@ -340,7 +346,6 @@ int port_lock(const char *lockdir, const s_modemport *modemport)
if( tmpname ) if( tmpname )
free(tmpname); free(tmpname);
if( lckname )
free(lckname); free(lckname);
return rc; return rc;

View File

@ -144,7 +144,7 @@ int log_close(void)
ASSERT(log_fp); ASSERT(log_fp);
if( log_fp ) if( log_fp != NULL )
{ {
rc = fclose(log_fp); rc = fclose(log_fp);
DEB((D_INFO,"Closing log file.")); DEB((D_INFO,"Closing log file."));
@ -543,7 +543,7 @@ void debug(unsigned long what, const char *str, ...)
debug_open(); debug_open();
} }
if( debug_fp ) if( debug_fp != NULL )
{ {
fprintf(debug_fp, "%s ", time_string_log(buf, sizeof(buf), 0)); fprintf(debug_fp, "%s ", time_string_log(buf, sizeof(buf), 0));
va_start(args, str); va_start(args, str);

View File

@ -155,8 +155,8 @@ int exec_redirect_descriptor(int desc, const char *fname, int flags)
close(fd); close(fd);
return -1; return -1;
} }
//cppcheck-suppress resourceLeak
return 0; return 0; //cppcheck-suppress resourceLeak
} }
int exec_command(s_exec_options *eopt) int exec_command(s_exec_options *eopt)

View File

@ -46,7 +46,7 @@ char *out_getname_4d(s_faddr addr)
else else
sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point); sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point);
dest = string_concat(p_outbound, buf, NULL); dest = string_concat(p_outbound, buf, '\0');
} }
else else
{ {
@ -55,7 +55,7 @@ char *out_getname_4d(s_faddr addr)
else else
sprintf(buf, ".%03x/%04x%04x.pnt/%08x", addr.zone, addr.net, addr.node, addr.point); sprintf(buf, ".%03x/%04x%04x.pnt/%08x", addr.zone, addr.net, addr.node, addr.point);
dest = string_concat(out_root, out_main, buf, NULL); dest = string_concat(out_root, out_main, buf, '\0');
} }
} }
@ -83,7 +83,7 @@ char *out_getname_domain(s_faddr addr)
else else
sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point); sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point);
dest = string_concat(cfptr->d.domain.path, buf, NULL); dest = string_concat(cfptr->d.domain.path, buf, '\0');
break; break;
} }
} }
@ -102,7 +102,7 @@ char *out_getname_amiga(s_faddr addr)
if( p_amigaoutbound && *p_amigaoutbound ) if( p_amigaoutbound && *p_amigaoutbound )
{ {
sprintf(buf, "%d.%d.%d.%d", addr.zone, addr.net, addr.node, addr.point); sprintf(buf, "%d.%d.%d.%d", addr.zone, addr.net, addr.node, addr.point);
dest = string_concat(p_amigaoutbound, buf, NULL); dest = string_concat(p_amigaoutbound, buf, '\0');
} }
return dest; return dest;

View File

@ -155,7 +155,7 @@ static int out_scan_bso_dir(s_outbound_callback_data *callback,
if( alst || !fa_list ) if( alst || !fa_list )
{ {
p = string_concat(path, dirent->d_name, "/", NULL); p = string_concat(path, dirent->d_name, "/", '\0');
out_scan_bso_dir(callback, fa_list, addr, p, 1); out_scan_bso_dir(callback, fa_list, addr, p, 1);
if( p ) { free(p); p = NULL; } if( p ) { free(p); p = NULL; }
} }
@ -178,7 +178,7 @@ static int out_scan_bso_dir(s_outbound_callback_data *callback,
if( alst || !fa_list ) if( alst || !fa_list )
{ {
callback->path = string_concat(path, dirent->d_name, NULL); callback->path = string_concat(path, dirent->d_name, '\0');
callback->addr = *addr; callback->addr = *addr;
callback->type = OUTB_TYPE_BSO; callback->type = OUTB_TYPE_BSO;
callback->flavor = -1; callback->flavor = -1;
@ -250,7 +250,7 @@ static int out_scan_bso(s_outbound_callback_data *callback,
if( alst || mailfor == NULL ) if( alst || mailfor == NULL )
{ {
newpath = string_concat(out_root, dirent->d_name, "/", NULL); newpath = string_concat(out_root, dirent->d_name, "/", '\0');
out_scan_bso_dir(callback, mailfor, &addr, newpath, 0); out_scan_bso_dir(callback, mailfor, &addr, newpath, 0);
free(newpath); free(newpath);
} }
@ -296,7 +296,7 @@ static int out_scan_fbox_dir(s_outbound_callback_data *callback,
while( (dirent = readdir(dir)) ) while( (dirent = readdir(dir)) )
{ {
callback->path = string_concat(path, dirent->d_name, NULL); callback->path = string_concat(path, dirent->d_name, '\0');
if( is_regfile(callback->path) ) if( is_regfile(callback->path) )
{ {
callback->addr = addr; callback->addr = addr;
@ -340,7 +340,7 @@ static int out_scan_lbox(s_outbound_callback_data *callback,
alst = alst->next ); alst = alst->next );
if( alst ) if( alst )
{ {
newpath = string_concat(path, dirent->d_name, "/", NULL); newpath = string_concat(path, dirent->d_name, "/", '\0');
(void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD); (void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD);
free(newpath); free(newpath);
} }
@ -348,7 +348,7 @@ static int out_scan_lbox(s_outbound_callback_data *callback,
else else
{ {
/* Scan all fileboxes */ /* Scan all fileboxes */
newpath = string_concat(path, dirent->d_name, "/", NULL); newpath = string_concat(path, dirent->d_name, "/", '\0');
(void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD); (void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD);
free(newpath); free(newpath);
} }
@ -424,7 +424,7 @@ static int out_scan_aso(s_outbound_callback_data *callback,
if( alst || !mailfor ) if( alst || !mailfor )
{ {
callback->path = string_concat(path, dirent->d_name, NULL); callback->path = string_concat(path, dirent->d_name, '\0');
callback->addr = addr; callback->addr = addr;
callback->type = OUTB_TYPE_ASO; callback->type = OUTB_TYPE_ASO;
callback->flavor = -1; callback->flavor = -1;

View File

@ -593,7 +593,7 @@ else if (bstate->mode == bmode_transfer) {
case 1: //send M_FILE - M_GET forcibly sets this phase. M_GET must open needed file case 1: //send M_FILE - M_GET forcibly sets this phase. M_GET must open needed file
DEB((D_24554, "send M_FILE")); DEB((D_24554, "send M_FILE"));
buf[0] = BPMSG_FILE; buf[0] = BPMSG_FILE;
*block_length = 1+sprintf(buf+1, "%s %ld %ld 0", bstate->pi->send->net_name, *block_length = 1+sprintf(buf+1, "%s %zu %lu 0", bstate->pi->send->net_name,
bstate->pi->send->bytes_total, bstate->pi->send->mod_time); bstate->pi->send->bytes_total, bstate->pi->send->mod_time);
DEB((D_24554, "M_FILE: %s", buf+1)); DEB((D_24554, "M_FILE: %s", buf+1));
*block_type = BINKP_BLK_CMD; *block_type = BINKP_BLK_CMD;
@ -823,7 +823,7 @@ case BPMSG_FILE: /* File information */
DEB((D_24554, "no, skipping; TODO: accept it")); DEB((D_24554, "no, skipping; TODO: accept it"));
if( bstate->extracmd[0] != (char)-1 ) return 0; if( bstate->extracmd[0] != (char)-1 ) return 0;
bstate->extracmd[0] = BPMSG_SKIP; bstate->extracmd[0] = BPMSG_SKIP;
sprintf(bstate->extracmd+1, "%s %ld %ld %ld", recvfi.fn, recvfi.sz, recvfi.tm, recvfi.offs); sprintf(bstate->extracmd+1, "%s %zu %lu %zu", recvfi.fn, recvfi.sz, recvfi.tm, recvfi.offs);
bstate->extraislast = false; bstate->extraislast = false;
return 1; return 1;
} }

View File

@ -1053,7 +1053,7 @@ int p_rx_fopen(s_protinfo *pi, char *fn, size_t sz, time_t tm, mode_t mode)
/* /*
* Check, there is enough space in our inbound * Check, there is enough space in our inbound
*/ */
if (openmode == "a") needed_bytes_total = minfree + pi->recv->bytes_total - pi->recv->bytes_skipped; if ( strcmp(openmode, "a") == 0 ) needed_bytes_total = minfree + pi->recv->bytes_total - pi->recv->bytes_skipped;
else needed_bytes_total = minfree + pi->recv->bytes_total; else needed_bytes_total = minfree + pi->recv->bytes_total;
if( minfree > 0 && getfreespace(state.inbound) < needed_bytes_total ) if( minfree > 0 && getfreespace(state.inbound) < needed_bytes_total )

View File

@ -449,8 +449,8 @@ static int sm_rx_waitseq(s_rx_emsidat *d)
static int sm_rx_getdat(s_rx_emsidat *d) static int sm_rx_getdat(s_rx_emsidat *d)
{ {
int rc = 0; int rc = 0;
int pos = 0; u_int pos = 0;
int emsi_len = 0; u_int emsi_len = 0;
short unsigned ourcrc; short unsigned ourcrc;
short unsigned remcrc; short unsigned remcrc;
char *emsi_dat = NULL; char *emsi_dat = NULL;

View File

@ -65,7 +65,7 @@ static char *add_str(char *source, const char *add)
{ {
len += 2; len += 2;
dest = (char *)xrealloc(dest, len); dest = (char *)xrealloc(dest, len);
sprintf(&dest[pos], "\\%02hd", *(unsigned char*)add); sprintf(&dest[pos], "\\%02hhu", *(unsigned char*)add);
add += 1; add += 1;
pos += 3; pos += 3;
} }
@ -200,12 +200,12 @@ char *emsi_createdat(s_emsi *emsi)
if( emsi->compcodes.NCP ) tmp = add_str(tmp, "NCP,"); if( emsi->compcodes.NCP ) tmp = add_str(tmp, "NCP,");
} else { } else {
ord = xmalloc(4); ord = xmalloc(4);
if (ord)
{
DEB((D_HSHAKE,"Protocol order found: %s", p_order)); DEB((D_HSHAKE,"Protocol order found: %s", p_order));
ord = strncpy(ord, p_order,3); ord = strncpy(ord, p_order,3);
ord[3] = '\0'; ord[3] = '\0';
DEB((D_HSHAKE,"Protocol order chunk: %s", ord)); DEB((D_HSHAKE,"Protocol order chunk: %s", ord));
if ( ord == NULL )
DEB((D_HSHAKE,"EMSI create order error"));
if ( !strcmp(ord,"HYD") ) if ( !strcmp(ord,"HYD") )
if ( emsi->compcodes.HYD) tmp = add_str(tmp, "HYD,"); if ( emsi->compcodes.HYD) tmp = add_str(tmp, "HYD,");
if ( !strcmp(ord,"JAN") ) if ( !strcmp(ord,"JAN") )
@ -230,8 +230,6 @@ char *emsi_createdat(s_emsi *emsi)
ord = strncpy(ord, p_order,3); ord = strncpy(ord, p_order,3);
ord[3] = '\0'; ord[3] = '\0';
DEB((D_HSHAKE,"Protocol order chunk: %s", ord)); DEB((D_HSHAKE,"Protocol order chunk: %s", ord));
if ( ord == NULL )
DEB((D_HSHAKE,"EMSI create order error"));
if ( !strcmp(ord,"HYD") ) if ( !strcmp(ord,"HYD") )
if ( emsi->compcodes.HYD) tmp = add_str(tmp, "HYD,"); if ( emsi->compcodes.HYD) tmp = add_str(tmp, "HYD,");
if ( !strcmp(ord,"JAN") ) if ( !strcmp(ord,"JAN") )
@ -255,6 +253,7 @@ char *emsi_createdat(s_emsi *emsi)
} }
free(ord); free(ord);
} }
}
if( emsi->compcodes.FRQ ) tmp = add_str(tmp, "FRQ,"); if( emsi->compcodes.FRQ ) tmp = add_str(tmp, "FRQ,");
if( emsi->compcodes.NRQ ) tmp = add_str(tmp, "NRQ,"); if( emsi->compcodes.NRQ ) tmp = add_str(tmp, "NRQ,");
@ -452,7 +451,7 @@ char *emsi_createdat(s_emsi *emsi)
static char *get_field(char **str, char from, char to) static char *get_field(char **str, char from, char to)
{ {
char *dst, *src, *dest = NULL; char *dst, *src, *dest = NULL;
int ch; u_int ch;
src = *str; src = *str;
@ -722,7 +721,7 @@ int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1); if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p ) if( p && *p )
{ {
if( sscanf(p, "%08X %08X", &emsi->netmail_size, &emsi->arcmail_size) == 2 ) if( sscanf(p, "%08zX %08zX", &emsi->netmail_size, &emsi->arcmail_size) == 2 )
{ {
emsi->have_traf = 1; emsi->have_traf = 1;
} }
@ -738,7 +737,7 @@ int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
if( (p=get_field(&p, '[', ']')) == NULL ) return(1); if( (p=get_field(&p, '[', ']')) == NULL ) return(1);
if( p && *p ) if( p && *p )
{ {
if( sscanf(p, "%08X", &emsi->files_size) == 1 ) if( sscanf(p, "%08zX", &emsi->files_size) == 1 )
{ {
emsi->have_moh = 1; emsi->have_moh = 1;
} }
@ -781,6 +780,8 @@ int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
/* Parse EMSI TZUTC in fmt (+|-)HHMM */ /* Parse EMSI TZUTC in fmt (+|-)HHMM */
if( *p ) { if( *p ) {
tzc = malloc(2); tzc = malloc(2);
if (tzc)
{
DEB((D_HSHAKE, "Got TZUTC=%s for parsing", p)); DEB((D_HSHAKE, "Got TZUTC=%s for parsing", p));
tzn = sscanf( p, "%1c%02u%02u", tzc, &tzh, &tzm); tzn = sscanf( p, "%1c%02u%02u", tzc, &tzh, &tzm);
tzc[1] = '\0'; tzc[1] = '\0';
@ -798,6 +799,7 @@ int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
free(tzc); free(tzc);
} }
} }
}
else else
{ {
DEB((D_HSHAKE, "Step - no known EMSI-part - got %s", tmp)); DEB((D_HSHAKE, "Step - no known EMSI-part - got %s", tmp));

View File

@ -100,7 +100,8 @@ char *hydra_pkttype_names[] =
"HPKT_EOFACK", "HPKT_EOFACK",
"HPKT_END", "HPKT_END",
"HPKT_IDLE", "HPKT_IDLE",
"HPKT_DEVDATA" "HPKT_DEVDATA",
"HPKT_DEVDACK"
}; };
char *hydra_char_names[] = char *hydra_char_names[] =
@ -1049,8 +1050,8 @@ static int hydra_parse_init(s_hydrainfo *hi, char *pkt, size_t pktlen)
if( appinf && canopt && desopt && window && prefix ) if( appinf && canopt && desopt && window && prefix )
{ {
char buf[256]; char buf[256];
long txwindow = 0L; unsigned long txwindow = 0UL;
long rxwindow = 0L; unsigned long rxwindow = 0UL;
DEB((D_PROT, "hydra: revtime = \"%s\"", time_string_long(buf, sizeof(buf), revtime))); DEB((D_PROT, "hydra: revtime = \"%s\"", time_string_long(buf, sizeof(buf), revtime)));
DEB((D_PROT, "hydra: appinf = \"%s\"", appinf)); DEB((D_PROT, "hydra: appinf = \"%s\"", appinf));
@ -1637,7 +1638,7 @@ int hydra_batch(s_hydrainfo *hi, s_protinfo *pi)
char *p; char *p;
/* Get file modification time and size */ /* Get file modification time and size */
sscanf(hi->ibuf, "%08lx%08x%*08x%*08x%*08x", sscanf(hi->ibuf, "%08lx%08zx%*08zx%*08zx%*08zx",
(unsigned long *)&modtime, &filesize); (unsigned long *)&modtime, &filesize);
/* Convert local time -> UTC */ /* Convert local time -> UTC */

View File

@ -67,7 +67,7 @@ static const char *FrameTypes[] =
"ZCOMMAND", "ZCOMMAND",
"ZSTDERR", "ZSTDERR",
"Unused" "Unused"
#define FRTYPES 22 /* Total number of frame types in this array */ #define FRTYPES 20 /* Total number of frame types in this array */
/* not including psuedo negative entries */ /* not including psuedo negative entries */
}; };
#endif #endif

View File

@ -548,7 +548,7 @@ static int zmodem_proc_ZFILE(s_protinfo *pi, char *blkptr, size_t blklen)
fileiptr = blkptr + strlen(blkptr) + 1; fileiptr = blkptr + strlen(blkptr) + 1;
if( fileiptr >= (blkptr + blklen) || if( fileiptr >= (blkptr + blklen) ||
sscanf(fileiptr, "%d%lo", &filesize, (unsigned long *)&filetime) < 1 ) sscanf(fileiptr, "%zu%lo", &filesize, (unsigned long *)&filetime) < 1 )
{ {
log("zmodem: got invalid ZFILE packet"); log("zmodem: got invalid ZFILE packet");
return 1; return 1;

View File

@ -47,14 +47,18 @@ static void zmodem_add_empty_packet(s_protinfo *pi)
s_filelist **ptrl; s_filelist **ptrl;
s_packet pkt; s_packet pkt;
char tmpname[] = "/tmp/bfXXXXXX"; char tmpname[] = "/tmp/bfXXXXXX";
char *chunk;
char *p_tmpname; char *p_tmpname;
if( (p_tmpname = mktemp(tmpname)) == NULL ) chunk = xmalloc(7);
{ if (!chunk) {
logerr("cannot generate temp. file name for packet from \"%s\"", tmpname); logerr("cannot generate temp. file name for packet");
return; return;
} }
getrandname(chunk, 6);
p_tmpname = string_concat("/tmp/bf", chunk, '\0');
free(chunk);
memset(&pkt, '\0', sizeof(s_packet)); memset(&pkt, '\0', sizeof(s_packet));
pkt.dest = state.node.addr; pkt.dest = state.node.addr;

View File

@ -519,7 +519,7 @@ case CALL_TCPIP_TELNET:
state.session = SESSION_UNKNOWN; state.session = SESSION_UNKNOWN;
target = xstrcpy("ITN"); target = xstrcpy("ITN");
break; break;
defalt: default:
log("invalid protocol for TCP/IP module"); log("invalid protocol for TCP/IP module");
return BFERR_FATALERROR; return BFERR_FATALERROR;
} }
@ -536,7 +536,7 @@ defalt:
if ( ! resflg ) if ( ! resflg )
{ {
char *p = string_casestr(pbuf, target); const char *p = string_casestr(pbuf, target);
if ( p ) if ( p )
{ {

View File

@ -58,11 +58,11 @@ static char *session_stat_get_stsfile(s_faddr *addr, int linenum)
addr->zone, addr->net, addr->zone, addr->net,
addr->node, addr->point); addr->node, addr->point);
else else
sprintf(buf, "%u.%u.%u.%u-%u.sts", sprintf(buf, "%u.%u.%u.%u-%d.sts",
addr->zone, addr->net, addr->zone, addr->net,
addr->node, addr->point, linenum); addr->node, addr->point, linenum);
yield = string_concat(p_stsdir, buf, NULL); yield = string_concat(p_stsdir, buf, '\0');
} }
return yield; return yield;

View File

@ -109,6 +109,22 @@ int file_lock_wait(FILE *fp, bool exclusive)
return -1; return -1;
} }
void getrandname(char * buf, u_int size)
{
srand((unsigned int)time(NULL));
char c;
int i;
for (i = 0; i<size; i++)
{
c = rand();
// Only ASCII 0..9A..Z
while ( (c > 90) || (c < 48) || ( ( c > 57) && ( c < 65 ) ) )
c = rand();
buf[i] = c;
}
buf[size]='\0';
}
bool file_name_issafe(int ch) bool file_name_issafe(int ch)
{ {
if( ch == '!' ) return TRUE; if( ch == '!' ) return TRUE;
@ -151,12 +167,22 @@ char *file_getname(char *filename)
char *file_gettmp(void) char *file_gettmp(void)
{ {
char *tmp = xstrcpy("/tmp/bforce-XXXXXX"); char *chunk = xmalloc(7);
char *res = mktemp(tmp); char *res = NULL;
if (chunk)
{
getrandname(chunk,6);
chunk[6] = '\0';
char *tmp = xstrcpy("/tmp/bforce-");
res = string_concat(tmp, chunk, '\0');
if( chunk )
free(chunk);
if( !res ) if( !res )
free(tmp); free(tmp);
}
return res; return res;
} }

View File

@ -152,7 +152,13 @@ int plock_link(const char *lockname, const char *tmpname)
int plock_create(const char *lockname) int plock_create(const char *lockname)
{ {
int rc; int rc;
char *tmpname, *p; char *tmpname, *p, *chunk;
chunk = xmalloc(7);
if (!chunk) {
logerr("can't generate unique file name from \"%s\"", tmpname);
DEB((D_FREE, "plock freed"));
return PLOCK_ERROR;
}
ASSERT(lockname != NULL); ASSERT(lockname != NULL);
@ -166,16 +172,10 @@ int plock_create(const char *lockname)
DEB((D_FREE, "plock freed")); DEB((D_FREE, "plock freed"));
return PLOCK_ERROR; return PLOCK_ERROR;
} }
tmpname = xstrcat(tmpname, "bforce-XXXXXX"); tmpname = xstrcat(tmpname, "bforce-");
if( (p = mktemp(tmpname)) == NULL ) getrandname(chunk,6);
{ p = string_concat(tmpname,chunk,'\0');
logerr("can't generate unique file name from \"%s\"", tmpname);
DEB((D_FREE, "plock free"));
free(tmpname);
DEB((D_FREE, "plock freed"));
return PLOCK_ERROR;
}
if( (rc = plock_write(p)) == PLOCK_OK ) if( (rc = plock_write(p)) == PLOCK_OK )
rc = plock_link(lockname, p); rc = plock_link(lockname, p);

View File

@ -46,10 +46,10 @@ enum day
typedef struct faddr { typedef struct faddr {
bool inetform; /* Is address in domain form? */ bool inetform; /* Is address in domain form? */
int zone; /* -1 value means any?! */ u_int zone; /* -1 value means any?! */
int net; u_int net;
int node; u_int node;
int point; u_int point;
char domain[BF_MAXDOMAIN+1]; char domain[BF_MAXDOMAIN+1];
} s_faddr; } s_faddr;
@ -83,7 +83,7 @@ typedef struct message {
typedef struct packet { typedef struct packet {
s_faddr orig; s_faddr orig;
s_faddr dest; s_faddr dest;
int baud; u_int baud;
char password[8+1]; char password[8+1];
s_message *msgs; s_message *msgs;
int n_msgs; int n_msgs;
@ -161,6 +161,7 @@ bool is_regfile(const char *filename);
int directory_create(const char *dirname, mode_t access_mode); int directory_create(const char *dirname, mode_t access_mode);
FILE *file_open(const char *path, const char *mode); FILE *file_open(const char *path, const char *mode);
int file_close(FILE *stream); int file_close(FILE *stream);
void getrandname(char * buf, u_int size);
/* u_ftn.c */ /* u_ftn.c */
int ftn_addrparse(s_faddr *addr, const char *s, bool wildcard); int ftn_addrparse(s_faddr *addr, const char *s, bool wildcard);

View File

@ -6,7 +6,7 @@ proto_order %PROTO%
#domain schoolnet /var/spool/ftn/schoolnet/ 461 #domain schoolnet /var/spool/ftn/schoolnet/ 461
log_file %TESTZONE%/logsA/bf-log log_file %TESTZONE%/logsA/bf-log
debug_file %TESTZONE%/logsA/bf-debug debug_file %TESTZONE%/logsA/bf-debug
debug_level info modem hshake event prot override debug_level info modem hshake event prot outbound override
nodial_flag %TESTZONE%/etc/nodial nodial_flag %TESTZONE%/etc/nodial
inbound_directory (Protected) %TESTZONE%/inboundA inbound_directory (Protected) %TESTZONE%/inboundA
inbound_directory %TESTZONE%/inbound-unsecureA inbound_directory %TESTZONE%/inbound-unsecureA

View File

@ -6,7 +6,7 @@ proto_order %PROTO%
#domain schoolnet /var/spool/ftn/schoolnet/ 461 #domain schoolnet /var/spool/ftn/schoolnet/ 461
log_file %TESTZONE%/logsB/bf-log log_file %TESTZONE%/logsB/bf-log
debug_file %TESTZONE%/logsB/bf-debug debug_file %TESTZONE%/logsB/bf-debug
debug_level info modem hshake event prot override debug_level info modem hshake event prot outbound override
nodial_flag %TESTZONE%/etc/nodial nodial_flag %TESTZONE%/etc/nodial
inbound_directory (Protected) %TESTZONE%/inboundB inbound_directory (Protected) %TESTZONE%/inboundB
inbound_directory %TESTZONE%/inbound-unsecureB inbound_directory %TESTZONE%/inbound-unsecureB