Skip to content

Commit

Permalink
mctpd: fix return value check in control socket reads
Browse files Browse the repository at this point in the history
Currently, we're checking the return value of read_message against 0 to
detect EOF, but this isn't a length value. This means that any
successful read will hit the errx.

Instead, check the actual length, and improve the read_message case
where we see an EOF from the recvmsg().

Fixes: ea5c9a3 ("mctpd: Exit on control socket EOF")
Signed-off-by: Jeremy Kerr <[email protected]>
  • Loading branch information
jk-ozlabs committed Jun 26, 2024
1 parent 69ed224 commit 6a924ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
pre-configured EID that would conflict with other (already enumerated)
endpoints. The new endpoint will get a non-conflicting address assigned.

2. mctpd: fix incorrect error detection on control socket reads

## [1.1] - 2023-04-13
9 changes: 8 additions & 1 deletion src/mctpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ static int read_message(ctx *ctx, int sd, uint8_t **ret_buf, size_t *ret_buf_siz
goto out;
}

if (len == 0) {
*ret_buf = NULL;
*ret_buf_size = 0;
rc = 0;
goto out;
}

buf_size = len;
buf = malloc(buf_size);
if (!buf) {
Expand Down Expand Up @@ -721,7 +728,7 @@ static int cb_listen_control_msg(sd_event_source *s, int sd, uint32_t revents,
if (rc < 0)
goto out;

if (rc == 0)
if (buf_size == 0)
errx(EXIT_FAILURE, "Control socket returned EOF");

if (addr.smctp_base.smctp_type != MCTP_CTRL_HDR_MSG_TYPE) {
Expand Down

0 comments on commit 6a924ad

Please sign in to comment.