EBADMSG
Linux / POSIXERRORNotableIPCHIGH confidence

Bad Message

Production Risk

Indicates message format mismatch in STREAMS or IPC.

What this means

EBADMSG (errno 74) is returned when a message has an invalid format. Common in STREAMS, some ioctls, and message-passing APIs. Also used by some syscalls when a malformed message is received.

Why it happens
  1. 1STREAMS message does not match expected format
  2. 2Corrupted message received from remote peer
  3. 3getmsg() reading an M_PROTO message when expecting M_DATA
How to reproduce

getmsg() reads a control message when caller expects data.

trigger — this will error
trigger — this will error
struct strbuf ctrl = {0}, data = {0};
int flags = MSG_ANY;
// Receives control message when expecting data
getmsg(fd, &ctrl, &data, &flags);
// Returns -1, errno = EBADMSG if message type unexpected

expected output

getmsg: Bad message (EBADMSG)

Fix

Accept both message types

WHEN When using STREAMS getmsg()

Accept both message types
// Accept any message type
int flags = 0;  // 0 accepts any type
int rc = getmsg(fd, &ctrl, &data, &flags);
// Check flags after to determine what was received

Why this works

Setting flags to 0 accepts any STREAMS message type; inspect the returned flags to determine message type.

Sources
Official documentation ↗

Linux Programmer Manual errno(3)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors