commit:     13b0eecccaeae428c5fcd58b9c7edf9854e154a3
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Feb  1 08:20:42 2024 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Feb  1 08:20:42 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=13b0eecc

libq/tree: handle hypothetical fail in tree_pkg_meta_get_int

When we cannot read all bytes from a file, return an empty string, not
partial garbage.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/tree.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index 15d8267..4678634 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1233,6 +1233,12 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t 
offset, const char *keyn)
                                        p[--s.st_size] = '\0';
                                m->storage->pos += s.st_size + 1;
                        }
+                       else
+                       {
+                               /* hmmm, couldn't read the whole file?!? */
+                               p[0] = '\0';
+                               m->storage->pos++;
+                       }
                        close(fd);
                }
        } else {

Reply via email to