elput - simplify and fix handling of string overflow with xdg runtimedir
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sat, 9 Jul 2016 03:01:51 +0000 (12:01 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sat, 9 Jul 2016 03:01:51 +0000 (12:01 +0900)
this addresses an issue pointed to by CID 1357168

src/lib/elput/elput_evdev.c

index 5393a07..089bad5 100644 (file)
@@ -60,24 +60,15 @@ _keyboard_modifiers_update(Elput_Keyboard *kbd, Elput_Seat *seat)
 static int
 _keyboard_fd_get(off_t size)
 {
-   int fd = 0, blen = 0, len = 0;
+   int fd = 0;
    const char *path;
    char tmp[PATH_MAX];
    long flags;
 
-   blen = sizeof(tmp) - 1;
-
    if (!(path = getenv("XDG_RUNTIME_DIR")))
      return -1;
 
-   len = strlen(path);
-   if (len < blen)
-     {
-        strcpy(tmp, path);
-        strcat(tmp, "/elput-keymap-XXXXXX");
-     }
-   else
-     return -1;
+   snprintf(tmp, sizeof(tmp), "%s/elput-keymap-XXXXXX", path);
 
    fd = eina_file_mkstemp(tmp, NULL);
    if (fd < 0) return -1;