Skip to content

Commit

Permalink
[PATCH] Check that there is actually a callback when reporting errors
Browse files Browse the repository at this point in the history
If the PDU belonged to a server replying there would be no callback set
and the application will crash with a segfault if we make the call without
checking the value first.

From: David Galeano Corrales <[email protected]>
Signed-off-by: Ronnie Sahlberg <[email protected]>
  • Loading branch information
sahlberg committed Aug 15, 2024
1 parent 28ad33a commit e6065ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ static void rpc_purge_all_pdus(struct rpc_context *rpc, int status, const char *
while ((pdu = outqueue.head) != NULL) {
outqueue.head = pdu->next;
pdu->next = NULL;
pdu->cb(rpc, status, (void *) error, pdu->private_data);
if (pdu->cb) {
pdu->cb(rpc, status, (void *) error, pdu->private_data);
}
rpc_free_pdu(rpc, pdu);
}
#ifdef HAVE_MULTITHREADING
Expand All @@ -450,7 +452,9 @@ static void rpc_purge_all_pdus(struct rpc_context *rpc, int status, const char *
while((pdu = waitqueue.head) != NULL) {
waitqueue.head = pdu->next;
pdu->next = NULL;
pdu->cb(rpc, status, (void *) error, pdu->private_data);
if (pdu->cb) {
pdu->cb(rpc, status, (void *) error, pdu->private_data);
}
rpc_free_pdu(rpc, pdu);
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,10 @@ rpc_timeout_scan(struct rpc_context *rpc)
rpc->outqueue.tail = NULL; //done
}
rpc_set_error_locked(rpc, "command timed out");
pdu->cb(rpc, RPC_STATUS_TIMEOUT,
NULL, pdu->private_data);
if (pdu->cb) {
pdu->cb(rpc, RPC_STATUS_TIMEOUT,
NULL, pdu->private_data);
}
rpc_free_pdu(rpc, pdu);
}
}
Expand Down Expand Up @@ -1074,8 +1076,10 @@ rpc_timeout_scan(struct rpc_context *rpc)
// qqq move to a temporary queue and process after
// we drop the mutex
rpc_set_error_locked(rpc, "command timed out");
pdu->cb(rpc, RPC_STATUS_TIMEOUT,
NULL, pdu->private_data);
if (pdu->cb) {
pdu->cb(rpc, RPC_STATUS_TIMEOUT,
NULL, pdu->private_data);
}
rpc_free_pdu(rpc, pdu);
}
}
Expand Down

0 comments on commit e6065ce

Please sign in to comment.