staging: usbip: stub_main.c: Cleaning up missing null-terminate in conjunction with...
authorRickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Sat, 26 Jul 2014 14:43:20 +0000 (16:43 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 27 Jul 2014 18:43:01 +0000 (11:43 -0700)
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/usbip/stub_main.c

index 9c5832a..44ab43f 100644 (file)
@@ -94,7 +94,7 @@ static int add_match_busid(char *busid)
 
        for (i = 0; i < MAX_BUSID; i++)
                if (!busid_table[i].name[0]) {
-                       strncpy(busid_table[i].name, busid, BUSID_SIZE);
+                       strlcpy(busid_table[i].name, busid, BUSID_SIZE);
                        if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
                            (busid_table[i].status != STUB_BUSID_REMOV))
                                busid_table[i].status = STUB_BUSID_ADDED;
@@ -158,15 +158,11 @@ static ssize_t store_match_busid(struct device_driver *dev, const char *buf,
        if (count < 5)
                return -EINVAL;
 
-       /* strnlen() does not include \0 */
-       len = strnlen(buf + 4, BUSID_SIZE);
-
        /* busid needs to include \0 termination */
-       if (!(len < BUSID_SIZE))
+       len = strlcpy(busid, buf + 4, BUSID_SIZE);
+       if (sizeof(busid) <= len)
                return -EINVAL;
 
-       strncpy(busid, buf + 4, BUSID_SIZE);
-
        if (!strncmp(buf, "add ", 4)) {
                if (add_match_busid(busid) < 0)
                        return -ENOMEM;