From ecce2a8a402e7330486bf423d604a908aec86475 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Wed, 2 Mar 2022 13:38:46 -0800 Subject: [PATCH] Detect smb_fallocdat() and ftell() failures CID 33245 --- src/sbbs3/smbutil.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/sbbs3/smbutil.c b/src/sbbs3/smbutil.c index b8d123adda..8153f72cd4 100644 --- a/src/sbbs3/smbutil.c +++ b/src/sbbs3/smbutil.c @@ -1196,16 +1196,26 @@ void packmsgs(ulong packable) continue; } + off_t offset; if(!(smb.status.attr&SMB_HYPERALLOC)) { - msg.hdr.offset = (uint32_t)smb_fallocdat(&smb,(uint32_t)m,1); - datoffset[datoffsets].new = msg.hdr.offset; + offset = smb_fallocdat(&smb,(uint32_t)m,1); + if(offset < 0) { + fprintf(errfp,"\n%s!Data allocation failure: %ld\n", beep, (long)offset); + continue; + } + datoffset[datoffsets].new = (uint32_t)offset; datoffsets++; - fseek(tmp_sdt,msg.hdr.offset,SEEK_SET); + fseeko(tmp_sdt, offset, SEEK_SET); } else { fseek(tmp_sdt,0L,SEEK_END); - msg.hdr.offset=ftell(tmp_sdt); + offset=ftell(tmp_sdt); + if(offset < 0) { + fprintf(errfp,"\n%s!ftell() ERROR %d\n", beep, errno); + continue; + } } + msg.hdr.offset = (uint32_t)offset; /* Actually copy the data */ -- GitLab