]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: plug some memleaks in rule serialization/deserialization
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 27 Nov 2017 12:01:41 +0000 (12:01 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Nov 2017 08:25:38 +0000 (09:25 +0100)
This fixes the (mostly theoretical, since we're only parsing data that we write
ourselves) memleak when iif or oif is deserialized multiple times. Unfortunately
it does not fix the memleak when rule is freed, but that'll require a bigger
effort.

src/network/networkd-routing-policy-rule.c
src/network/test-routing-policy-rule.c

index 20f748944eaff22d59f8b9608cb08e14ee0ace0e..f4b3b7180b68c525561a0d384e3070449235cdd8 100644 (file)
@@ -1017,13 +1017,12 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
                                 }
                         } else if (streq(a, "iif")) {
 
-                                rule->iif = strdup(b);
-                                if (!rule->iif)
+                                if (free_and_strdup(&rule->iif, b) < 0)
                                         return log_oom();
+
                         } else if (streq(a, "oif")) {
 
-                                rule->oif = strdup(b);
-                                if (!rule->oif)
+                                if (free_and_strdup(&rule->oif, b) < 0)
                                         return log_oom();
                         }
                 }
index c619dbc1594387959d93a94b2d4692337cd4727d..fc6eb5626d0e0bc20ee4c04fa12598a549a1c582 100644 (file)
@@ -96,5 +96,9 @@ int main(int argc, char **argv) {
         test_rule_serialization("outgoing interface",
                                 "RULE=from=1::2/64 to=2::3/64 oif=eth0 table=1", NULL);
 
+        test_rule_serialization("freeing interface names",
+                                "RULE=from=1::2/64 to=2::3/64 iif=e0 iif=e1 oif=e0 oif=e1 table=1",
+                                "RULE=from=1::2/64 to=2::3/64 iif=e1 oif=e1 table=1");
+
         return 0;
 }