1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

more readlink buffer size handling

This commit is contained in:
Kay Sievers 2010-04-21 14:44:33 +02:00
parent e925018786
commit 60067cc75a
4 changed files with 19 additions and 18 deletions

View File

@ -222,12 +222,11 @@ int udev_device_read_db(struct udev_device *udev_device)
char *next; char *next;
target_len = readlink(filename, target, sizeof(target)); target_len = readlink(filename, target, sizeof(target));
if (target_len > 0) if (target_len <= 0 || target_len == sizeof(target)) {
target[target_len] = '\0'; info(udev_device->udev, "error reading db link %s: %m\n", filename);
else {
dbg(udev_device->udev, "error reading db link %s: %m\n", filename);
return -1; return -1;
} }
target[target_len] = '\0';
next = strchr(target, ' '); next = strchr(target, ' ');
if (next != NULL) { if (next != NULL) {
@ -1095,8 +1094,10 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
goto out; goto out;
len = readlink(path, target, sizeof(target)); len = readlink(path, target, sizeof(target));
if (len > 0) { if (len <= 0 || len == sizeof(target))
goto out;
target[len] = '\0'; target[len] = '\0';
pos = strrchr(target, '/'); pos = strrchr(target, '/');
if (pos != NULL) { if (pos != NULL) {
pos = &pos[1]; pos = &pos[1];
@ -1104,7 +1105,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list, sysattr, pos, 0, 0); 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); val = udev_list_entry_get_value(list_entry);
} }
}
goto out; goto out;
} }

View File

@ -488,7 +488,7 @@ struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev
s = syspath; s = syspath;
l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL); l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL);
len = readlinkat(dirfd(dir), dent->d_name, s, l); len = readlinkat(dirfd(dir), dent->d_name, s, l);
if (len < 0 || (size_t)len >= l) if (len <= 0 || (size_t)len == l)
continue; continue;
s[len] = '\0'; s[len] = '\0';
dbg(udev_queue->udev, "found '%s' [%s]\n", syspath, dent->d_name); dbg(udev_queue->udev, "found '%s' [%s]\n", syspath, dent->d_name);

View File

@ -163,8 +163,8 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink)
int len; int len;
dbg(udev, "found existing symlink '%s'\n", slink); dbg(udev, "found existing symlink '%s'\n", slink);
len = readlink(slink, buf, sizeof(buf) - 1); len = readlink(slink, buf, sizeof(buf));
if (len > 0) { if (len > 0 && len < (int)sizeof(buf)) {
buf[len] = '\0'; buf[len] = '\0';
if (strcmp(target, buf) == 0) { if (strcmp(target, buf) == 0) {
info(udev, "preserve already existing symlink '%s' to '%s'\n", info(udev, "preserve already existing symlink '%s' to '%s'\n",

View File

@ -81,7 +81,7 @@ void udev_watch_restore(struct udev *udev)
s = device; s = device;
l = util_strpcpy(&s, sizeof(device), udev_get_sys_path(udev)); l = util_strpcpy(&s, sizeof(device), udev_get_sys_path(udev));
len = readlinkat(dirfd(dir), ent->d_name, s, l); 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; goto unlink;
s[len] = '\0'; s[len] = '\0';
@ -173,7 +173,7 @@ struct udev_device *udev_watch_lookup(struct udev *udev, int wd)
s = majmin; s = majmin;
l = util_strpcpy(&s, sizeof(majmin), udev_get_sys_path(udev)); l = util_strpcpy(&s, sizeof(majmin), udev_get_sys_path(udev));
len = readlink(filename, s, l); len = readlink(filename, s, l);
if (len < 0 || (size_t)len >= l) if (len <= 0 || (size_t)len == l)
return NULL; return NULL;
s[len] = '\0'; s[len] = '\0';