loader: fix sysfs uevent file parsing
authorFrank Binns <frank.binns@imgtec.com>
Thu, 4 Aug 2016 14:15:23 +0000 (15:15 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Thu, 1 Sep 2016 14:48:34 +0000 (15:48 +0100)
When trying to get a device name for an fd using sysfs, it would always fail
as it was expecting key/value pairs to be delimited by '\0', which is not the
case.

Signed-off-by: Frank Binns <frank.binns@imgtec.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/loader/loader.c

index 56ffc5d77a799ad5b14a789cd929bee009511cb4..3e60e4ccf1d1cc9eadef2e9a0b24b45e7452d715 100644 (file)
@@ -645,7 +645,7 @@ sysfs_get_device_name_for_fd(int fd)
    unsigned int maj, min;
    FILE *f;
    char buf[0x40];
-   static const char match[9] = "\0DEVNAME=";
+   static const char match[9] = "\nDEVNAME=";
    int expected = 1;
 
    if (dev_node_from_fd(fd, &maj, &min) < 0)
@@ -668,8 +668,10 @@ sysfs_get_device_name_for_fd(int fd)
    }
 
    strcpy(buf, "/dev/");
-   if (fgets(buf + 5, sizeof(buf) - 5, f))
+   if (fgets(buf + 5, sizeof(buf) - 5, f)) {
+      buf[strcspn(buf, "\n")] = '\0';
       device_name = strdup(buf);
+   }
 
    fclose(f);
    return device_name;