Skip to content

fix: initialize msg to NULL in rcon_receive to avoid UB#259

Open
jmallach wants to merge 1 commit into
XQF:masterfrom
jmallach:fix-rcon-uninitialized-msg
Open

fix: initialize msg to NULL in rcon_receive to avoid UB#259
jmallach wants to merge 1 commit into
XQF:masterfrom
jmallach:fix-rcon-uninitialized-msg

Conversation

@jmallach

Copy link
Copy Markdown
Contributor

In rcon_receive(), msg is declared but not initialized. There are two code paths that can leave it indeterminate before it is passed to msg_terminate():

  1. DOOM3/Q4 branch: when the received packet has size <= 2+6+4+1 (i.e. the payload is too short to contain a useful message), the if body that would assign msg is skipped entirely.

  2. HW_SERVER branch: when size > PACKET_MAXSIZE the switch breaks out without setting msg.

msg_terminate() guards against NULL (if (!msg || size <= 0) return g_strdup("\n")), so setting msg = NULL makes both paths safe and well-defined.

Assisted-By: Claude Sonnet 4.6 noreply@anthropic.com

In rcon_receive(), `msg` is declared but not initialized. There are two
code paths that can leave it indeterminate before it is passed to
msg_terminate():

1. DOOM3/Q4 branch: when the received packet has size <= 2+6+4+1 (i.e.
   the payload is too short to contain a useful message), the `if` body
   that would assign `msg` is skipped entirely.

2. HW_SERVER branch: when size > PACKET_MAXSIZE the switch breaks out
   without setting `msg`.

msg_terminate() guards against NULL (`if (!msg || size <= 0) return
g_strdup("\n")`), so setting `msg = NULL` makes both paths safe and
well-defined.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@jmallach
jmallach force-pushed the fix-rcon-uninitialized-msg branch from 62bda44 to e64521b Compare July 11, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant