Skip to content
Snippets Groups Projects
Commit bcb7baf0 authored by rswindell's avatar rswindell
Browse files

Bugfix: smb_addcrc() no longer tries to malloc or read the CRC history file if

the length is 0.
smb_addcrc() now verifies the file is evenly divisible by 4 bytes (the size of
a 32-bit CRC record).
parent cd4c3e28
No related branches found
No related tags found
No related merge requests found
...@@ -1248,12 +1248,13 @@ int SMBCALL smb_addcrc(smb_t* smb, ulong crc) ...@@ -1248,12 +1248,13 @@ int SMBCALL smb_addcrc(smb_t* smb, ulong crc)
} }
length=filelength(file); length=filelength(file);
if(length<0L) { if(length<0L || length%sizeof(long)) {
close(file); close(file);
sprintf(smb->last_error,"invalid file length: %ld", length); sprintf(smb->last_error,"invalid file length: %ld", length);
return(SMB_ERR_FILE_LEN); return(SMB_ERR_FILE_LEN);
} }
if(length!=0) {
if((buf=(ulong*)MALLOC(length))==NULL) { if((buf=(ulong*)MALLOC(length))==NULL) {
close(file); close(file);
sprintf(smb->last_error sprintf(smb->last_error
...@@ -1288,8 +1289,9 @@ int SMBCALL smb_addcrc(smb_t* smb, ulong crc) ...@@ -1288,8 +1289,9 @@ int SMBCALL smb_addcrc(smb_t* smb, ulong crc)
lseek(file,0L,SEEK_SET); lseek(file,0L,SEEK_SET);
write(file,buf+(length-newlen),newlen); write(file,buf+(length-newlen),newlen);
} }
wr=write(file,&crc,sizeof(crc)); /* Write to the end */
FREE(buf); FREE(buf);
}
wr=write(file,&crc,sizeof(crc)); /* Write to the end */
close(file); close(file);
if(wr!=sizeof(crc)) { if(wr!=sizeof(crc)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment