commit: 93b42c880a13128663c6ddf2ee1a98b901ede6fa
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon May 25 13:25:15 2020 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon May 25 13:25:15 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=93b42c88
libq/tree: avoid invalid read in tree_foreach_packages
eat_file doesn't return how much data was written, only produced buffer
size, so need to calculate length there
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/tree.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libq/tree.c b/libq/tree.c
index e4c4eb7..eb5f324 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1277,11 +1277,11 @@ tree_close_pkg(tree_pkg_ctx *pkg_ctx)
static int
tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
{
- char *p = ctx->pkgs;
+ char *p;
char *q;
char *c;
char pkgname[_Q_PATH_MAX];
- size_t len = ctx->pkgslen;
+ size_t len;
int ret = 0;
depend_atom *query = ctx->query_atom;
@@ -1307,6 +1307,9 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb
callback, void *priv)
close(fd);
}
+ p = ctx->pkgs;
+ len = strlen(ctx->pkgs); /* sucks, need eat_file change */
+
memset(&meta, 0, sizeof(meta));
do {