Michal Domonkos f3557c
From fd57fc716231c8296d340fdb4c0f6eac176f7f7c Mon Sep 17 00:00:00 2001
Michal Domonkos f3557c
From: Florian Festi <ffesti@redhat.com>
Michal Domonkos f3557c
Date: Fri, 20 Aug 2021 15:14:16 +0200
Michal Domonkos f3557c
Subject: [PATCH] Don't segfault on missing priority tag
Michal Domonkos f3557c
Michal Domonkos f3557c
Resolves: #1636
Michal Domonkos f3557c
Related: #1638
Michal Domonkos f3557c
---
Michal Domonkos f3557c
 lib/rpmtriggers.c | 7 +++++--
Michal Domonkos f3557c
 1 file changed, 5 insertions(+), 2 deletions(-)
Michal Domonkos f3557c
Michal Domonkos f3557c
diff --git a/lib/rpmtriggers.c b/lib/rpmtriggers.c
Michal Domonkos f3557c
index fc809a65e..d541974e8 100644
Michal Domonkos f3557c
--- a/lib/rpmtriggers.c
Michal Domonkos f3557c
+++ b/lib/rpmtriggers.c
Michal Domonkos f3557c
@@ -517,7 +517,8 @@ rpmRC runFileTriggers(rpmts ts, rpmte te, rpmsenseFlags sense,
Michal Domonkos f3557c
 	if (matchFunc(ts, te, pfx, sense)) {
Michal Domonkos f3557c
 	    for (i = 0; i < rpmdbIndexIteratorNumPkgs(ii); i++) {
Michal Domonkos f3557c
 		struct rpmtd_s priorities;
Michal Domonkos f3557c
-		unsigned int priority;
Michal Domonkos f3557c
+		unsigned int priority = 0;
Michal Domonkos f3557c
+		unsigned int *priority_ptr;
Michal Domonkos f3557c
 		unsigned int offset = rpmdbIndexIteratorPkgOffset(ii, i);
Michal Domonkos f3557c
 		unsigned int tix = rpmdbIndexIteratorTagNum(ii, i);
Michal Domonkos f3557c
 
Michal Domonkos f3557c
@@ -535,7 +536,9 @@ rpmRC runFileTriggers(rpmts ts, rpmte te, rpmsenseFlags sense,
Michal Domonkos f3557c
 		trigH = rpmdbGetHeaderAt(rpmtsGetRdb(ts), offset);
Michal Domonkos f3557c
 		headerGet(trigH, priorityTag, &priorities, HEADERGET_MINMEM);
Michal Domonkos f3557c
 		rpmtdSetIndex(&priorities, tix);
Michal Domonkos f3557c
-		priority = *rpmtdGetUint32(&priorities);
Michal Domonkos f3557c
+		priority_ptr = rpmtdGetUint32(&priorities);
Michal Domonkos f3557c
+		if (priority_ptr)
Michal Domonkos f3557c
+		    priority = *priority_ptr;
Michal Domonkos f3557c
 		headerFree(trigH);
Michal Domonkos f3557c
 
Michal Domonkos f3557c
 		/* Store file trigger in array */
Michal Domonkos f3557c
-- 
Michal Domonkos f3557c
2.45.1
Michal Domonkos f3557c