libinput: do not call close() when fd is negative 96/280796/1
authorduna.oh <duna.oh@samsung.com>
Mon, 5 Sep 2022 02:17:00 +0000 (11:17 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 5 Sep 2022 07:53:42 +0000 (16:53 +0900)
fix potential security issue

Change-Id: Ie6ee22ced3c913902124daed181056bfdcaa7cd7

src/backend/libinput/backend.c

index b7e1bc4..7a7ed02 100644 (file)
@@ -80,8 +80,11 @@ libinput_open_restricted(const char *path, int flags, void *_backend)
 
     fd = open(path, flags | O_CLOEXEC);
 
-    if (fd < 0 || (fstat(fd, &s) == -1)) {
+    if (fd < 0) {
         ds_log(DS_ERR, "Could not open device");
+        return -1;
+    }
+    if (fstat(fd, &s) == -1) {
         close(fd);
         return -1;
     }
@@ -226,4 +229,4 @@ libinput_backend_handle_display_destroy(struct wl_listener *listener,
 
 uint32_t usec_to_msec(uint64_t usec) {
        return (uint32_t)(usec / 1000);
-}
\ No newline at end of file
+}