]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: remove getdelim() buffer null check
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 7 May 2025 17:46:55 +0000 (18:46 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 20 May 2025 02:51:44 +0000 (21:51 -0500)
As per the manual getdelim(3):
   The buffer is null-terminated and ...

Remove the local check and inline the function call. As a nice result,
we no longer set the errno and the context of feof() is obvious.

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 06ff4ab4f7bc769c87704d3a80573e3791536ebc..26c9e51c228a3f7e9255c27c8fca2d4fc6e6377f 100644 (file)
@@ -62,19 +62,6 @@ static void kmod_builtin_info_release(struct kmod_builtin_info *info)
        fclose(info->fp);
 }
 
-static ssize_t get_string(struct kmod_builtin_info *info)
-{
-       ssize_t len;
-
-       len = getdelim(&info->buf, &info->bufsz, '\0', info->fp);
-       if (len > 0 && info->buf[len] != '\0') {
-               errno = EINVAL;
-               len = -1;
-       }
-
-       return len;
-}
-
 static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname,
                           struct strbuf *buf)
 {
@@ -84,11 +71,11 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname,
        for (count = 0; count < INTPTR_MAX;) {
                char *dot, *line;
 
-               n = get_string(info);
+               n = getdelim(&info->buf, &info->bufsz, '\0', info->fp);
                if (n == -1) {
                        if (!feof(info->fp)) {
                                count = -errno;
-                               ERR(info->ctx, "get_string: %m\n");
+                               ERR(info->ctx, "get_strings: %m\n");
                        }
                        break;
                }