5 Commits

Author SHA1 Message Date
3edfe19438 [rcore] Bounds-check gamepad index in GetGamepadAxisCount() and GetGamepadName() (#5937)
* [rcore] Bounds-check gamepad index in GetGamepadAxisCount() and GetGamepadName()

Both public getters indexed CORE.Input.Gamepad.axisCount[gamepad] / .name[gamepad]
with an unvalidated gamepad argument -- an out-of-bounds read for gamepad < 0 or
gamepad >= MAX_GAMEPADS. Every sibling gamepad accessor (IsGamepadAvailable,
IsGamepadButton*, GetGamepadAxisMovement) already guards the index; add the same
check, returning a safe default (0 / NULL).

* Refactor GetGamepadName/GetGamepadAxisCount to single-return pattern

---------

Co-authored-by: Brandon Arrendondo <brandon.arrendondo@bissell.com>
2026-06-24 17:40:28 +02:00
9215540015 [rtext] Fix buffer overflow in TextReplaceBetween() (#5936)
The MAX_TEXT_BUFFER_LENGTH guard present in TextReplace()/TextInsert() was
missing here, so the three strncpy() calls could write past the 1024-byte
static buffer for long inputs. Add the same length check before copying.

Co-authored-by: Brandon Arrendondo <brandon.arrendondo@bissell.com>
2026-06-24 16:41:19 +02:00
83cb4cc210 [rlgl] Fix matrix stack overflow in rlPushMatrix() (#5935)
The RL_MAX_MATRIX_STACK_SIZE check logged an error but did not return, so
RLGL.State.stack[stackCounter] = *currentMatrix still executed when the stack
was full -- writing one element past stack[RL_MAX_MATRIX_STACK_SIZE] and
corrupting the adjacent RLGL.State members (stackCounter, etc.). rlPopMatrix()
already guards the symmetric underflow case; add the missing early return.

Co-authored-by: Brandon Arrendondo <brandon.arrendondo@bissell.com>
2026-06-24 16:38:08 +02:00
Ray
d1a14bee5d Update rmodels.c 2026-06-24 10:38:20 +02:00
eu
ba3b8f8370 Add comments for GenMeshTorus (#5934) 2026-06-24 10:36:30 +02:00
4 changed files with 24 additions and 6 deletions

View File

@ -3934,7 +3934,11 @@ bool IsGamepadAvailable(int gamepad)
// Get gamepad internal name id
const char *GetGamepadName(int gamepad)
{
return CORE.Input.Gamepad.name[gamepad];
const char *name = NULL;
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS)) name = CORE.Input.Gamepad.name[gamepad];
return name;
}
// Check if gamepad button has been pressed once
@ -3999,7 +4003,11 @@ int GetGamepadButtonPressed(void)
// Get gamepad axis count
int GetGamepadAxisCount(int gamepad)
{
return CORE.Input.Gamepad.axisCount[gamepad];
int result = 0;
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS)) result = CORE.Input.Gamepad.axisCount[gamepad];
return result;
}
// Get axis movement vector for a gamepad

View File

@ -1237,7 +1237,11 @@ void rlMatrixMode(int mode)
// Push the current matrix into RLGL.State.stack
void rlPushMatrix(void)
{
if (RLGL.State.stackCounter >= RL_MAX_MATRIX_STACK_SIZE) TRACELOG(RL_LOG_ERROR, "RLGL: Matrix stack overflow (RL_MAX_MATRIX_STACK_SIZE)");
if (RLGL.State.stackCounter >= RL_MAX_MATRIX_STACK_SIZE)
{
TRACELOG(RL_LOG_ERROR, "RLGL: Matrix stack overflow (RL_MAX_MATRIX_STACK_SIZE)");
return;
}
if (RLGL.State.currentMatrixMode == RL_MODELVIEW)
{

View File

@ -3142,6 +3142,8 @@ Mesh GenMeshCone(float radius, float height, int slices)
}
// Generate torus mesh
// NOTE: The distance between the center of the hole and the center of the
// tube is half size of the radius of the tube (radius*size/2)
Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
{
Mesh mesh = { 0 };

View File

@ -1919,9 +1919,13 @@ char *TextReplaceBetween(const char *text, const char *begin, const char *end, c
int replaceLen = (replacement == NULL)? 0 : TextLength(replacement);
//int toreplaceLen = endIndex - beginIndex - beginLen;
strncpy(buffer, text, beginIndex + beginLen); // Copy first text part
if (replacement != NULL) strncpy(buffer + beginIndex + beginLen, replacement, replaceLen); // Copy replacement (if provided)
strncpy(buffer + beginIndex + beginLen + replaceLen, text + endIndex, textLen - endIndex); // Copy end text part
if ((beginIndex + beginLen + replaceLen + (textLen - endIndex)) < (MAX_TEXT_BUFFER_LENGTH - 1))
{
strncpy(buffer, text, beginIndex + beginLen); // Copy first text part
if (replacement != NULL) strncpy(buffer + beginIndex + beginLen, replacement, replaceLen); // Copy replacement (if provided)
strncpy(buffer + beginIndex + beginLen + replaceLen, text + endIndex, textLen - endIndex); // Copy end text part
}
else TRACELOG(LOG_WARNING, "TEXT: Text with replaced string is longer than internal buffer (MAX_TEXT_BUFFER_LENGTH)");
}
}
}