From 1eeb00f776eb9f78c4ec06f7891ce602cafb619e Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Wed, 4 Jun 2025 17:16:25 +0100 Subject: [PATCH] libkmod: return ENOMEM when strbuf_pushchar(s) fails Currently get_strings() assumes that errno is set when either function fails. This is not the case when our overflow checks kick in. The other case where these functions fail is memory exhaustion. In practice we cannot do anything if either of those trigger, plus I don't see a compelling reason to set errno to EOVERFLOW... Something which other parts of the codebase don't do. So let's just return ENOMEM and avoid the corner case of returning success from get_strings(), when it should be failing. Fixes: 1005e99e ("libkmod: refactor builtin module handling") Fixes: 952bf223 ("strbuf: Add strbuf_reserve_extra()") Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/368 Signed-off-by: Lucas De Marchi --- libkmod/libkmod-builtin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c index 26c9e51c..f54d876b 100644 --- a/libkmod/libkmod-builtin.c +++ b/libkmod/libkmod-builtin.c @@ -99,7 +99,7 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname, break; } if (!strbuf_pushchars(buf, dot + 1) || !strbuf_pushchar(buf, '\0')) { - count = -errno; + count = -ENOMEM; ERR(info->ctx, "get_strings: " "failed to append modinfo string\n"); return count; -- 2.47.2