Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drbd: Replace deprecated strcpy with strscpy

strcpy() has been deprecated [1] because it performs no bounds checking
on the destination buffer, which can lead to buffer overflows. Replace
it with the safer strscpy(). No functional changes.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Thorsten Blum and committed by
Jens Axboe
81b1f046 ab140365

+11 -7
+9 -5
drivers/block/drbd/drbd_main.c
··· 32 32 #include <linux/memcontrol.h> 33 33 #include <linux/mm_inline.h> 34 34 #include <linux/slab.h> 35 + #include <linux/string.h> 35 36 #include <linux/random.h> 36 37 #include <linux/reboot.h> 37 38 #include <linux/notifier.h> ··· 733 732 } 734 733 735 734 if (apv >= 88) 736 - strcpy(p->verify_alg, nc->verify_alg); 735 + strscpy(p->verify_alg, nc->verify_alg); 737 736 if (apv >= 89) 738 - strcpy(p->csums_alg, nc->csums_alg); 737 + strscpy(p->csums_alg, nc->csums_alg); 739 738 rcu_read_unlock(); 740 739 741 740 return drbd_send_command(peer_device, sock, cmd, size, NULL, 0); ··· 746 745 struct drbd_socket *sock; 747 746 struct p_protocol *p; 748 747 struct net_conf *nc; 748 + size_t integrity_alg_len; 749 749 int size, cf; 750 750 751 751 sock = &connection->data; ··· 764 762 } 765 763 766 764 size = sizeof(*p); 767 - if (connection->agreed_pro_version >= 87) 768 - size += strlen(nc->integrity_alg) + 1; 765 + if (connection->agreed_pro_version >= 87) { 766 + integrity_alg_len = strlen(nc->integrity_alg) + 1; 767 + size += integrity_alg_len; 768 + } 769 769 770 770 p->protocol = cpu_to_be32(nc->wire_protocol); 771 771 p->after_sb_0p = cpu_to_be32(nc->after_sb_0p); ··· 782 778 p->conn_flags = cpu_to_be32(cf); 783 779 784 780 if (connection->agreed_pro_version >= 87) 785 - strcpy(p->integrity_alg, nc->integrity_alg); 781 + strscpy(p->integrity_alg, nc->integrity_alg, integrity_alg_len); 786 782 rcu_read_unlock(); 787 783 788 784 return __conn_send_command(connection, sock, cmd, size, NULL, 0);
+2 -2
drivers/block/drbd/drbd_receiver.c
··· 3801 3801 *new_net_conf = *old_net_conf; 3802 3802 3803 3803 if (verify_tfm) { 3804 - strcpy(new_net_conf->verify_alg, p->verify_alg); 3804 + strscpy(new_net_conf->verify_alg, p->verify_alg); 3805 3805 new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1; 3806 3806 crypto_free_shash(peer_device->connection->verify_tfm); 3807 3807 peer_device->connection->verify_tfm = verify_tfm; 3808 3808 drbd_info(device, "using verify-alg: \"%s\"\n", p->verify_alg); 3809 3809 } 3810 3810 if (csums_tfm) { 3811 - strcpy(new_net_conf->csums_alg, p->csums_alg); 3811 + strscpy(new_net_conf->csums_alg, p->csums_alg); 3812 3812 new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1; 3813 3813 crypto_free_shash(peer_device->connection->csums_tfm); 3814 3814 peer_device->connection->csums_tfm = csums_tfm;