]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/route-metric: invalidate [Route] section if an invalid string is specified 30811/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 7 Jan 2024 02:53:27 +0000 (11:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 7 Jan 2024 05:04:00 +0000 (14:04 +0900)
Follow-up for 18c4c5d84f756b144a1823f3de8bc0e61264b976.

src/network/networkd-route-metric.c
src/shared/conf-parser.c

index 43480bd3831b3f2c19fae13fa2db22533ac0a15a..67841cb67ea41e64b20b9c1da6123fa1092ce5a3 100644 (file)
@@ -435,15 +435,12 @@ int config_parse_route_metric_tcp_congestion(
                 void *data,
                 void *userdata) {
 
-        Network *network = userdata;
+        Network *network = ASSERT_PTR(userdata);
         _cleanup_(route_free_or_set_invalidp) Route *route = NULL;
         int r;
 
         assert(filename);
-        assert(section);
-        assert(lvalue);
         assert(rvalue);
-        assert(data);
 
         r = route_new_static(network, filename, section_line, &route);
         if (r == -ENOMEM)
@@ -456,7 +453,7 @@ int config_parse_route_metric_tcp_congestion(
 
         r = config_parse_string(unit, filename, line, section, section_line, lvalue, 0,
                                 rvalue, &route->metric.tcp_congestion_control_algo, userdata);
-        if (r < 0)
+        if (r <= 0)
                 return r;
 
         TAKE_PTR(route);
index 1d201528ace4bc50a4256bbb5f27c652a983d219..d8a2c47209d83eaac4333e26024e2d93b1362bff 100644 (file)
@@ -1088,6 +1088,7 @@ int config_parse_string(
                 void *userdata) {
 
         char **s = ASSERT_PTR(data);
+        int r;
 
         assert(filename);
         assert(lvalue);
@@ -1095,7 +1096,7 @@ int config_parse_string(
 
         if (isempty(rvalue)) {
                 *s = mfree(*s);
-                return 0;
+                return 1;
         }
 
         if (FLAGS_SET(ltype, CONFIG_PARSE_STRING_SAFE) && !string_is_safe(rvalue)) {
@@ -1116,7 +1117,11 @@ int config_parse_string(
                 return 0;
         }
 
-        return free_and_strdup_warn(s, empty_to_null(rvalue));
+        r = free_and_strdup_warn(s, empty_to_null(rvalue));
+        if (r < 0)
+                return r;
+
+        return 1;
 }
 
 int config_parse_dns_name(