char *next;
target_len = readlink(filename, target, sizeof(target));
- if (target_len > 0)
- target[target_len] = '\0';
- else {
- dbg(udev_device->udev, "error reading db link %s: %m\n", filename);
+ if (target_len <= 0 || target_len == sizeof(target)) {
+ info(udev_device->udev, "error reading db link %s: %m\n", filename);
return -1;
}
+ target[target_len] = '\0';
next = strchr(target, ' ');
if (next != NULL) {
goto out;
len = readlink(path, target, sizeof(target));
- if (len > 0) {
- target[len] = '\0';
- pos = strrchr(target, '/');
- if (pos != NULL) {
- pos = &pos[1];
- dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
- list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list, sysattr, pos, 0, 0);
- val = udev_list_entry_get_value(list_entry);
- }
+ if (len <= 0 || len == sizeof(target))
+ goto out;
+ target[len] = '\0';
+
+ pos = strrchr(target, '/');
+ if (pos != NULL) {
+ pos = &pos[1];
+ dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
+ list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list, sysattr, pos, 0, 0);
+ val = udev_list_entry_get_value(list_entry);
}
+
goto out;
}
s = syspath;
l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL);
len = readlinkat(dirfd(dir), dent->d_name, s, l);
- if (len < 0 || (size_t)len >= l)
+ if (len <= 0 || (size_t)len == l)
continue;
s[len] = '\0';
dbg(udev_queue->udev, "found '%s' [%s]\n", syspath, dent->d_name);
int len;
dbg(udev, "found existing symlink '%s'\n", slink);
- len = readlink(slink, buf, sizeof(buf) - 1);
- if (len > 0) {
+ len = readlink(slink, buf, sizeof(buf));
+ 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",
s = device;
l = util_strpcpy(&s, sizeof(device), udev_get_sys_path(udev));
len = readlinkat(dirfd(dir), ent->d_name, s, l);
- if (len <= 0 || len >= (ssize_t)l)
+ if (len <= 0 || len == (ssize_t)l)
goto unlink;
s[len] = '\0';
s = majmin;
l = util_strpcpy(&s, sizeof(majmin), udev_get_sys_path(udev));
len = readlink(filename, s, l);
- if (len < 0 || (size_t)len >= l)
+ if (len <= 0 || (size_t)len == l)
return NULL;
s[len] = '\0';