summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-06-20 12:35:34 +0200
committerGitHub <noreply@github.com>2019-06-20 12:35:34 +0200
commit64ef83139cf84a700b95e8150a458b0bb9f720de (patch)
treed824cbcedcdcddae04c7aebc0b5ecadcb5122d5b
parent0219b3524f414e23589e63c6de6a759811ef8474 (diff)
parent31a9be2372eeef7357dc8c2fd95b1e96305c107d (diff)
downloadsystemd-64ef83139cf84a700b95e8150a458b0bb9f720de.tar.gz
Merge pull request #12837 from yuwata/tree-wide-lgtm-fixes
tree-wide: fix issues found by lgtm
-rw-r--r--src/basic/cgroup-util.c32
-rw-r--r--src/basic/virt.c26
-rw-r--r--src/delta/delta.c12
-rw-r--r--src/getty-generator/getty-generator.c6
-rw-r--r--src/journal/journalctl.c6
-rw-r--r--src/journal/journald-audit.c7
-rw-r--r--src/libsystemd/sd-device/sd-device.c6
-rw-r--r--src/locale/keymap-util.c4
-rw-r--r--src/network/networkd-address.c2
-rw-r--r--src/shared/firewall-util.c4
10 files changed, 67 insertions, 38 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index e6a8b0e0fb..156a360885 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -91,10 +91,9 @@ int cg_read_event(
const char *controller,
const char *path,
const char *event,
- char **val) {
+ char **ret) {
_cleanup_free_ char *events = NULL, *content = NULL;
- char *p, *line;
int r;
r = cg_get_path(controller, path, "cgroup.events", &events);
@@ -105,22 +104,33 @@ int cg_read_event(
if (r < 0)
return r;
- p = content;
- while ((line = strsep(&p, "\n"))) {
- char *key;
+ for (const char *p = content;;) {
+ _cleanup_free_ char *line = NULL, *key = NULL, *val = NULL;
+ const char *q;
- key = strsep(&line, " ");
- if (!key || !line)
+ r = extract_first_word(&p, &line, "\n", 0);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return -ENOENT;
+
+ q = line;
+ r = extract_first_word(&q, &key, " ", 0);
+ if (r < 0)
+ return r;
+ if (r == 0)
return -EINVAL;
- if (strcmp(key, event))
+ if (!streq(key, event))
continue;
- *val = strdup(line);
+ val = strdup(q);
+ if (!val)
+ return -ENOMEM;
+
+ *ret = TAKE_PTR(val);
return 0;
}
-
- return -ENOENT;
}
bool cg_ns_supported(void) {
diff --git a/src/basic/virt.c b/src/basic/virt.c
index 84b2d64b25..7a7400773b 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -198,7 +198,6 @@ static int detect_vm_xen(void) {
/* Returns -errno, or 0 for domU, or 1 for dom0 */
static int detect_vm_xen_dom0(void) {
_cleanup_free_ char *domcap = NULL;
- char *cap, *i;
int r;
r = read_one_line_file(PATH_FEATURES, &domcap);
@@ -229,17 +228,22 @@ static int detect_vm_xen_dom0(void) {
if (r < 0)
return r;
- i = domcap;
- while ((cap = strsep(&i, ",")))
- if (streq(cap, "control_d"))
- break;
- if (!cap) {
- log_debug("Virtualization XEN DomU found (/proc/xen/capabilities)");
- return 0;
- }
+ for (const char *i = domcap;;) {
+ _cleanup_free_ char *cap = NULL;
- log_debug("Virtualization XEN Dom0 ignored (/proc/xen/capabilities)");
- return 1;
+ r = extract_first_word(&i, &cap, ",", 0);
+ if (r < 0)
+ return r;
+ if (r == 0) {
+ log_debug("Virtualization XEN DomU found (/proc/xen/capabilities)");
+ return 0;
+ }
+
+ if (streq(cap, "control_d")) {
+ log_debug("Virtualization XEN Dom0 ignored (/proc/xen/capabilities)");
+ return 1;
+ }
+ }
}
static int detect_vm_hypervisor(void) {
diff --git a/src/delta/delta.c b/src/delta/delta.c
index 63baa74794..08d8867431 100644
--- a/src/delta/delta.c
+++ b/src/delta/delta.c
@@ -371,7 +371,7 @@ static int enumerate_dir(
return 0;
}
-static bool should_skip_path(const char *prefix, const char *suffix) {
+static int should_skip_path(const char *prefix, const char *suffix) {
#if HAVE_SPLIT_USR
_cleanup_free_ char *target = NULL;
const char *p;
@@ -383,10 +383,16 @@ static bool should_skip_path(const char *prefix, const char *suffix) {
return false;
NULSTR_FOREACH(p, prefixes) {
+ _cleanup_free_ char *tmp = NULL;
+
if (path_startswith(dirname, p))
continue;
- if (path_equal(target, strjoina(p, "/", suffix))) {
+ tmp = path_join(p, suffix);
+ if (!tmp)
+ return -ENOMEM;
+
+ if (path_equal(target, tmp)) {
log_debug("%s redirects to %s, skipping.", dirname, target);
return true;
}
@@ -423,7 +429,7 @@ static int process_suffix(const char *suffix, const char *onlyprefix) {
NULSTR_FOREACH(p, prefixes) {
_cleanup_free_ char *t = NULL;
- if (should_skip_path(p, suffix))
+ if (should_skip_path(p, suffix) > 0)
continue;
t = strjoin(p, "/", suffix);
diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c
index 35501b61f5..8610ab6705 100644
--- a/src/getty-generator/getty-generator.c
+++ b/src/getty-generator/getty-generator.c
@@ -189,9 +189,11 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
"sclp_line0",
"ttysclp0",
"3270!tty1") {
- const char *p;
+ _cleanup_free_ char *p = NULL;
- p = strjoina("/sys/class/tty/", j);
+ p = path_join("/sys/class/tty", j);
+ if (!p)
+ return -ENOMEM;
if (access(p, F_OK) < 0)
continue;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index a3eb61e0f1..27518b6363 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1679,9 +1679,11 @@ static int add_syslog_identifier(sd_journal *j) {
assert(j);
STRV_FOREACH(i, arg_syslog_identifier) {
- char *u;
+ _cleanup_free_ char *u = NULL;
- u = strjoina("SYSLOG_IDENTIFIER=", *i);
+ u = strjoin("SYSLOG_IDENTIFIER=", *i);
+ if (!u)
+ return -ENOMEM;
r = sd_journal_add_match(j, u, 0);
if (r < 0)
return r;
diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c
index 71d9282ed5..fae9138ecb 100644
--- a/src/journal/journald-audit.c
+++ b/src/journal/journald-audit.c
@@ -264,8 +264,8 @@ static int map_all_fields(
if (handle_msg) {
v = startswith(p, "msg='");
if (v) {
+ _cleanup_free_ char *c = NULL;
const char *e;
- char *c;
/* Userspace message. It's enclosed in
simple quotation marks, is not
@@ -279,7 +279,10 @@ static int map_all_fields(
if (!e)
return 0; /* don't continue splitting up if the final quotation mark is missing */
- c = strndupa(v, e - v);
+ c = strndup(v, e - v);
+ if (!c)
+ return -ENOMEM;
+
return map_all_fields(c, map_fields_userspace, "AUDIT_FIELD_", false, iov, n_iov_allocated, n_iov);
}
}
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index c2315c03fe..b1572981b1 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -1600,14 +1600,16 @@ static int device_sysattrs_read_all(sd_device *device) {
return r;
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
- char *path;
+ _cleanup_free_ char *path = NULL;
struct stat statbuf;
/* only handle symlinks and regular files */
if (!IN_SET(dent->d_type, DT_LNK, DT_REG))
continue;
- path = strjoina(syspath, "/", dent->d_name);
+ path = path_join(syspath, dent->d_name);
+ if (!path)
+ return -ENOMEM;
if (lstat(path, &statbuf) != 0)
continue;
diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c
index e238e5a124..c7dcd8ad38 100644
--- a/src/locale/keymap-util.c
+++ b/src/locale/keymap-util.c
@@ -648,11 +648,11 @@ int find_legacy_keymap(Context *c, char **ret) {
if (startswith_comma(c->x11_layout, a[1]))
matching = 5;
else {
- char *x;
+ _cleanup_free_ char *x = NULL;
/* If that didn't work, strip off the
* other layouts from the entry, too */
- x = strndupa(a[1], strcspn(a[1], ","));
+ x = strndup(a[1], strcspn(a[1], ","));
if (startswith_comma(c->x11_layout, x))
matching = 1;
}
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index e75a49f614..a207bb0790 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -793,7 +793,7 @@ int config_parse_address(const char *unit,
n->in_addr_peer = buffer;
if (n->family == AF_INET && n->broadcast.s_addr == 0 && n->prefixlen <= 30)
- n->broadcast.s_addr = n->in_addr.in.s_addr | htonl(0xfffffffflu >> n->prefixlen);
+ n->broadcast.s_addr = n->in_addr.in.s_addr | htobe32(0xfffffffflu >> n->prefixlen);
n = NULL;
diff --git a/src/shared/firewall-util.c b/src/shared/firewall-util.c
index cba52fb419..87bc3f76fe 100644
--- a/src/shared/firewall-util.c
+++ b/src/shared/firewall-util.c
@@ -266,9 +266,9 @@ int fw_add_local_dnat(
mr->range[0].flags = NF_NAT_RANGE_PROTO_SPECIFIED|NF_NAT_RANGE_MAP_IPS;
mr->range[0].min_ip = mr->range[0].max_ip = remote->in.s_addr;
if (protocol == IPPROTO_TCP)
- mr->range[0].min.tcp.port = mr->range[0].max.tcp.port = htons(remote_port);
+ mr->range[0].min.tcp.port = mr->range[0].max.tcp.port = htobe16(remote_port);
else
- mr->range[0].min.udp.port = mr->range[0].max.udp.port = htons(remote_port);
+ mr->range[0].min.udp.port = mr->range[0].max.udp.port = htobe16(remote_port);
mask = alloca0(sz);
memset(mask, 0xFF, sz);