Skip to content

Commit

Permalink
make sure async flag is set for pending status replies
Browse files Browse the repository at this point in the history
  • Loading branch information
bdodge authored and sahlberg committed Dec 27, 2024
1 parent cb73676 commit 935d3c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lib/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ smb2_free_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu)
if (pdu->free_payload != NULL) {
pdu->free_payload(smb2, pdu->payload);
}

free(pdu->payload);
free(pdu->crypt);
free(pdu);
Expand Down Expand Up @@ -584,9 +584,6 @@ smb2_correlate_reply(struct smb2_context *smb2, struct smb2_pdu *pdu)
struct smb2_pdu *req_pdu;
int ret = 0;

/* set reply flag */
pdu->header.flags |= SMB2_FLAGS_SERVER_TO_REDIR;

req_pdu = smb2_find_pdu_by_command(smb2, pdu->header.command);
if (req_pdu == NULL) {
if (pdu->header.command != SMB2_OPLOCK_BREAK) {
Expand All @@ -601,8 +598,6 @@ smb2_correlate_reply(struct smb2_context *smb2, struct smb2_pdu *pdu)
pdu->header.session_id = 0;
}
} else {
SMB2_LIST_REMOVE(&smb2->waitqueue, req_pdu);

pdu->header.credit_request_response =
64 + req_pdu->header.credit_charge;

Expand All @@ -615,7 +610,12 @@ smb2_correlate_reply(struct smb2_context *smb2, struct smb2_pdu *pdu)
if (pdu->header.command != SMB2_TREE_CONNECT) {
pdu->header.sync.tree_id = req_pdu->header.sync.tree_id;
}
smb2_free_pdu(smb2, req_pdu);

/* leave pdu in waitqueue if this is an async reply */
if (!(pdu->header.flags & SMB2_FLAGS_ASYNC_COMMAND)) {
SMB2_LIST_REMOVE(&smb2->waitqueue, req_pdu);
smb2_free_pdu(smb2, req_pdu);
}
}
return ret;
}
Expand All @@ -628,10 +628,15 @@ smb2_queue_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu)
/* Update all the PDU headers in this chain */
for (p = pdu; p; p = p->next_compound) {
if (smb2_is_server(smb2)) {
if (!(pdu->header.flags & SMB2_FLAGS_ASYNC_COMMAND)) {
smb2_correlate_reply(smb2, p);
/* TODO - care about check reply failures? */
/* set reply flag, servers will only reply */
pdu->header.flags |= SMB2_FLAGS_SERVER_TO_REDIR;

/* set async flag for status==pending */
if (pdu->header.status == SMB2_STATUS_PENDING) {
pdu->header.flags |= SMB2_FLAGS_ASYNC_COMMAND;
}
smb2_correlate_reply(smb2, p);
/* TODO - care about check reply failures? */
}
smb2_encode_header(smb2, &p->out.iov[0], &p->header);
if (smb2->sign ||
Expand Down
4 changes: 3 additions & 1 deletion lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,9 @@ static int smb2_read_data(struct smb2_context *smb2, read_func func,
pdu = smb2_find_pdu(smb2, smb2->hdr.message_id);
if (pdu == NULL) {
smb2_set_error(smb2, "no matching PDU found");
return -1;
/* ignore this error for now, it might be OK
* to not pass the pending reply along */
/*return -1;*/
}
else
{
Expand Down

0 comments on commit 935d3c9

Please sign in to comment.