From 5bcf9c76fd71d2e538f187c085a843694ac0afb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 8 Jun 2017 19:23:06 +0200 Subject: [PATCH] Linux: Fix path buffer length warning Fixes #1025. --- README.md | 1 + src/linux_joystick.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c53173d2..90729f3b 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ information on what to include when reporting a bug. - [X11] Bugfix: Gamma ramp setting via RandR did not validate ramp size - [X11] Bugfix: Key name string encoding depended on current locale (#981,#983) - [Linux] Bugfix: Event processing did not detect joystick disconnection (#932) +- [Linux] Bugfix: The joystick device path could be truncated (#1025) - [Cocoa] Added support for Vulkan window surface creation via [MoltenVK](https://moltengl.com/moltenvk/) (#870) - [Cocoa] Added support for loading a `MainMenu.nib` when available diff --git a/src/linux_joystick.c b/src/linux_joystick.c index 6e4b6a8c..da6c490d 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -160,15 +160,24 @@ GLFWbool _glfwInitJoysticksLinux(void) while ((entry = readdir(dir))) { - char path[20]; regmatch_t match; + char* path = NULL; if (regexec(&_glfw.linjs.regex, entry->d_name, 1, &match, 0) != 0) continue; - snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name); + if (asprintf(&path, "%s/%s", dirname, entry->d_name) < 0) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Linux: Failed to construct device path: %s", + strerror(errno)); + continue; + } + if (openJoystickDevice(path)) count++; + + free(path); } closedir(dir);