]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: don't set errno in strbuf_to_vector()
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 7 May 2025 13:20:29 +0000 (14:20 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 20 May 2025 02:51:44 +0000 (21:51 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/346
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-builtin.c

index c08626b2f7bd7c9feae8a0d3dcf1a4f874090cf3..06ff4ab4f7bc769c87704d3a80573e3791536ebc 100644 (file)
@@ -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");
                }
        }