File: | build-scan/../src/network/networkd-network-bus.c |
Warning: | line 69, column 21 Potential leak of memory pointed to by 'name' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include "alloc-util.h" | |||
4 | #include "ether-addr-util.h" | |||
5 | #include "networkd-manager.h" | |||
6 | #include "string-util.h" | |||
7 | #include "strv.h" | |||
8 | ||||
9 | static int property_get_ether_addrs( | |||
10 | sd_bus *bus, | |||
11 | const char *path, | |||
12 | const char *interface, | |||
13 | const char *property, | |||
14 | sd_bus_message *reply, | |||
15 | void *userdata, | |||
16 | sd_bus_error *error) { | |||
17 | ||||
18 | char buf[ETHER_ADDR_TO_STRING_MAX(3*6)]; | |||
19 | const struct ether_addr *p; | |||
20 | Iterator i; | |||
21 | Set *s; | |||
22 | int r; | |||
23 | ||||
24 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-network-bus.c" , 24, __PRETTY_FUNCTION__); } while (0); | |||
25 | assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("reply"), "../src/network/networkd-network-bus.c" , 25, __PRETTY_FUNCTION__); } while (0); | |||
26 | assert(userdata)do { if ((__builtin_expect(!!(!(userdata)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("userdata"), "../src/network/networkd-network-bus.c" , 26, __PRETTY_FUNCTION__); } while (0); | |||
27 | ||||
28 | s = *(Set **) userdata; | |||
29 | ||||
30 | r = sd_bus_message_open_container(reply, 'a', "s"); | |||
31 | if (r < 0) | |||
32 | return r; | |||
33 | ||||
34 | SET_FOREACH(p, s, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); set_iterate((s), &(i), (void**) &(p)); ) { | |||
35 | r = sd_bus_message_append(reply, "s", ether_addr_to_string(p, buf)); | |||
36 | if (r < 0) | |||
37 | return r; | |||
38 | } | |||
39 | ||||
40 | return sd_bus_message_close_container(reply); | |||
41 | } | |||
42 | ||||
43 | const sd_bus_vtable network_vtable[] = { | |||
44 | SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = { .element_size = sizeof(sd_bus_vtable) }, }, }, | |||
45 | ||||
46 | SD_BUS_PROPERTY("Description", "s", NULL, offsetof(Network, description), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "Description", .signature = "s" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Network, description), }, }, }, | |||
47 | SD_BUS_PROPERTY("SourcePath", "s", NULL, offsetof(Network, filename), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "SourcePath", .signature = "s" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Network, filename), }, }, }, | |||
48 | SD_BUS_PROPERTY("MatchMAC", "as", property_get_ether_addrs, offsetof(Network, match_mac), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "MatchMAC", .signature = "as" , .get = property_get_ether_addrs, .set = ((void*)0), .offset = __builtin_offsetof(Network, match_mac), }, }, }, | |||
49 | SD_BUS_PROPERTY("MatchPath", "as", NULL, offsetof(Network, match_path), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "MatchPath", .signature = "as" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Network, match_path), }, }, }, | |||
50 | SD_BUS_PROPERTY("MatchDriver", "as", NULL, offsetof(Network, match_driver), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "MatchDriver", .signature = "as" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Network, match_driver), }, }, }, | |||
51 | SD_BUS_PROPERTY("MatchType", "as", NULL, offsetof(Network, match_type), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "MatchType", .signature = "as" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Network, match_type), }, }, }, | |||
52 | SD_BUS_PROPERTY("MatchName", "as", NULL, offsetof(Network, match_name), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST , .x = { .property = { .member = "MatchName", .signature = "as" , .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof (Network, match_name), }, }, }, | |||
53 | ||||
54 | SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, } | |||
55 | }; | |||
56 | ||||
57 | static char *network_bus_path(Network *network) { | |||
58 | _cleanup_free___attribute__((cleanup(freep))) char *name = NULL((void*)0); | |||
59 | char *networkname, *d, *path; | |||
60 | int r; | |||
61 | ||||
62 | assert(network)do { if ((__builtin_expect(!!(!(network)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("network"), "../src/network/networkd-network-bus.c" , 62, __PRETTY_FUNCTION__); } while (0); | |||
63 | assert(network->filename)do { if ((__builtin_expect(!!(!(network->filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("network->filename"), "../src/network/networkd-network-bus.c" , 63, __PRETTY_FUNCTION__); } while (0); | |||
64 | ||||
65 | name = strdup(network->filename); | |||
66 | if (!name) | |||
67 | return NULL((void*)0); | |||
68 | ||||
69 | networkname = basename(name); | |||
| ||||
70 | ||||
71 | d = strrchr(networkname, '.'); | |||
72 | if (!d) | |||
73 | return NULL((void*)0); | |||
74 | ||||
75 | assert(streq(d, ".network"))do { if ((__builtin_expect(!!(!((strcmp((d),(".network")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(d, \".network\")" ), "../src/network/networkd-network-bus.c", 75, __PRETTY_FUNCTION__ ); } while (0); | |||
76 | ||||
77 | *d = '\0'; | |||
78 | ||||
79 | r = sd_bus_path_encode("/org/freedesktop/network1/network", networkname, &path); | |||
80 | if (r < 0) | |||
81 | return NULL((void*)0); | |||
82 | ||||
83 | return path; | |||
84 | } | |||
85 | ||||
86 | int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { | |||
87 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0); | |||
88 | Manager *m = userdata; | |||
89 | Network *network; | |||
90 | int r; | |||
91 | ||||
92 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-network-bus.c" , 92, __PRETTY_FUNCTION__); } while (0); | |||
| ||||
93 | assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path"), "../src/network/networkd-network-bus.c" , 93, __PRETTY_FUNCTION__); } while (0); | |||
94 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/network/networkd-network-bus.c" , 94, __PRETTY_FUNCTION__); } while (0); | |||
95 | assert(nodes)do { if ((__builtin_expect(!!(!(nodes)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("nodes"), "../src/network/networkd-network-bus.c" , 95, __PRETTY_FUNCTION__); } while (0); | |||
96 | ||||
97 | LIST_FOREACH(networks, network, m->networks)for ((network) = (m->networks); (network); (network) = (network )->networks_next) { | |||
98 | char *p; | |||
99 | ||||
100 | p = network_bus_path(network); | |||
101 | if (!p) | |||
102 | return -ENOMEM12; | |||
103 | ||||
104 | r = strv_consume(&l, p); | |||
105 | if (r < 0) | |||
106 | return r; | |||
107 | } | |||
108 | ||||
109 | *nodes = TAKE_PTR(l)({ typeof(l) _ptr_ = (l); (l) = ((void*)0); _ptr_; }); | |||
110 | ||||
111 | return 1; | |||
112 | } | |||
113 | ||||
114 | int network_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { | |||
115 | Manager *m = userdata; | |||
116 | Network *network; | |||
117 | _cleanup_free___attribute__((cleanup(freep))) char *name = NULL((void*)0); | |||
118 | int r; | |||
119 | ||||
120 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-network-bus.c" , 120, __PRETTY_FUNCTION__); } while (0); | |||
121 | assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path"), "../src/network/networkd-network-bus.c" , 121, __PRETTY_FUNCTION__); } while (0); | |||
122 | assert(interface)do { if ((__builtin_expect(!!(!(interface)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("interface"), "../src/network/networkd-network-bus.c" , 122, __PRETTY_FUNCTION__); } while (0); | |||
123 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/network/networkd-network-bus.c" , 123, __PRETTY_FUNCTION__); } while (0); | |||
124 | assert(found)do { if ((__builtin_expect(!!(!(found)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("found"), "../src/network/networkd-network-bus.c" , 124, __PRETTY_FUNCTION__); } while (0); | |||
125 | ||||
126 | r = sd_bus_path_decode(path, "/org/freedesktop/network1/network", &name); | |||
127 | if (r < 0) | |||
128 | return 0; | |||
129 | ||||
130 | r = network_get_by_name(m, name, &network); | |||
131 | if (r < 0) | |||
132 | return 0; | |||
133 | ||||
134 | *found = network; | |||
135 | ||||
136 | return 1; | |||
137 | } |