From: Emil Velikov Date: Wed, 7 May 2025 13:20:29 +0000 (+0100) Subject: libkmod: don't set errno in strbuf_to_vector() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e0f6a6eab86f99dfc3d33f488b5647af0d8ddeb9;p=thirdparty%2Fkmod.git libkmod: don't set errno in strbuf_to_vector() The function does bounds checking, allocation and copying. In the first instance, we manually set errno (to ENOMEM?) on failure. The realloc() call does the same, implicitly. In practice we don't distinguish between the two failures, so we might as well stop manually setting errno and always assume ENOMEM in the caller. Reference: https://github.com/kmod-project/kmod/issues/244 Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/346 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c index c08626b2..06ff4ab4 100644 --- a/libkmod/libkmod-builtin.c +++ b/libkmod/libkmod-builtin.c @@ -140,10 +140,8 @@ static char **strbuf_to_vector(struct strbuf *buf, size_t count) /* (string vector + NULL) * sizeof(char *) + strbuf_used() */ if (uaddsz_overflow(count, 1, &n) || umulsz_overflow(sizeof(char *), n, &vec_size) || - uaddsz_overflow(strbuf_used(buf), vec_size, &total_size)) { - errno = ENOMEM; + uaddsz_overflow(strbuf_used(buf), vec_size, &total_size)) return NULL; - } vector = realloc(buf->bytes, total_size); if (vector == NULL) @@ -181,7 +179,7 @@ ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname, else if (count > 0) { *modinfo = strbuf_to_vector(&buf, (size_t)count); if (*modinfo == NULL) { - count = -errno; + count = -ENOMEM; ERR(ctx, "strbuf_to_vector: %m\n"); } }