summaryrefslogtreecommitdiffstats
path: root/src/udev/udev-watch.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-10-13 16:28:02 +0200
committerLennart Poettering <lennart@poettering.net>2018-10-14 19:59:49 +0200
commite7aa9512e42e79dc5b0d744e68a394f29000ebdb (patch)
treed8baccc4f443dbabe1b3b48ccd613339c1df219e /src/udev/udev-watch.c
parentMerge pull request #10381 from poettering/coverity-fixes (diff)
downloadsystemd-e7aa9512e42e79dc5b0d744e68a394f29000ebdb.tar.xz
systemd-e7aa9512e42e79dc5b0d744e68a394f29000ebdb.zip
udev: use readlink_malloc() or its friend
Follow-up for a2554acec652fc65c8ed0c6c1fede9ba8c3693b1 and 70068602713e8f441c5ddc2618f007f24488e422.
Diffstat (limited to 'src/udev/udev-watch.c')
-rw-r--r--src/udev/udev-watch.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c
index d3e4391ee9..cfcb310d23 100644
--- a/src/udev/udev-watch.c
+++ b/src/udev/udev-watch.c
@@ -7,8 +7,10 @@
#include <sys/inotify.h>
#include <unistd.h>
+#include "alloc-util.h"
#include "device-private.h"
#include "dirent-util.h"
+#include "fs-util.h"
#include "mkdir.h"
#include "stdio-util.h"
#include "udev-watch.h"
@@ -48,21 +50,16 @@ int udev_watch_restore(void) {
FOREACH_DIRENT_ALL(ent, dir, break) {
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
- char device[PATH_MAX];
- ssize_t len;
+ _cleanup_free_ char *device = NULL;
if (ent->d_name[0] == '.')
continue;
- len = readlinkat(dirfd(dir), ent->d_name, device, sizeof(device));
- if (len <= 0) {
- log_error_errno(errno, "Failed to read link '/run/udev/watch.old/%s', ignoring: %m", ent->d_name);
- goto unlink;
- } else if (len >= (ssize_t) sizeof(device)) {
- log_error("Path specified by link '/run/udev/watch.old/%s' is truncated, ignoring.", ent->d_name);
+ r = readlinkat_malloc(dirfd(dir), ent->d_name, &device);
+ if (r < 0) {
+ log_error_errno(r, "Failed to read link '/run/udev/watch.old/%s', ignoring: %m", ent->d_name);
goto unlink;
}
- device[len] = '\0';
r = sd_device_new_from_device_id(&dev, device);
if (r < 0) {
@@ -152,8 +149,8 @@ int udev_watch_end(sd_device *dev) {
}
int udev_watch_lookup(int wd, sd_device **ret) {
- char filename[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)], device[PATH_MAX];
- ssize_t len;
+ char filename[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
+ _cleanup_free_ char *device = NULL;
int r;
assert(ret);
@@ -165,14 +162,12 @@ int udev_watch_lookup(int wd, sd_device **ret) {
return log_error_errno(EINVAL, "Invalid watch handle.");
xsprintf(filename, "/run/udev/watch/%d", wd);
- len = readlink(filename, device, sizeof(device));
- if (len <= 0) {
- if (errno != ENOENT)
+ r = readlink_malloc(filename, &device);
+ if (r < 0) {
+ if (r != -ENOENT)
return log_error_errno(errno, "Failed to read link '%s': %m", filename);
return 0;
- } else if (len >= (ssize_t) sizeof(device))
- return log_error_errno(ENAMETOOLONG, "Path specified by link '%s' is truncated.", filename);
- device[len] = '\0';
+ }
r = sd_device_new_from_device_id(ret, device);
if (r < 0)