Skip to content

Commit f0d3e9a

Browse files
authored
Security fixes (rcore_desktop_win32.c) (#5899)
* Security fixes in rcore_desktop_win32.c * Avoid calling strlen() twice
1 parent 7c284cc commit f0d3e9a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/platforms/rcore_desktop_win32.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,9 @@ void OpenURL(const char *url)
12571257
if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
12581258
else
12591259
{
1260-
char *cmd = (char *)RL_CALLOC(strlen(url) + 32, sizeof(char));
1261-
sprintf(cmd, "explorer \"%s\"", url);
1260+
int len = strlen(url) + 32;
1261+
char *cmd = (char *)RL_CALLOC(len, sizeof(char));
1262+
snprintf(cmd, len, "explorer \"%s\"", url);
12621263
int result = system(cmd);
12631264
if (result == -1) TRACELOG(LOG_WARNING, "OpenURL() child process could not be created");
12641265
RL_FREE(cmd);
@@ -2052,8 +2053,11 @@ static void HandleMouseButton(int button, char state)
20522053
static void HandleRawInput(LPARAM lparam)
20532054
{
20542055
RAWINPUT input = { 0 };
2056+
UINT inputSize = 0;
2057+
2058+
if (GetRawInputData((HRAWINPUT)lparam, RID_INPUT, NULL, &inputSize, sizeof(RAWINPUTHEADER)) != 0) return;
2059+
if (inputSize > sizeof(input)) return;
20552060

2056-
UINT inputSize = sizeof(input);
20572061
UINT size = GetRawInputData((HRAWINPUT)lparam, RID_INPUT, &input, &inputSize, sizeof(RAWINPUTHEADER));
20582062

20592063
if (size == (UINT)-1) TRACELOG(LOG_ERROR, "WIN32: Failed to get raw input data [ERROR: %lu]", GetLastError());

0 commit comments

Comments
 (0)