]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: fix dumps for non-alias indexes
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 7 Nov 2024 19:43:49 +0000 (13:43 -0600)
For non-alias indexes prefix is an empty string, where
strbuf_pushchars() returns the number of characters added to the strbuf.

Since those are zero, we end up completely skipping the dump process.

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Fixes: 889d02b1 ("libkmod: check strbuf return values")
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-index.c

index 2ed8752d8cba97ecbc1d07ecf7701b3c48f5360c..9e1ba43d9eb0518b26ab2add840efb97436e2efd 100644 (file)
@@ -401,7 +401,7 @@ void index_dump(struct index_file *in, int fd, const char *prefix)
                return;
 
        strbuf_init(&buf);
-       if (strbuf_pushchars(&buf, prefix))
+       if (prefix[0] == '\0' || strbuf_pushchars(&buf, prefix))
                index_dump_node(root, &buf, fd);
        strbuf_release(&buf);
 }
@@ -866,7 +866,7 @@ void index_mm_dump(struct index_mm *idx, int fd, const char *prefix)
                return;
 
        strbuf_init(&buf);
-       if (strbuf_pushchars(&buf, prefix))
+       if (prefix[0] == '\0' || strbuf_pushchars(&buf, prefix))
                index_mm_dump_node(root, &buf, fd);
        strbuf_release(&buf);
 }