From 673192494c129975b605541ee688143ecf2a6416 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Dec 2017 19:47:46 +0100 Subject: [PATCH 1/3] coccinelle: automatically rewrite memset() to zero() or memzero() where we can We are pretty good at this already, hence only a single case is actually found by this. --- coccinelle/memzero.cocci | 30 ++++++++++++++++++++++++++++++ src/journal/journald-server.c | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 coccinelle/memzero.cocci diff --git a/coccinelle/memzero.cocci b/coccinelle/memzero.cocci new file mode 100644 index 0000000000..ebdc3f6a2a --- /dev/null +++ b/coccinelle/memzero.cocci @@ -0,0 +1,30 @@ +@@ +expression s; +@@ +- memset(&s, 0, sizeof(s)) ++ zero(s) +@@ +expression s; +@@ +- memset(s, 0, sizeof(*s)) ++ zero(*s) +@@ +expression s; +@@ +- bzero(&s, sizeof(s)) ++ zero(s) +@@ +expression s; +@@ +- bzero(s, sizeof(*s)) ++ zero(*s) +@@ +expression a, b; +@@ +- memset(a, 0, b) ++ memzero(a, b) +@@ +expression a, b; +@@ +- bzero(a, b) ++ memzero(a, b) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 48375f9c3e..d68e3a8d51 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -133,7 +133,7 @@ static int determine_path_usage(Server *s, const char *path, uint64_t *ret_used, } static void cache_space_invalidate(JournalStorageSpace *space) { - memset(space, 0, sizeof(*space)); + zero(*space); } static int cache_space_refresh(Server *s, JournalStorage *storage) { From ab27086387c29886febd27e5366bc1b3eea2df06 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Dec 2017 19:50:43 +0100 Subject: [PATCH 2/3] link-config: make initialization to -1 less weird memset() is weird anyway, since it expects an "int" as second parameter, which it then uses as a byte, i.e. as uint8_t or something like that. But by passing -1 to it, things get particularly weird, as that relies on sign expansion to do the right thing. --- src/udev/net/link-config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 89891f9e27..9fc9c1176a 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -171,7 +171,7 @@ static int load_link(link_config_ctx *ctx, const char *filename) { link->port = _NET_DEV_PORT_INVALID; link->autonegotiation = -1; - memset(&link->features, -1, sizeof(link->features)); + memset(&link->features, 0xFF, sizeof(link->features)); r = config_parse(NULL, filename, file, "Match\0Link\0Ethernet\0", From c805d41c9bed0b805d3763ebec88d7cf8b048dd6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Dec 2017 20:09:45 +0100 Subject: [PATCH 3/3] udev-link-config: add missing OOM check --- src/udev/net/link-config.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 9fc9c1176a..92d41a6e95 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -186,6 +186,8 @@ static int load_link(link_config_ctx *ctx, const char *filename) { return -ERANGE; link->filename = strdup(filename); + if (!link->filename) + return log_oom(); LIST_PREPEND(links, ctx->links, link); link = NULL;