[systemd-devel] [PATCH] libudev-monitor: ensure proper string termination

Topi Miettinen toiwoton at gmail.com
Sat Jan 24 00:39:56 PST 2015


Leave space for the terminating zero when reading and make sure
that the last byte is zero. This also makes the check for long packets
equivalent to code before 9c89c1ca: reject also packets with size 8192.
---
 src/libudev/libudev-monitor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c
index 4cfb2f6..b7fc031 100644
--- a/src/libudev/libudev-monitor.c
+++ b/src/libudev/libudev-monitor.c
@@ -590,7 +590,7 @@ retry:
         if (udev_monitor == NULL)
                 return NULL;
         iov.iov_base = &buf;
-        iov.iov_len = sizeof(buf);
+        iov.iov_len = sizeof(buf) - 1; /* Leave space for terminating zero */
         memzero(&smsg, sizeof(struct msghdr));
         smsg.msg_iov = &iov;
         smsg.msg_iovlen = 1;
@@ -642,6 +642,8 @@ retry:
         if (udev_device == NULL)
                 return NULL;
 
+        buf.raw[sizeof(buf.raw) - 1] = '\0';
+
         if (memcmp(buf.raw, "libudev", 8) == 0) {
                 /* udev message needs proper version magic */
                 if (buf.nlh.magic != htonl(UDEV_MONITOR_MAGIC)) {
-- 
2.1.4



More information about the systemd-devel mailing list