ipq40xx: fritzrepeater-1200: fix MDIO and PHY probing
[openwrt/openwrt.git] / package / network / utils / iptables / patches / 070-extensions-string-Review-parse_string-function.patch
1 From da5b32fb4656ab69fe1156eb7e36c7c961839e8a Mon Sep 17 00:00:00 2001
2 From: Phil Sutter <phil@nwl.cc>
3 Date: Wed, 8 Jun 2022 13:45:13 +0200
4 Subject: [PATCH] extensions: string: Review parse_string() function
5
6 * Compare against sizeof(info->pattern) which is more clear than having
7 to know that this buffer is of size XT_STRING_MAX_PATTERN_SIZE
8
9 * Invert the check and error early to reduce indenting
10
11 * Pass info->patlen to memcpy() to avoid reading past end of 's'
12
13 Signed-off-by: Phil Sutter <phil@nwl.cc>
14 ---
15 extensions/libxt_string.c | 13 ++++++-------
16 1 file changed, 6 insertions(+), 7 deletions(-)
17
18 --- a/extensions/libxt_string.c
19 +++ b/extensions/libxt_string.c
20 @@ -78,14 +78,13 @@ static void string_init(struct xt_entry_
21
22 static void
23 parse_string(const char *s, struct xt_string_info *info)
24 -{
25 +{
26 /* xt_string does not need \0 at the end of the pattern */
27 - if (strlen(s) <= XT_STRING_MAX_PATTERN_SIZE) {
28 - memcpy(info->pattern, s, XT_STRING_MAX_PATTERN_SIZE);
29 - info->patlen = strnlen(s, XT_STRING_MAX_PATTERN_SIZE);
30 - return;
31 - }
32 - xtables_error(PARAMETER_PROBLEM, "STRING too long \"%s\"", s);
33 + if (strlen(s) > sizeof(info->pattern))
34 + xtables_error(PARAMETER_PROBLEM, "STRING too long \"%s\"", s);
35 +
36 + info->patlen = strnlen(s, sizeof(info->pattern));
37 + memcpy(info->pattern, s, info->patlen);
38 }
39
40 static void