Bug Summary

File:build-scan/../src/network/networkd-network-bus.c
Warning:line 69, column 21
Potential leak of memory pointed to by 'name'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name networkd-network-bus.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I src/network/libnetworkd-core.a.p -I src/network -I ../src/network -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -I . -I .. -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/network/networkd-network-bus.c
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
9static 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
43const 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
57static 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)
;
15
Taking false branch
16
Loop condition is false. Exiting loop
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)
;
17
Assuming field 'filename' is non-null
18
Taking false branch
19
Loop condition is false. Exiting loop
64
65 name = strdup(network->filename);
20
Memory is allocated
66 if (!name)
21
Assuming 'name' is non-null
22
Taking false branch
67 return NULL((void*)0);
68
69 networkname = basename(name);
23
Potential leak of memory pointed to by '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
86int 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)
;
1
Assuming 'bus' is non-null
2
Taking false branch
3
Loop condition is false. Exiting loop
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)
;
4
Assuming 'path' is non-null
5
Taking false branch
6
Loop condition is false. Exiting loop
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)
;
7
Assuming 'm' is non-null
8
Taking false branch
9
Loop condition is false. Exiting loop
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)
;
10
Assuming 'nodes' is non-null
11
Taking false branch
12
Loop condition is false. Exiting loop
96
97 LIST_FOREACH(networks, network, m->networks)for ((network) = (m->networks); (network); (network) = (network
)->networks_next)
{
13
Loop condition is true. Entering loop body
98 char *p;
99
100 p = network_bus_path(network);
14
Calling 'network_bus_path'
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
114int 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}