libsystemd: make check-pointer-deref clean
Add the needed assert changes to make the code clean for the new check-pointer-deref script.
This commit is contained in:
@@ -2978,7 +2978,6 @@ if spatch.found()
|
||||
# Remove directories from this list as they are cleaned up.
|
||||
coccinelle_exclude = [
|
||||
'src/basic/',
|
||||
'src/libsystemd/',
|
||||
'src/shared/',
|
||||
# libc/ has no assert() or systemd-headers so leave it
|
||||
'src/libc/',
|
||||
|
||||
@@ -358,6 +358,7 @@ _public_ int sd_bus_creds_get_tid(sd_bus_creds *c, pid_t *ret) {
|
||||
|
||||
_public_ int sd_bus_creds_get_selinux_context(sd_bus_creds *c, const char **ret) {
|
||||
assert_return(c, -EINVAL);
|
||||
assert_return(ret, -EINVAL);
|
||||
|
||||
if (!(c->mask & SD_BUS_CREDS_SELINUX_CONTEXT))
|
||||
return -ENODATA;
|
||||
|
||||
@@ -165,6 +165,8 @@ static int errno_to_bus_error_name_new(int error, char **ret) {
|
||||
const char *name;
|
||||
char *n;
|
||||
|
||||
assert(ret);
|
||||
|
||||
/* D-Bus names must not start with a digit. Thus, an name like System.Error.500 would not be legal.
|
||||
* Let's just return 0 if an unknown errno is encountered, which will cause the caller to fall back
|
||||
* to BUS_ERROR_FAILED.
|
||||
|
||||
@@ -263,6 +263,8 @@ bool path_simple_pattern(const char *pattern, const char *value) {
|
||||
}
|
||||
|
||||
int bus_message_type_from_string(const char *s, uint8_t *u) {
|
||||
assert(u);
|
||||
|
||||
if (streq(s, "signal"))
|
||||
*u = SD_BUS_MESSAGE_SIGNAL;
|
||||
else if (streq(s, "method_call"))
|
||||
|
||||
@@ -175,6 +175,8 @@ static int introspect_write_arguments(BusIntrospect *i, const char *signature, c
|
||||
|
||||
assert(i);
|
||||
assert(i->m.f);
|
||||
assert(signature);
|
||||
assert(names);
|
||||
|
||||
for (;;) {
|
||||
size_t l;
|
||||
|
||||
@@ -1704,6 +1704,10 @@ typedef enum {
|
||||
static bool names_are_valid(const char *signature, const char **names, names_flags *flags) {
|
||||
int r;
|
||||
|
||||
assert(signature);
|
||||
assert(names);
|
||||
assert(flags);
|
||||
|
||||
if ((*flags & NAMES_FIRST_PART || *flags & NAMES_SINGLE_PART) && **names != '\0')
|
||||
*flags |= NAMES_PRESENT;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#define SNDBUF_SIZE (8*1024*1024)
|
||||
|
||||
static void iovec_advance(struct iovec iov[], unsigned *idx, size_t size) {
|
||||
assert(idx);
|
||||
|
||||
while (size > 0) {
|
||||
struct iovec *i = iov + *idx;
|
||||
|
||||
@@ -2021,6 +2021,7 @@ static int bus_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) {
|
||||
|
||||
assert(bus);
|
||||
assert(m);
|
||||
assert(idx);
|
||||
|
||||
r = bus_socket_write_message(bus, m, idx);
|
||||
if (r <= 0)
|
||||
|
||||
@@ -177,6 +177,7 @@ static const sd_bus_vtable vtable2[] = {
|
||||
};
|
||||
|
||||
static int enumerator_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
|
||||
assert(nodes);
|
||||
|
||||
if (object_path_startswith("/value", path))
|
||||
ASSERT_NOT_NULL(*nodes = strv_new("/value/c", "/value/b", "/value/a"));
|
||||
@@ -185,6 +186,7 @@ static int enumerator_callback(sd_bus *bus, const char *path, void *userdata, ch
|
||||
}
|
||||
|
||||
static int enumerator2_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
|
||||
assert(nodes);
|
||||
|
||||
if (object_path_startswith("/value/a", path))
|
||||
ASSERT_NOT_NULL(*nodes = strv_new("/value/a/z", "/value/a/x", "/value/a/y"));
|
||||
@@ -195,6 +197,8 @@ static int enumerator2_callback(sd_bus *bus, const char *path, void *userdata, c
|
||||
static int enumerator3_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *reterr_error) {
|
||||
_cleanup_strv_free_ char **v = NULL;
|
||||
|
||||
assert(nodes);
|
||||
|
||||
if (!object_path_startswith("/value/b", path))
|
||||
return 1;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ static struct context c = {};
|
||||
static int happy_finder_object = 0;
|
||||
|
||||
static int happy_finder(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *reterr_error) {
|
||||
assert(found);
|
||||
assert(userdata);
|
||||
assert(userdata == &c);
|
||||
|
||||
|
||||
@@ -783,6 +783,8 @@ int device_monitor_send(
|
||||
|
||||
static void bpf_stmt(struct sock_filter *ins, unsigned *i,
|
||||
unsigned short code, unsigned data) {
|
||||
assert(i);
|
||||
|
||||
ins[(*i)++] = (struct sock_filter) {
|
||||
.code = code,
|
||||
.k = data,
|
||||
@@ -792,6 +794,8 @@ static void bpf_stmt(struct sock_filter *ins, unsigned *i,
|
||||
static void bpf_jmp(struct sock_filter *ins, unsigned *i,
|
||||
unsigned short code, unsigned data,
|
||||
unsigned short jt, unsigned short jf) {
|
||||
assert(i);
|
||||
|
||||
ins[(*i)++] = (struct sock_filter) {
|
||||
.code = code,
|
||||
.jt = jt,
|
||||
|
||||
@@ -5077,6 +5077,7 @@ _public_ int sd_event_get_watchdog(sd_event *e) {
|
||||
_public_ int sd_event_get_iteration(sd_event *e, uint64_t *ret) {
|
||||
assert_return(e, -EINVAL);
|
||||
assert_return(e = event_resolve(e), -ENOPKG);
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(!event_origin_changed(e), -ECHILD);
|
||||
|
||||
*ret = e->iteration;
|
||||
|
||||
@@ -199,6 +199,8 @@ int id128_write_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t id) {
|
||||
}
|
||||
|
||||
void id128_hash_func(const sd_id128_t *p, struct siphash *state) {
|
||||
assert(p);
|
||||
|
||||
siphash24_compress_typesafe(*p, state);
|
||||
}
|
||||
|
||||
|
||||
@@ -2107,6 +2107,8 @@ static int link_entry_into_array(
|
||||
assert(f->header);
|
||||
assert(first);
|
||||
assert(idx);
|
||||
POINTER_MAY_BE_NULL(tail);
|
||||
POINTER_MAY_BE_NULL(tidx);
|
||||
assert(p > 0);
|
||||
|
||||
a = tail ? le32toh(*tail) : le64toh(*first);
|
||||
|
||||
@@ -23,6 +23,8 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
|
||||
unsigned n, i, j, k;
|
||||
usec_t z, x;
|
||||
|
||||
assert(last_usec);
|
||||
|
||||
if (!on_tty())
|
||||
return;
|
||||
|
||||
|
||||
@@ -591,6 +591,8 @@ TEST(sequence_numbers) {
|
||||
}
|
||||
|
||||
static int expected_result(uint64_t needle, const uint64_t *candidates, const uint64_t *offset, size_t n, direction_t direction, uint64_t *ret) {
|
||||
assert(ret);
|
||||
|
||||
switch (direction) {
|
||||
case DIRECTION_DOWN:
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
@@ -625,6 +627,8 @@ static int expected_result(uint64_t needle, const uint64_t *candidates, const ui
|
||||
}
|
||||
|
||||
static int expected_result_next(uint64_t needle, const uint64_t *candidates, const uint64_t *offset, size_t n, direction_t direction, uint64_t *ret) {
|
||||
assert(ret);
|
||||
|
||||
switch (direction) {
|
||||
case DIRECTION_DOWN:
|
||||
for (size_t i = 0; i < n; i++)
|
||||
|
||||
@@ -385,6 +385,8 @@ int sd_rtnl_message_new_addr_update(
|
||||
int family) {
|
||||
int r;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
|
||||
r = sd_rtnl_message_new_addr(rtnl, ret, RTM_NEWADDR, ifindex, family);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
Reference in New Issue
Block a user