From: Yu Watanabe Date: Mon, 16 Sep 2024 00:19:21 +0000 (+0900) Subject: network/sysctl-monitor: fix sanity check in cut_last() X-Git-Tag: v257-rc1~421^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=41afafbf2a1b248bee77d6c9e5d73cee63595bb2;p=thirdparty%2Fsystemd.git network/sysctl-monitor: fix sanity check in cut_last() This also adds basic comment about the return code. Follow-up for 6d9ef22acdeac4b429efb75164341233955484af. --- diff --git a/src/network/bpf/sysctl_monitor/sysctl-monitor.bpf.c b/src/network/bpf/sysctl_monitor/sysctl-monitor.bpf.c index ef154931ce2..e0ec8489d21 100644 --- a/src/network/bpf/sysctl_monitor/sysctl-monitor.bpf.c +++ b/src/network/bpf/sysctl_monitor/sysctl-monitor.bpf.c @@ -36,23 +36,22 @@ struct str { static long cut_last(u32 i, struct str *str) { char *s; - i = str->l - i - 1; - s = str->s + i; - /* Sanity check for the preverifier */ if (i >= str->l) - return 1; + return 1; /* exit from the loop */ + + i = str->l - i - 1; + s = str->s + i; if (*s == 0) - return 0; + return 0; /* continue */ if (*s == '\n' || *s == '\r' || *s == ' ' || *s == '\t') { *s = 0; - - return 0; + return 0; /* continue */ } - return 1; + return 1; /* exit from the loop */ } /* Cut off trailing whitespace and newlines */