chiark / gitweb /
set buffer size if strlcpy/strlcat indicate truncation
authorMichael Morony <michael.morony@gmail.com>
Fri, 24 Aug 2007 06:14:21 +0000 (08:14 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Fri, 24 Aug 2007 06:14:21 +0000 (08:14 +0200)
udev_rules.c
udev_sysfs.c
udevinfo.c
udevmonitor.c
udevtrigger.c

index 0dcbf156ea14d9708b4b53b5d9cd60b4b956e0ff..35db958c8df4959fbb68664b1aed7afb0124a3aa 100644 (file)
@@ -475,10 +475,12 @@ static int pass_env_to_socket(const char *sockname, const char *devpath, const c
 
        bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath);
        bufpos++;
-       for (i = 0; environ[i] != NULL && bufpos < sizeof(buf); i++) {
+       for (i = 0; environ[i] != NULL && bufpos < (sizeof(buf)-1); i++) {
                bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos-1);
                bufpos++;
        }
+       if (bufpos > sizeof(buf))
+               bufpos = sizeof(buf);
 
        count = sendto(sock, &buf, bufpos, 0, (struct sockaddr *)&saddr, addrlen);
        if (count < 0)
index 34ae9ac14fd400758d5d3a618dc527d19a9bbd54..d5b04c310fe8bc10585fe36f135c381584caa808 100644 (file)
@@ -355,6 +355,8 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
 
        dbg("open '%s'/'%s'", devpath, attr_name);
        sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full));
+       if(sysfs_len >= sizeof(path_full))
+               sysfs_len = sizeof(path_full) - 1;
        path = &path_full[sysfs_len];
        strlcat(path_full, devpath, sizeof(path_full));
        strlcat(path_full, "/", sizeof(path_full));
index d0b1c447f4d65f2692b026996333dbf58f8f0328..be9aa769e10f46352039dbdb93e0d723d5dc89d6 100644 (file)
@@ -79,6 +79,8 @@ static void print_all_attributes(const char *devpath, const char *key)
                        if (attr_value == NULL)
                                continue;
                        len = strlcpy(value, attr_value, sizeof(value));
+                       if(len >= sizeof(value))
+                               len = sizeof(value) - 1;
                        dbg("attr '%s'='%s'(%zi)", dent->d_name, value, len);
 
                        /* remove trailing newlines */
index a9cc0614ff8f0da7765403829eae813241ac0fc5..644a955090e22e69b47ce295180574422e3abe47 100644 (file)
@@ -43,7 +43,6 @@ static int init_udev_monitor_socket(void)
 {
        struct sockaddr_un saddr;
        socklen_t addrlen;
-       const int feature_on = 1;
        int retval;
 
        memset(&saddr, 0x00, sizeof(saddr));
@@ -67,9 +66,6 @@ static int init_udev_monitor_socket(void)
                return -1;
        }
 
-       /* enable receiving of the sender credentials */
-       setsockopt(udev_monitor_sock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
-
        return 0;
 }
 
index cf8f209b1c105155727fe9f186218dd19832f6de..309c54ab68b3f41fd0e4c68b1eb77798f8621734 100644 (file)
@@ -435,6 +435,8 @@ static void scan_failed(void)
                                continue;
 
                        start = strlcpy(device, sysfs_path, sizeof(device));
+                       if(start >= sizeof(device))
+                               start = sizeof(device) - 1;
                        strlcat(device, dent->d_name, sizeof(device));
                        path_decode(&device[start]);
                        device_list_insert(device);