Bug Summary

File:build-scan/../src/network/networkd-link-bus.c
Warning:line 61, column 33
Potential leak of memory pointed to by 'l'

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-link-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-link-bus.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include "alloc-util.h"
4#include "bus-util.h"
5#include "networkd-link.h"
6#include "networkd-manager.h"
7#include "parse-util.h"
8#include "strv.h"
9
10static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState)int property_get_operational_state(sd_bus *bus, const char *path
, const char *interface, const char *property, sd_bus_message
*reply, void *userdata, sd_bus_error *error) { LinkOperationalState
*data = userdata; do { if ((__builtin_expect(!!(!(bus)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c"
, 10, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/network/networkd-link-bus.c", 10, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-link-bus.c"
, 10, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "s", link_operstate_to_string((*(data)))); }
;
11static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_administrative_state, link_state, LinkState)int property_get_administrative_state(sd_bus *bus, const char
*path, const char *interface, const char *property, sd_bus_message
*reply, void *userdata, sd_bus_error *error) { LinkState *data
= userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c"
, 11, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/network/networkd-link-bus.c", 11, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-link-bus.c"
, 11, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "s", link_state_to_string((*(data)))); }
;
12
13const sd_bus_vtable link_vtable[] = {
14 SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = {
.element_size = sizeof(sd_bus_vtable) }, }, }
,
15
16 SD_BUS_PROPERTY("OperationalState", "s", property_get_operational_state, offsetof(Link, operstate), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "OperationalState", .signature
= "s", .get = property_get_operational_state, .set = ((void*
)0), .offset = __builtin_offsetof(Link, operstate), }, }, }
,
17 SD_BUS_PROPERTY("AdministrativeState", "s", property_get_administrative_state, offsetof(Link, state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "AdministrativeState", .signature
= "s", .get = property_get_administrative_state, .set = ((void
*)0), .offset = __builtin_offsetof(Link, state), }, }, }
,
18
19 SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, }
20};
21
22static char *link_bus_path(Link *link) {
23 _cleanup_free___attribute__((cleanup(freep))) char *ifindex = NULL((void*)0);
24 char *p;
25 int r;
26
27 assert(link)do { if ((__builtin_expect(!!(!(link)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("link"), "../src/network/networkd-link-bus.c"
, 27, __PRETTY_FUNCTION__); } while (0)
;
28 assert(link->ifindex > 0)do { if ((__builtin_expect(!!(!(link->ifindex > 0)),0))
) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("link->ifindex > 0"
), "../src/network/networkd-link-bus.c", 28, __PRETTY_FUNCTION__
); } while (0)
;
29
30 if (asprintf(&ifindex, "%d", link->ifindex) < 0)
31 return NULL((void*)0);
32
33 r = sd_bus_path_encode("/org/freedesktop/network1/link", ifindex, &p);
34 if (r < 0)
35 return NULL((void*)0);
36
37 return p;
38}
39
40int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
41 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0);
42 Manager *m = userdata;
43 unsigned c = 0;
44 Link *link;
45 Iterator i;
46
47 assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c"
, 47, __PRETTY_FUNCTION__); } while (0)
;
1
Assuming 'bus' is non-null
2
Taking false branch
3
Loop condition is false. Exiting loop
48 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/network/networkd-link-bus.c"
, 48, __PRETTY_FUNCTION__); } while (0)
;
4
Assuming 'path' is non-null
5
Taking false branch
6
Loop condition is false. Exiting loop
49 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/network/networkd-link-bus.c"
, 49, __PRETTY_FUNCTION__); } while (0)
;
7
Assuming 'm' is non-null
8
Taking false branch
9
Loop condition is false. Exiting loop
50 assert(nodes)do { if ((__builtin_expect(!!(!(nodes)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("nodes"), "../src/network/networkd-link-bus.c"
, 50, __PRETTY_FUNCTION__); } while (0)
;
10
Assuming 'nodes' is non-null
11
Taking false branch
12
Loop condition is false. Exiting loop
51
52 l = new0(char*, hashmap_size(m->links) + 1)((char**) calloc((hashmap_size(m->links) + 1), sizeof(char
*)))
;
13
Memory is allocated
53 if (!l)
14
Assuming 'l' is non-null
15
Taking false branch
54 return -ENOMEM12;
55
56 HASHMAP_FOREACH(link, m->links, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->links), &
(i), (void**)&(link), ((void*)0)); )
{
16
Loop condition is true. Entering loop body
57 char *p;
58
59 p = link_bus_path(link);
60 if (!p
16.1
'p' is null
)
17
Taking true branch
61 return -ENOMEM12;
18
Potential leak of memory pointed to by 'l'
62
63 l[c++] = p;
64 }
65
66 l[c] = NULL((void*)0);
67 *nodes = TAKE_PTR(l)({ typeof(l) _ptr_ = (l); (l) = ((void*)0); _ptr_; });
68
69 return 1;
70}
71
72int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
73 _cleanup_free___attribute__((cleanup(freep))) char *identifier = NULL((void*)0);
74 Manager *m = userdata;
75 Link *link;
76 int ifindex, r;
77
78 assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c"
, 78, __PRETTY_FUNCTION__); } while (0)
;
79 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/network/networkd-link-bus.c"
, 79, __PRETTY_FUNCTION__); } while (0)
;
80 assert(interface)do { if ((__builtin_expect(!!(!(interface)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("interface"), "../src/network/networkd-link-bus.c"
, 80, __PRETTY_FUNCTION__); } while (0)
;
81 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/network/networkd-link-bus.c"
, 81, __PRETTY_FUNCTION__); } while (0)
;
82 assert(found)do { if ((__builtin_expect(!!(!(found)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("found"), "../src/network/networkd-link-bus.c"
, 82, __PRETTY_FUNCTION__); } while (0)
;
83
84 r = sd_bus_path_decode(path, "/org/freedesktop/network1/link", &identifier);
85 if (r <= 0)
86 return 0;
87
88 r = parse_ifindex(identifier, &ifindex);
89 if (r < 0)
90 return 0;
91
92 r = link_get(m, ifindex, &link);
93 if (r < 0)
94 return 0;
95
96 *found = link;
97
98 return 1;
99}
100
101int link_send_changed(Link *link, const char *property, ...) {
102 _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0);
103 char **l;
104
105 assert(link)do { if ((__builtin_expect(!!(!(link)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("link"), "../src/network/networkd-link-bus.c"
, 105, __PRETTY_FUNCTION__); } while (0)
;
106 assert(link->manager)do { if ((__builtin_expect(!!(!(link->manager)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("link->manager"), "../src/network/networkd-link-bus.c"
, 106, __PRETTY_FUNCTION__); } while (0)
;
107
108 if (!link->manager->bus)
109 return 0; /* replace with assert when we have kdbus */
110
111 l = strv_from_stdarg_alloca(property)({ char **_l; if (!property) _l = (char**) &property; else
{ size_t _n; va_list _ap; _n = 1; __builtin_va_start(_ap, property
); while (__builtin_va_arg(_ap, char*)) _n++; __builtin_va_end
(_ap); _l = ({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow
(sizeof(char*), _n+1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(char*), _n+1)"), "../src/network/networkd-link-bus.c"
, 111, __PRETTY_FUNCTION__); } while (0); (char**) __builtin_alloca
(sizeof(char*)*(_n+1)); }); _l[_n = 0] = (char*) property; __builtin_va_start
(_ap, property); for (;;) { _l[++_n] = __builtin_va_arg(_ap, char
*); if (!_l[_n]) break; } __builtin_va_end(_ap); } _l; })
;
112
113 p = link_bus_path(link);
114 if (!p)
115 return -ENOMEM12;
116
117 return sd_bus_emit_properties_changed_strv(
118 link->manager->bus,
119 p,
120 "org.freedesktop.network1.Link",
121 l);
122}