dbg(udev, "found existing symlink '%s'\n", slink);
len = readlink(slink, buf, sizeof(buf));
- if (len > 0) {
+ if (len > 0 && len < (int)sizeof(buf)) {
buf[len] = '\0';
if (strcmp(target, buf) == 0) {
info(udev, "preserve already existing symlink '%s' to '%s'\n",
err = util_create_path(udev, filename);
if (err != 0 && err != -ENOENT)
break;
- fd = open(filename, O_WRONLY|O_CREAT, 0444);
+ fd = open(filename, O_WRONLY|O_CREAT|O_NOFOLLOW, 0444);
if (fd >= 0)
close(fd);
else