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

Fix the relocation of enlarged message headers in smb_putmsghdr()

The first commit of this feature would leave the base corrupted for a couple
of reasons (.sha file wasn't opened, using modified header when re-writing the
old header to set the DELETED attribute). Both fixed.
parent de41e1b7
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4255 passed
...@@ -1922,23 +1922,28 @@ int smb_putmsghdr(smb_t* smb, smbmsg_t* msg) ...@@ -1922,23 +1922,28 @@ int smb_putmsghdr(smb_t* smb, smbmsg_t* msg)
return(SMB_ERR_HDR_LEN); return(SMB_ERR_HDR_LEN);
} }
if(smb_hdrblocks(hdrlen) > smb_hdrblocks(msg->hdr.length)) { if(smb_hdrblocks(hdrlen) > smb_hdrblocks(msg->hdr.length)) {
off_t offset = msg->idx.offset; smbmsg_t old_msg = *msg;
int result = smb_new_msghdr(smb, msg, (smb->status.attr&SMB_HYPERALLOC) ? SMB_HYPERALLOC : SMB_SELFPACK, FALSE); int result = smb_new_msghdr(smb, msg, (smb->status.attr&SMB_HYPERALLOC) ? SMB_HYPERALLOC : SMB_SELFPACK, FALSE);
if(result != SMB_SUCCESS) if(result != SMB_SUCCESS)
return result; return result;
if(fseeko(smb->shd_fp, offset, SEEK_SET) != 0) { if(fseeko(smb->shd_fp, old_msg.idx.offset, SEEK_SET) != 0) {
safe_snprintf(smb->last_error,sizeof(smb->last_error) safe_snprintf(smb->last_error,sizeof(smb->last_error)
,"%s %d '%s' seeking to %u in header file (to delete)", __FUNCTION__ ,"%s %d '%s' seeking to %u in header file (to delete)", __FUNCTION__
,get_errno(),STRERROR(get_errno()), (uint)msg->idx.offset); ,get_errno(),STRERROR(get_errno()), (uint)msg->idx.offset);
return(SMB_ERR_SEEK); return(SMB_ERR_SEEK);
} }
msg->hdr.attr |= MSG_DELETE; old_msg.hdr.attr |= MSG_DELETE;
if(fwrite(&msg->hdr, sizeof(msg->hdr), 1, smb->shd_fp) != 1) { if(fwrite(&old_msg.hdr, sizeof(old_msg.hdr), 1, smb->shd_fp) != 1) {
safe_snprintf(smb->last_error,sizeof(smb->last_error) safe_snprintf(smb->last_error,sizeof(smb->last_error)
,"%s writing fixed portion of header record (to delete)", __FUNCTION__); ,"%s writing fixed portion of header record (to delete)", __FUNCTION__);
return(SMB_ERR_WRITE); return(SMB_ERR_WRITE);
} }
return smb_freemsghdr(smb, msg->idx.offset-smb->status.header_offset, msg->hdr.length); if((smb->status.attr&SMB_HYPERALLOC) == 0 && (result = smb_open_ha(smb)) != SMB_SUCCESS)
return result;
result = smb_freemsghdr(smb, old_msg.idx.offset - smb->status.header_offset, old_msg.hdr.length);
if((smb->status.attr&SMB_HYPERALLOC) == 0)
smb_close_ha(smb);
return result;
} }
msg->hdr.length=(uint16_t)hdrlen; /* store the actual header length */ msg->hdr.length=(uint16_t)hdrlen; /* store the actual header length */
/**********************************/ /**********************************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment