]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: handle read_char errors
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 10 Sep 2024 16:13:41 +0000 (18:13 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 17 Sep 2024 03:22:39 +0000 (22:22 -0500)
If read_char fails, stop operations and return an error instead.

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/123
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-index.c

index 6f6c2f4e7685e10a4f238b6bd7fd917319bbed9a..77d43dba8a947e8ef30c5edce0b95d7760b48bef 100644 (file)
@@ -196,7 +196,7 @@ static ssize_t buf_freadchars(struct strbuf *buf, FILE *in)
        int ch;
 
        while ((ch = read_char(in))) {
-               if (!strbuf_pushchar(buf, ch))
+               if (ch == EOF || !strbuf_pushchar(buf, ch))
                        return -1;
                i++;
        }
@@ -240,15 +240,19 @@ static struct index_node_f *index_read(FILE *in, uint32_t offset)
                prefix = NOFAIL(strdup(""));
 
        if (offset & INDEX_NODE_CHILDS) {
-               char first = read_char(in);
-               char last = read_char(in);
+               int first = read_char(in);
+               int last = read_char(in);
+
+               if (first == EOF || last == EOF)
+                       goto err;
+
                child_count = last - first + 1;
 
                node = NOFAIL(malloc(sizeof(struct index_node_f) +
                                     sizeof(uint32_t) * child_count));
 
-               node->first = first;
-               node->last = last;
+               node->first = (unsigned char) first;
+               node->last = (unsigned char) last;
 
                for (i = 0; i < child_count; i++)
                        if (read_long(in, &node->children[i]) < 0)