[PATCH net-next v1 11/11] net: pktgen: fix code style (WARNING: Prefer strscpy over strcpy)

Peter Seiderer posted 11 patches 8 months, 1 week ago
There is a newer version of this series
[PATCH net-next v1 11/11] net: pktgen: fix code style (WARNING: Prefer strscpy over strcpy)
Posted by Peter Seiderer 8 months, 1 week ago
Fix checkpatch code style warnings:

  WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
  #1422: FILE: net/core/pktgen.c:1422:
  +                       strcpy(pkt_dev->dst_min, buf);

  WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
  #1443: FILE: net/core/pktgen.c:1443:
  +                       strcpy(pkt_dev->dst_max, buf);

  WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
  #1553: FILE: net/core/pktgen.c:1553:
  +                       strcpy(pkt_dev->src_min, buf);

  WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
  #1574: FILE: net/core/pktgen.c:1574:
  +                       strcpy(pkt_dev->src_max, buf);

  WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
  #3227: FILE: net/core/pktgen.c:3227:
  +                       strcpy(pkt_dev->result, "Starting");

  WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
  #3231: FILE: net/core/pktgen.c:3231:
  +                       strcpy(pkt_dev->result, "Error starting");

  WARNING: Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88
  #3845: FILE: net/core/pktgen.c:3845:
  +       strcpy(pkt_dev->odevname, ifname);

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
 net/core/pktgen.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 0d18fd932ed9..3f76cae9cf57 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1419,7 +1419,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 		if (strcmp(buf, pkt_dev->dst_min) != 0) {
 			memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
-			strcpy(pkt_dev->dst_min, buf);
+			strscpy(pkt_dev->dst_min, buf);
 			pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
 			pkt_dev->cur_daddr = pkt_dev->daddr_min;
 		}
@@ -1440,7 +1440,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 		if (strcmp(buf, pkt_dev->dst_max) != 0) {
 			memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max));
-			strcpy(pkt_dev->dst_max, buf);
+			strscpy(pkt_dev->dst_max, buf);
 			pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
 			pkt_dev->cur_daddr = pkt_dev->daddr_max;
 		}
@@ -1550,7 +1550,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 		if (strcmp(buf, pkt_dev->src_min) != 0) {
 			memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min));
-			strcpy(pkt_dev->src_min, buf);
+			strscpy(pkt_dev->src_min, buf);
 			pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
 			pkt_dev->cur_saddr = pkt_dev->saddr_min;
 		}
@@ -1571,7 +1571,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 		if (strcmp(buf, pkt_dev->src_max) != 0) {
 			memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max));
-			strcpy(pkt_dev->src_max, buf);
+			strscpy(pkt_dev->src_max, buf);
 			pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
 			pkt_dev->cur_saddr = pkt_dev->saddr_max;
 		}
@@ -3224,11 +3224,11 @@ static void pktgen_run(struct pktgen_thread *t)
 
 			set_pkt_overhead(pkt_dev);
 
-			strcpy(pkt_dev->result, "Starting");
+			strscpy(pkt_dev->result, "Starting");
 			pkt_dev->running = 1;	/* Cranke yeself! */
 			started++;
 		} else
-			strcpy(pkt_dev->result, "Error starting");
+			strscpy(pkt_dev->result, "Error starting");
 	}
 	rcu_read_unlock();
 	if (started)
@@ -3842,7 +3842,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
 	if (!pkt_dev)
 		return -ENOMEM;
 
-	strcpy(pkt_dev->odevname, ifname);
+	strscpy(pkt_dev->odevname, ifname);
 	pkt_dev->flows = vzalloc_node(array_size(MAX_CFLOWS,
 						 sizeof(struct flow_state)),
 				      node);
-- 
2.49.0

Re: [PATCH net-next v1 11/11] net: pktgen: fix code style (WARNING: Prefer strscpy over strcpy)
Posted by Jakub Kicinski 8 months, 1 week ago
On Thu, 10 Apr 2025 09:17:48 +0200 Peter Seiderer wrote:
>  			memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
> -			strcpy(pkt_dev->dst_min, buf);
> +			strscpy(pkt_dev->dst_min, buf);

these should probably be strcpy_pad()