Skip to content

🔒 Fix unsafe strcpy and add null check in LicensePlate#231

Open
CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
CanerKaraca23:fix-plate-strcpy-vulnerability-8336605616389221954
Open

🔒 Fix unsafe strcpy and add null check in LicensePlate#231
CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
CanerKaraca23:fix-plate-strcpy-vulnerability-8336605616389221954

Conversation

@CanerKaraca23
Copy link
Copy Markdown
Contributor

🎯 What: Replaced the unsafe strcpy call with the standard RenderWare RwTextureSetName function and added a null check for the texture array.

⚠️ Risk: The use of strcpy could lead to a buffer overflow if the source string were ever changed to something longer than the destination buffer. Additionally, the lack of a null check for m_Plates[i] could lead to a crash if a texture fails to load.

🛡️ Solution: Used RwTextureSetName, which is the safe and idiomatic way to set a texture's name in RenderWare, and added a defensive null check to ensure the texture pointer is valid before use.

…ll check in LicensePlate

This change addresses a potential buffer overflow by replacing the unsafe
`strcpy` function with the official RenderWare `RwTextureSetName` API.
Additionally, it adds a null check for `m_Plates[i]` to prevent crashes
if any texture fails to load.
Copilot AI review requested due to automatic review settings May 8, 2026 19:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens LicensePlate::CCustomCarPlateMgr_Initialise() by removing an unsafe direct write into RwTexture::name and by guarding against null plate textures returned from TextureMgr::Get, aligning the code with existing RenderWare usage patterns in the codebase.

Changes:

  • Replaced strcpy(m_Plates[i]->name, ...) with RwTextureSetName(...) when assigning the RenderWare texture name.
  • Added a null check around per-plate texture initialization to avoid dereferencing null texture pointers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/features/plate.cpp
Comment on lines +78 to +84
if (m_Plates[i])
{
RwTextureSetName(m_Plates[i], "carpback");
RwTextureSetAddressingU(m_Plates[i], rwFILTERMIPNEAREST);
RwTextureSetAddressingV(m_Plates[i], rwFILTERMIPNEAREST);
RwTextureSetFilterMode(m_Plates[i], rwFILTERLINEAR);
}
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.

2 participants