linux_joystick.c: ensure regfree is only called with valid data

Introduces regex_compiled boolean to track whether the regex is compiled
successfully.
This commit is contained in:
Michael Skec 2023-11-09 15:04:19 +11:00
parent 3eaf1255b2
commit 51d9dd1848
No known key found for this signature in database
GPG Key ID: 796F2FAAF880965C
2 changed files with 7 additions and 2 deletions

View File

@ -326,7 +326,9 @@ GLFWbool _glfwInitJoysticksLinux(void)
// Continue without device connection notifications if inotify fails // Continue without device connection notifications if inotify fails
if (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) != 0) _glfw.linjs.regex_compiled = regcomp(&_glfw.linjs.regex,
"^event[0-9]\\+$", 0) == 0;
if (!_glfw.linjs.regex_compiled)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex"); _glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex");
return GLFW_FALSE; return GLFW_FALSE;
@ -378,8 +380,10 @@ void _glfwTerminateJoysticksLinux(void)
inotify_rm_watch(_glfw.linjs.inotify, _glfw.linjs.watch); inotify_rm_watch(_glfw.linjs.inotify, _glfw.linjs.watch);
close(_glfw.linjs.inotify); close(_glfw.linjs.inotify);
regfree(&_glfw.linjs.regex);
} }
if (_glfw.linjs.regex_compiled)
regfree(&_glfw.linjs.regex);
} }
GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode) GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode)

View File

@ -50,6 +50,7 @@ typedef struct _GLFWlibraryLinux
int inotify; int inotify;
int watch; int watch;
regex_t regex; regex_t regex;
GLFWbool regex_compiled;
GLFWbool dropped; GLFWbool dropped;
} _GLFWlibraryLinux; } _GLFWlibraryLinux;