Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
Date: Mon, 14 Jun 2021 09:34:19
Message-Id: 1623512266.f3ce28b07839e478051947ae7f04bc4b798c1345.grobian@gentoo
1 commit: f3ce28b07839e478051947ae7f04bc4b798c1345
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jun 12 15:37:46 2021 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Sat Jun 12 15:37:46 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=f3ce28b0
7
8 libq/tree: avoid crash in tree_close_pkg on virtuals
9
10 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
11
12 libq/tree.c | 9 +++++----
13 1 file changed, 5 insertions(+), 4 deletions(-)
14
15 diff --git a/libq/tree.c b/libq/tree.c
16 index 2180867..39beac8 100644
17 --- a/libq/tree.c
18 +++ b/libq/tree.c
19 @@ -1221,7 +1221,7 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *keyn)
20 ctx->cachetype = CACHE_PACKAGES;
21 if (pkg_ctx->meta == NULL) {
22 /* hrmffff. */
23 - pkg_ctx->fd = 0;
24 + pkg_ctx->fd = -2;
25 pkg_ctx->meta = tree_pkg_read(pkg_ctx);
26 }
27 key = (char **)((char *)&pkg_ctx->meta->Q__data + offset);
28 @@ -1324,7 +1324,7 @@ tree_close_metadata(tree_metadata_xml *meta_ctx)
29 void
30 tree_close_pkg(tree_pkg_ctx *pkg_ctx)
31 {
32 - if (pkg_ctx->fd != -1)
33 + if (pkg_ctx->fd >= 0)
34 close(pkg_ctx->fd);
35 if (pkg_ctx->atom != NULL)
36 atom_implode(pkg_ctx->atom);
37 @@ -1424,7 +1424,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
38 pkg.repo = ctx->repo;
39 pkg.atom = atom;
40 pkg.cat_ctx = cat;
41 - pkg.fd = 0; /* intentional, meta has already been read */
42 + pkg.fd = -2; /* intentional, meta has already been read */
43
44 /* do call callback with pkg_atom (populate cat and pkg) */
45 ret |= callback(&pkg, priv);
46 @@ -1690,7 +1690,8 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv)
47 if (meta != NULL) {
48 pkg->meta = xmalloc(sizeof(*pkg->meta));
49 memcpy(pkg->meta, meta, sizeof(*pkg->meta));
50 - pkg->fd = 0; /* don't try to read, we already got it */
51 + pkg->meta->Q__data = NULL; /* avoid free here */
52 + pkg->fd = -2; /* don't try to read, we already got it */
53 } else {
54 pkg->meta = NULL;
55 }