]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ipv4: ip_tunnel: Replace strcpy use with strscpy
authorRuben Wauters <rubenru09@aol.com>
Thu, 1 May 2025 20:23:55 +0000 (21:23 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 6 May 2025 01:16:11 +0000 (18:16 -0700)
Use of strcpy is decpreated, replaces the use of strcpy with strscpy as
recommended.

strscpy was chosen as it requires a NUL terminated non-padded string,
which is the case here.

I am aware there is an explicit bounds check above the second instance,
however using strscpy protects against buffer overflows in any future
code, and there is no good reason I can see to not use it.

I have also replaced the scrscpy above that had 3 params with the
version using 2 params. These are functionally equivalent, but it is
cleaner to have both using 2 params.

Signed-off-by: Ruben Wauters <rubenru09@aol.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250501202935.46318-1-rubenru09@aol.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/ip_tunnel.c

index 3913ec89ad207649404ce62423e8b2747aad59d4..678b8f96e3e9ccfd9df61a9f1d38056bbc9cca6b 100644 (file)
@@ -243,11 +243,11 @@ static struct net_device *__ip_tunnel_create(struct net *net,
        if (parms->name[0]) {
                if (!dev_valid_name(parms->name))
                        goto failed;
-               strscpy(name, parms->name, IFNAMSIZ);
+               strscpy(name, parms->name);
        } else {
                if (strlen(ops->kind) > (IFNAMSIZ - 3))
                        goto failed;
-               strcpy(name, ops->kind);
+               strscpy(name, ops->kind);
                strcat(name, "%d");
        }