]> err.no Git - systemd/commitdiff
replace strncpy() with strlcpy()
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>
Tue, 21 Oct 2008 21:42:15 +0000 (22:42 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 21 Oct 2008 21:55:13 +0000 (23:55 +0200)
The problem was strncpy() doesn't stop after writing the terminating
NUL; by definition it goes on to zero the entire buffer.

I spy another use of strncpy in udev_device_add_property_from_string(),
which is responsible for another ~1% user cpu time...

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
extras/scsi_id/scsi_id.c
udev/lib/libudev-device.c

index 6334af386b0910c9ee1a09c7ded395cfb513b85e..86c76cfcc40bf11648a5df8e72baca8a70579147 100644 (file)
@@ -135,8 +135,7 @@ static void set_type(char *to, const char *from, size_t len)
                        break;
                }
        }
-       strncpy(to, type, len);
-       to[len-1] = '\0';
+       util_strlcpy(to, type, len);
 }
 
 /*
@@ -385,8 +384,7 @@ static int set_options(struct udev *udev,
 
                case 'd':
                        dev_specified = 1;
-                       strncpy(maj_min_dev, optarg, MAX_PATH_LEN);
-                       maj_min_dev[MAX_PATH_LEN-1] = '\0';
+                       util_strlcpy(maj_min_dev, optarg, MAX_PATH_LEN);
                        break;
 
                case 'e':
@@ -394,8 +392,7 @@ static int set_options(struct udev *udev,
                        break;
 
                case 'f':
-                       strncpy(config_file, optarg, MAX_PATH_LEN);
-                       config_file[MAX_PATH_LEN-1] = '\0';
+                       util_strlcpy(config_file, optarg, MAX_PATH_LEN);
                        break;
 
                case 'g':
@@ -461,8 +458,7 @@ static int set_options(struct udev *udev,
        }
        if (optind < argc && !dev_specified) {
                dev_specified = 1;
-               strncpy(maj_min_dev, argv[optind], MAX_PATH_LEN);
-               maj_min_dev[MAX_PATH_LEN-1] = '\0';
+               util_strlcpy(maj_min_dev, argv[optind], MAX_PATH_LEN);
        }
        return 0;
 }
index 5a435487362eafb96f240f4c832edcc7a3a2d71c..f56db7ff155bbe70fa36fd2b83217cd9f148d42c 100644 (file)
@@ -1001,7 +1001,7 @@ struct udev_list_entry *udev_device_add_property_from_string(struct udev_device
        char name[UTIL_PATH_SIZE];
        char *val;
 
-       strncpy(name, property, sizeof(name));
+       util_strlcpy(name, property, sizeof(name));
        val = strchr(name, '=');
        if (val == NULL)
                return NULL;