Skip to content

Conversation

@Mauller
Copy link

@Mauller Mauller commented Dec 5, 2025

This PR prevents the ability to perform an out of bounds memory access using a well crafted wrapped command.

The Wrapped commands are designed to chunk up a larger data packet, so files can be transfered to another machine such as a map.

This PR adds checks to make sure the chunked data makes sense and fits within the bounds of the allocated memory.

@Mauller Mauller self-assigned this Dec 5, 2025
@Mauller Mauller added Bug Something is not working right, typically is user facing Critical Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Gen Relates to Generals ZH Relates to Zero Hour labels Dec 5, 2025
UnsignedShort m_commandID;
UnsignedByte *m_data;
UnsignedInt m_dataLength;
UnsignedInt m_totalDataLength;
Copy link
Author

@Mauller Mauller Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I altered this for sanity reasons as the original name can get confusing when the data length of the data chunk is also being considered.

I did consider further refactoring the NetWrapperCommandMsg but chose to revert those changes for now as they were touching NetPacket which has some waiting PR's to be merged

m_dataLength = msg->getTotalDataLength();
m_data = NEW UnsignedByte[m_dataLength]; // pool[]ify
m_totalDataLength = msg->getTotalDataLength();
m_data = NEW UnsignedByte[m_totalDataLength]; // pool[]ify
Copy link
Author

@Mauller Mauller Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering if we might want to also validate the total data length, since we can't allocate MAX_UINT of memory for example in a 32bit application.

If there is not a limit considered in the game already, then we should consider something sensible for a single transfer.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a transfer size cap does make sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's a matter of determining what we would consider our max, the game is still not large address aware so limited to 2/2.5GB of RAM at the moment.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 MB would be a reasonable limit for starters I think. But better be a separate change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, leave it for a followup.

@Mauller Mauller added this to the Major bug fixes milestone Dec 5, 2025
@Mauller Mauller added the Security Is security related label Dec 5, 2025
@Mauller Mauller force-pushed the Mauller/fix-filewrapperlist-security branch 2 times, most recently from 3d36e1d to 2fe28a3 Compare December 5, 2025 20:37
@Mauller
Copy link
Author

Mauller commented Dec 5, 2025

One thing this transfer mechanism lacks is a way to signal up that there was a problem with the transfer and that it needs to be cancelled.

I think the game has a timeout on the transfer screen of 5 minutes but is always good to be able to signal a problem. But a refactor for that would be more considerable and better done when we do some bigger refactoring of netcode.

@Mauller Mauller force-pushed the Mauller/fix-filewrapperlist-security branch from 2fe28a3 to 1e5ab7f Compare December 5, 2025 21:35
@Mauller
Copy link
Author

Mauller commented Dec 5, 2025

Tweaked based on feedback.

@Mauller Mauller force-pushed the Mauller/fix-filewrapperlist-security branch from 1e5ab7f to 17c275e Compare December 5, 2025 21:48
@Mauller Mauller force-pushed the Mauller/fix-filewrapperlist-security branch from 17c275e to c7fc2bd Compare December 5, 2025 21:54
@Mauller
Copy link
Author

Mauller commented Dec 5, 2025

Tweaked

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very secure game.

@Mauller
Copy link
Author

Mauller commented Dec 6, 2025

I don't think this needs replicating since the code is already in core, so should be good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Critical Severity: Minor < Major < Critical < Blocker Gen Relates to Generals Network Anything related to network, servers Security Is security related ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants