]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Propagate correct errno values
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 21 Aug 2024 20:42:32 +0000 (22:42 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 22 Aug 2024 21:53:20 +0000 (16:53 -0500)
Make sure that errors never end up with errno being 0. These code paths
negate the errno value to get a negative value to propagate the fact
that an error occurred. -0 would be 0 again so errors are not detected.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/83
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-builtin.c

index 825e3a72f6953d08080ce510d89ed8793fc20fe3..48e2f752dc20eb32367946db691af6e61115f628 100644 (file)
@@ -215,8 +215,10 @@ static bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter,
        size_t linesz, len;
        off_t offset;
 
-       if (iter->pos == iter->size)
-               return false;
+       if (iter->pos == iter->size) {
+               sv_errno = EINVAL;
+               goto fail;
+       }
 
        line = NULL;
 
@@ -230,7 +232,7 @@ static bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter,
 
        dot = strchr(line, '.');
        if (!dot) {
-               sv_errno = errno;
+               sv_errno = EINVAL;
                ERR(iter->ctx, "kmod_builtin_iter_get_modname: unexpected string without modname prefix\n");
                goto fail;
        }