Skip to content

fix(netpacket): Fix misplaced null test in NetPacket::addCommand()#2272

Merged
xezon merged 1 commit intoTheSuperHackers:mainfrom
xezon:xezon/fix-netpacket-addcommand
Feb 8, 2026
Merged

fix(netpacket): Fix misplaced null test in NetPacket::addCommand()#2272
xezon merged 1 commit intoTheSuperHackers:mainfrom
xezon:xezon/fix-netpacket-addcommand

Conversation

@xezon
Copy link

@xezon xezon commented Feb 8, 2026

This change fixes a misplaced null test in NetPacket::addCommand().

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Fix Is fixing something, but is not user facing labels Feb 8, 2026
@greptile-apps
Copy link

greptile-apps bot commented Feb 8, 2026

Greptile Overview

Greptile Summary

This PR fixes a crash bug in NetPacket::addCommand(NetCommandRef* msg) by moving the msg == nullptr guard before the first dereference (msg->getCommand()). With this change, callers can pass a null msg and the function will return success (TRUE) without accessing invalid memory.

The change is localized to the networking packet assembly path in Core/GameEngine/Source/GameNetwork/NetPacket.cpp and does not alter the command dispatch logic beyond preventing the null-pointer dereference.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • The change is a minimal, correctness-only fix that prevents a definite null-pointer dereference by moving an existing null check before the first use of msg. No control-flow or data-format behavior changes occur beyond early-returning for null input, and the patch is confined to a single function.
  • No files require special attention

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameNetwork/NetPacket.cpp Moves msg null-check before dereferencing in NetPacket::addCommand(), preventing a null pointer deref.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant NetPacket
  participant NetCommandRef
  participant NetCommandMsg

  Caller->>NetPacket: addCommand(msg)
  alt msg == nullptr
    NetPacket-->>Caller: return TRUE
  else msg != nullptr
    NetPacket->>NetCommandRef: getCommand()
    NetCommandRef-->>NetPacket: cmdMsg
    NetPacket->>NetCommandMsg: getNetCommandType()
    NetCommandMsg-->>NetPacket: type
    NetPacket-->>Caller: handle type in switch
  end

Loading

@xezon xezon merged commit 8536a29 into TheSuperHackers:main Feb 8, 2026
24 checks passed
@xezon xezon deleted the xezon/fix-netpacket-addcommand branch February 8, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants