aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2013-07-03 18:04:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:07:41 -0400
commit096a8aac6bf4a5a0b2ef812ad76d056bbf3fb2af (patch)
treefa3721d6d2a96f69023624366afecb72e7b60eb6 /drivers
parente7152b97f38f1f5b915c719e6a3040697a700a16 (diff)
clean up scary strncpy(dst, src, strlen(src)) uses
Fix various weird constructions of strncpy(dst, src, strlen(src)). Length limits should be about the space available in the destination, not repurposed as a method to either always include or always exclude a trailing NULL byte. Either the NULL should always be copied (using strlcpy), or it should not be copied (using something like memcpy). Readable code should not depend on the weird behavior of strncpy when it hits the length limit. Better to avoid the anti-pattern entirely. [akpm@linux-foundation.org: revert getdelays.c part due to missing bsd/string.h] Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [staging] Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> [acpi] Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Ursula Braun <ursula.braun@de.ibm.com> Cc: Frank Blaschka <blaschka@linux.vnet.ibm.com> Cc: Richard Weinberger <richard@nod.at> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/sysfs.c3
-rw-r--r--drivers/s390/net/qeth_l3_sys.c6
-rw-r--r--drivers/staging/tidspbridge/rmgr/drv_interface.c3
3 files changed, 4 insertions, 8 deletions
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index fcae5fa2e1b3..193745d96fcc 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -677,10 +677,9 @@ void acpi_irq_stats_init(void)
677 else 677 else
678 sprintf(buffer, "bug%02X", i); 678 sprintf(buffer, "bug%02X", i);
679 679
680 name = kzalloc(strlen(buffer) + 1, GFP_KERNEL); 680 name = kstrdup(buffer, GFP_KERNEL);
681 if (name == NULL) 681 if (name == NULL)
682 goto fail; 682 goto fail;
683 strncpy(name, buffer, strlen(buffer) + 1);
684 683
685 sysfs_attr_init(&counter_attrs[i].attr); 684 sysfs_attr_init(&counter_attrs[i].attr);
686 counter_attrs[i].attr.name = name; 685 counter_attrs[i].attr.name = name;
diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
index e70af2406ff9..d1c8025b0b03 100644
--- a/drivers/s390/net/qeth_l3_sys.c
+++ b/drivers/s390/net/qeth_l3_sys.c
@@ -315,10 +315,8 @@ static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
315 if (qeth_configure_cq(card, QETH_CQ_ENABLED)) 315 if (qeth_configure_cq(card, QETH_CQ_ENABLED))
316 return -EPERM; 316 return -EPERM;
317 317
318 for (i = 0; i < 8; i++) 318 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
319 card->options.hsuid[i] = ' '; 319 "%-8s", tmp);
320 card->options.hsuid[8] = '\0';
321 strncpy(card->options.hsuid, tmp, strlen(tmp));
322 ASCEBC(card->options.hsuid, 8); 320 ASCEBC(card->options.hsuid, 8);
323 if (card->dev) 321 if (card->dev)
324 memcpy(card->dev->perm_addr, card->options.hsuid, 9); 322 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index 9c020562c846..6d04eb48bfbc 100644
--- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
+++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
@@ -421,12 +421,11 @@ static int omap3_bridge_startup(struct platform_device *pdev)
421 drv_datap->tc_wordswapon = tc_wordswapon; 421 drv_datap->tc_wordswapon = tc_wordswapon;
422 422
423 if (base_img) { 423 if (base_img) {
424 drv_datap->base_img = kmalloc(strlen(base_img) + 1, GFP_KERNEL); 424 drv_datap->base_img = kstrdup(base_img, GFP_KERNEL);
425 if (!drv_datap->base_img) { 425 if (!drv_datap->base_img) {
426 err = -ENOMEM; 426 err = -ENOMEM;
427 goto err2; 427 goto err2;
428 } 428 }
429 strncpy(drv_datap->base_img, base_img, strlen(base_img) + 1);
430 } 429 }
431 430
432 dev_set_drvdata(bridge, drv_datap); 431 dev_set_drvdata(bridge, drv_datap);