From 30071f51e539fb86750a5b8251ddda2f6e1262c4 Mon Sep 17 00:00:00 2001 From: dongshengyuan <545258830@qq.com> Date: Tue, 16 Jun 2026 14:44:15 +0800 Subject: [PATCH] misc: fix minor error handling issues fstab-generator: pass k instead of r to bus_error_message() so the fallback error string reflects the actual bus call failure, not the accumulated result that was reset to 0 earlier. networkd-ndisc: return -ENOMEM when newdup() fails, since r is 0 at that point and the OOM would otherwise be reported as success. storagetm: add missing NULL check after strndup() for attr_model, matching the pattern already used for attr_firmware and attr_serial. Signed-off-by: dongshengyuan Co-developed-by: Claude Opus 4.8 (1M context) --- src/fstab-generator/fstab-generator.c | 2 +- src/network/networkd-ndisc.c | 2 +- src/storagetm/storagetm.c | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index f24974be5c..3a5ce47691 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -801,7 +801,7 @@ static int do_daemon_reload(void) { k = bus_call_method(bus, bus_systemd_mgr, "StartUnit", &error, NULL, "ss", unit, "replace"); if (k < 0) { - log_error_errno(k, "Failed to (re)start %s: %s", unit, bus_error_message(&error, r)); + log_error_errno(k, "Failed to (re)start %s: %s", unit, bus_error_message(&error, k)); RET_GATHER(r, k); } } diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 4e15da9588..08bb2bfd12 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -2243,7 +2243,7 @@ static int sd_dns_resolver_copy(const sd_dns_resolver *a, sd_dns_resolver *b) { /* addrs, n_addrs */ c.addrs = newdup(union in_addr_union, a->addrs, a->n_addrs); if (!c.addrs) - return r; + return -ENOMEM; c.n_addrs = a->n_addrs; /* dohpath */ diff --git a/src/storagetm/storagetm.c b/src/storagetm/storagetm.c index 384e88f7b8..2d59ab1408 100644 --- a/src/storagetm/storagetm.c +++ b/src/storagetm/storagetm.c @@ -258,6 +258,8 @@ static int nvme_subsystem_write_metadata(int subsystem_fd, sd_device *device) { } if (w) { _cleanup_free_ char *truncated = strndup(w, 40); /* kernel refuses more than 40 chars (as per nvme spec) */ + if (!truncated) + return log_oom(); /* The default string stored in 'attr_model' is "Linux" btw. */ r = write_string_file_at(subsystem_fd, "attr_model", truncated, WRITE_STRING_FILE_DISABLE_BUFFER);