🔒 Fix unsafe strcpy and add null check in LicensePlate#231
Open
CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
Open
🔒 Fix unsafe strcpy and add null check in LicensePlate#231CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
Conversation
…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.
Contributor
There was a problem hiding this comment.
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, ...)withRwTextureSetName(...)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 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 What: Replaced the unsafe
strcpycall with the standard RenderWareRwTextureSetNamefunction and added a null check for the texture array.strcpycould 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 form_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.