Skip to content

Commit 3506e7d

Browse files
committed
netlink: Fix NL_OP_COUNT definition, add debug for CHANGE_NAME
Commit 1b6c367 ("mctp-netlink: add MCTP_NL_CHANGE_NAME event") did not update the COUNT definition, so causing a potential array index overrun on change dump. Instead of hard-coding, use the enum itself for the count value, and add a dump string for the new CHANGE_NAME event type. Fixes: 1b6c367 ("mctp-netlink: add MCTP_NL_CHANGE_NAME event") Fixes: #120 Reported-by: Nidhin MS <[email protected]> Signed-off-by: Jeremy Kerr <[email protected]>
1 parent e9988db commit 3506e7d

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313

1414
2. Header compatibility fixes for environments without a recent linux/mctp.h
1515

16+
3. Fixed a potential array overrun when dumping netlink change events
17+
1618
## Added
1719

1820
1. `mctp-bench` now supports a "request receive" mode, where

src/mctp-netlink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ void mctp_nl_changes_dump(mctp_nl *nl, mctp_nl_change *changes,
345345
size_t num_changes)
346346
{
347347
const char *ops[MCTP_NL_OP_COUNT] = {
348-
"ADD_LINK", "DEL_LINK", "CHANGE_NET",
349-
"CHANGE_UP", "ADD_EID", "DEL_EID",
348+
"ADD_LINK", "DEL_LINK", "CHANGE_NET", "CHANGE_UP",
349+
"CHANGE_NAME", "ADD_EID", "DEL_EID",
350350
};
351351

352352
fprintf(stderr, "%zu changes:\n", num_changes);

src/mctp-netlink.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct mctp_nl;
1313
typedef struct mctp_nl mctp_nl;
1414

1515
struct mctp_nl_change {
16-
#define MCTP_NL_OP_COUNT 6
16+
#define MCTP_NL_OP_COUNT __MCTP_NL_OP_MAX
1717
enum {
1818
MCTP_NL_ADD_LINK,
1919
MCTP_NL_DEL_LINK,
@@ -22,6 +22,7 @@ struct mctp_nl_change {
2222
MCTP_NL_CHANGE_NAME,
2323
MCTP_NL_ADD_EID,
2424
MCTP_NL_DEL_EID,
25+
__MCTP_NL_OP_MAX,
2526
} op;
2627

2728
int ifindex;

src/mctpd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,8 @@ static int cb_listen_monitor(sd_event_source *s, int sd, uint32_t revents,
13611361
// 'up' state is currently unused
13621362
break;
13631363
}
1364+
default:
1365+
bug_warn("Unhandled netlink change type %d", c->op);
13641366
}
13651367
}
13661368

0 commit comments

Comments
 (0)