commit:     09b817763d3b03d9ccee92ddd4fa13edb82d53a9
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 29 13:23:27 2021 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Apr 29 13:23:27 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=09b81776

tree: avoid crash in tree_foreach_packages when category doesn't exist

This can be observed when reading a Packages file that refers to binpkgs
that do not exist.

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

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

diff --git a/libq/tree.c b/libq/tree.c
index a947735..04bf468 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1375,6 +1375,16 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
                                                tree_close_cat(cat);
                                        }
                                        pkg.cat_ctx = cat = tree_open_cat(ctx, 
atom->CATEGORY);
+                                       if (cat == NULL) {
+                                               /* probably dir doesn't exist 
or something, skip
+                                                * this one */
+                                               memset(&meta, 0, sizeof(meta));
+                                               if (len > 0) {  /* hop over \n 
*/
+                                                       p++;
+                                                       len--;
+                                               }
+                                               continue;
+                                       }
                                        cat->pkg_ctxs = (tree_pkg_ctx **)atom;  
/* for name */
                                }
                                pkgnamelen = snprintf(pkgname, sizeof(pkgname),

Reply via email to