Skip to content
Snippets Groups Projects
Commit ac811ab2 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Safer string handling

e.g. CID 33631: Unbounded source buffer
parent 3ab210cb
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
/* Utility to create list of files from Synchronet file directories */ /* Utility to create list of files from Synchronet file directories */
/* DEPRECATED: use filelist.js instead */
/* Default list format is FILES.BBS, but file size, uploader, upload date */ /* Default list format is FILES.BBS, but file size, uploader, upload date */
/* and other information can be included. */ /* and other information can be included. */
...@@ -55,31 +57,18 @@ int lprintf(int level, const char *fmat, ...) ...@@ -55,31 +57,18 @@ int lprintf(int level, const char *fmat, ...)
return(chcount); return(chcount);
} }
void stripctrlz(char *str)
{
char tmp[1024];
int i,j,k;
k=strlen(str);
for(i=j=0;i<k;i++)
if(str[i]!=0x1a)
tmp[j++]=str[i];
tmp[j]=0;
strcpy(str,tmp);
}
char* byteStr(unsigned long value) char* byteStr(unsigned long value)
{ {
static char tmp[128]; static char tmp[128];
if(value>=(1024*1024*1024)) if(value>=(1024*1024*1024))
sprintf(tmp, "%5.1fG", value/(1024.0*1024.0*1024.0)); SAFEPRINTF(tmp, "%5.1fG", value/(1024.0*1024.0*1024.0));
else if(value>=(1024*1024)) else if(value>=(1024*1024))
sprintf(tmp, "%5.1fM", value/(1024.0*1024.0)); SAFEPRINTF(tmp, "%5.1fM", value/(1024.0*1024.0));
else if(value>=1024) else if(value>=1024)
sprintf(tmp, "%5.1fK", value/1024.0); SAFEPRINTF(tmp, "%5.1fK", value/1024.0);
else else
sprintf(tmp, "%5luB", value); SAFEPRINTF(tmp, "%5luB", value);
return tmp; return tmp;
} }
...@@ -234,7 +223,8 @@ int main(int argc, char **argv) ...@@ -234,7 +223,8 @@ int main(int argc, char **argv)
printf("\nDirectory internal code must follow -not parameter.\n"); printf("\nDirectory internal code must follow -not parameter.\n");
exit(1); exit(1);
} }
sprintf(not[nots++],"%.8s",argv[i]); SAFECOPY(not[nots], argv[i]);
nots++;
} }
else if(!stricmp(argv[i],"-all")) { else if(!stricmp(argv[i],"-all")) {
if(dirnum!=-1) { if(dirnum!=-1) {
...@@ -343,14 +333,14 @@ int main(int argc, char **argv) ...@@ -343,14 +333,14 @@ int main(int argc, char **argv)
,/* filespec: */pattern, /* time: */t, file_detail_extdesc, scfg.dir[i]->sort, &file_count); ,/* filespec: */pattern, /* time: */t, file_detail_extdesc, scfg.dir[i]->sort, &file_count);
if(misc&AUTO) { if(misc&AUTO) {
sprintf(str,"%sFILES.BBS",scfg.dir[i]->path); SAFEPRINTF(str,"%sFILES.BBS",scfg.dir[i]->path);
if((out=fopen(str, omode)) == NULL) { if((out=fopen(str, omode)) == NULL) {
perror(str); perror(str);
exit(1); exit(1);
} }
} }
if(misc&HDR) { if(misc&HDR) {
sprintf(fname,"%-*s %-*s Files: %4lu" safe_snprintf(fname, sizeof(fname), "%-*s %-*s Files: %4lu"
,LEN_GSNAME,scfg.lib[scfg.dir[i]->lib]->sname ,LEN_GSNAME,scfg.lib[scfg.dir[i]->lib]->sname
,LEN_SLNAME,scfg.dir[i]->lname, (ulong)smb.status.total_files); ,LEN_SLNAME,scfg.dir[i]->lname, (ulong)smb.status.total_files);
fprintf(out,"%s\n",fname); fprintf(out,"%s\n",fname);
...@@ -400,7 +390,7 @@ int main(int argc, char **argv) ...@@ -400,7 +390,7 @@ int main(int argc, char **argv)
} }
if(misc&MINUS) { if(misc&MINUS) {
sprintf(str,"%s%s",scfg.dir[i]->path,file.name); SAFEPRINTF2(str,"%s%s",scfg.dir[i]->path,file.name);
if(!fexistcase(str)) if(!fexistcase(str))
fputc('-',out); fputc('-',out);
else else
...@@ -411,8 +401,7 @@ int main(int argc, char **argv) ...@@ -411,8 +401,7 @@ int main(int argc, char **argv)
desc_off++; desc_off++;
if(misc&DFD) { if(misc&DFD) {
// TODO: Fix to support alt-file-paths: SAFEPRINTF2(str,"%s%s",scfg.dir[i]->path,file.name);
sprintf(str,"%s%s",scfg.dir[i]->path,file.name);
desc_off += fprintf(out,"%s ",unixtodstr(&scfg,(time32_t)fdate(str),str)); desc_off += fprintf(out,"%s ",unixtodstr(&scfg,(time32_t)fdate(str),str));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment