]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/sysctl-monitor: fix sanity check in cut_last()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Sep 2024 00:19:21 +0000 (09:19 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Sep 2024 05:36:54 +0000 (14:36 +0900)
This also adds basic comment about the return code.

Follow-up for 6d9ef22acdeac4b429efb75164341233955484af.

src/network/bpf/sysctl_monitor/sysctl-monitor.bpf.c

index ef154931ce280347efa39dd84a2d3b1ce8b10657..e0ec8489d21bec4262fa59c85de95acb2ca703a5 100644 (file)
@@ -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 */