Skip to content

Commit df33a7d

Browse files
committed
Use strscpy rather than strlcpy (keep as fallback).
strscpy has been around since 4.3, and strlcpy got removed in 6.8. This patch switches to the plainly preferred strscpy whenever it is available, but will define that to strlcpy if strscpy (sized_strscpy due to strscpy really being a macro) is not available. Ideally we want to compile a test-call, but kbuild_test_symbol() doesn't work that way. We could also simply go "#ifndef strscpy ... # define strscpy strlcpy" if that would be preferred. Signed-off-by: Jaco Kroon <jaco@uls.co.za>
1 parent c5158c4 commit df33a7d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

compat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ static int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cm
178178
# define NF_IP_POST_ROUTING NF_INET_POST_ROUTING
179179
#endif
180180

181+
#ifndef HAVE_SIZED_STRSCPY
182+
#define strscpy strlcpy
183+
#endif
184+
181185
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
182186
/* net/netfilter/x_tables.c */
183187
static void xt_unregister_targets(struct xt_target *target, unsigned int n)

gen_compat_def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ kbuild_test_ref totalram_pages linux/mm.h
134134
kbuild_test_member nf_ct_event_notifier.ct_event net/netfilter/nf_conntrack_ecache.h
135135
# 6.4: 0199849acd07 ("sysctl: remove register_sysctl_paths()")
136136
kbuild_test_symbol register_sysctl_paths linux/sysctl.h
137+
# If we have strscpy, we can use that (more optimal compared to strlcpy).
138+
kbuild_test_symbol sized_strscpy linux/string.h
137139

138140
echo "// End of compat_def.h"
139141

ipt_NETFLOW.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <linux/spinlock_types.h>
4343
#include <linux/ktime.h>
4444
#include <linux/if_arp.h>
45+
#include <linux/string.h>
4546
#include <net/icmp.h>
4647
#include <net/ip.h>
4748
#include <net/ipv6.h>
@@ -4092,7 +4093,7 @@ static int ethtool_drvinfo(unsigned char *ptr, size_t size, struct net_device *d
40924093
ops->get_drvinfo(dev, &info);
40934094
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
40944095
else if (dev->dev.parent && dev->dev.parent->driver) {
4095-
strlcpy(info.driver, dev->dev.parent->driver->name, sizeof(info.driver));
4096+
strscpy(info.driver, dev->dev.parent->driver->name, sizeof(info.driver));
40964097
}
40974098
#endif
40984099
n = scnprintf(ptr, len, "%s", info.driver);
@@ -5691,7 +5692,7 @@ static int __init ipt_netflow_init(void)
56915692
if (!destination)
56925693
destination = destination_buf;
56935694
if (destination != destination_buf) {
5694-
strlcpy(destination_buf, destination, sizeof(destination_buf));
5695+
strscpy(destination_buf, destination, sizeof(destination_buf));
56955696
destination = destination_buf;
56965697
}
56975698
if (add_destinations(destination) < 0)
@@ -5701,7 +5702,7 @@ static int __init ipt_netflow_init(void)
57015702
if (!aggregation)
57025703
aggregation = aggregation_buf;
57035704
if (aggregation != aggregation_buf) {
5704-
strlcpy(aggregation_buf, aggregation, sizeof(aggregation_buf));
5705+
strscpy(aggregation_buf, aggregation, sizeof(aggregation_buf));
57055706
aggregation = aggregation_buf;
57065707
}
57075708
add_aggregation(aggregation);
@@ -5711,7 +5712,7 @@ static int __init ipt_netflow_init(void)
57115712
if (!sampler)
57125713
sampler = sampler_buf;
57135714
if (sampler != sampler_buf) {
5714-
strlcpy(sampler_buf, sampler, sizeof(sampler_buf));
5715+
strscpy(sampler_buf, sampler, sizeof(sampler_buf));
57155716
sampler = sampler_buf;
57165717
}
57175718
parse_sampler(sampler);
@@ -5728,7 +5729,7 @@ static int __init ipt_netflow_init(void)
57285729
if (!snmp_rules)
57295730
snmp_rules = snmp_rules_buf;
57305731
if (snmp_rules != snmp_rules_buf) {
5731-
strlcpy(snmp_rules_buf, snmp_rules, sizeof(snmp_rules_buf));
5732+
strscpy(snmp_rules_buf, snmp_rules, sizeof(snmp_rules_buf));
57325733
snmp_rules = snmp_rules_buf;
57335734
}
57345735
add_snmp_rules(snmp_rules);

0 commit comments

Comments
 (0)