chiark / gitweb /
util_resolve_sys_link(): fix possible buffer overflow
[elogind.git] / libudev / libudev-util-private.c
index c86567159eaf98a5886b67371bb1cb152bf98419..fe8f29b3a89007e20b595a73693644e4b18484ca 100644 (file)
@@ -34,11 +34,12 @@ int util_create_path(struct udev *udev, const char *path)
 
        util_strscpy(p, sizeof(p), path);
        pos = strrchr(p, '/');
-       if (pos == p || pos == NULL)
+       if (pos == NULL)
                return 0;
-
-       while (pos[-1] == '/')
+       while (pos != p && pos[-1] == '/')
                pos--;
+       if (pos == p)
+               return 0;
        pos[0] = '\0';
 
        dbg(udev, "stat '%s'\n", p);
@@ -64,6 +65,9 @@ int util_delete_path(struct udev *udev, const char *path)
        char *pos;
        int retval;
 
+       if (path[0] == '/')
+               while(path[1] == '/')
+                       path++;
        util_strscpy(p, sizeof(p), path);
        pos = strrchr(p, '/');
        if (pos == p || pos == NULL)