From 3a50688558f18cfb250b2e70bc34464a8e089d32 Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Tue, 20 Jun 2023 09:34:47 +0300
Subject: [PATCH] Fix rpmDigestBundleFinal() and Update() return code on
 invalid arguments

Discovered via #2548, these functions merrily return zero for success
when passed NULL data. In rpm nothing bothers to check for their return
codes but it doesn't mean it's the right thing to do
---
 rpmio/digest.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/rpmio/digest.c b/rpmio/digest.c
index 1975fe6b9..9c679d820 100644
--- a/rpmio/digest.c
+++ b/rpmio/digest.c
@@ -77,8 +77,9 @@ int rpmDigestBundleAddID(rpmDigestBundle bundle, int algo, int id,
 }
 int rpmDigestBundleUpdate(rpmDigestBundle bundle, const void *data, size_t len)
 {
-    int rc = 0;
+    int rc = -1;
     if (bundle && data && len > 0) {
+	rc = 0;
 	for (int i = 0; i <= bundle->index_max; i++) {
 	    if (bundle->ids[i] > 0)
 		rc += rpmDigestUpdate(bundle->digests[i], data, len);
@@ -91,7 +92,7 @@ int rpmDigestBundleUpdate(rpmDigestBundle bundle, const void *data, size_t len)
 int rpmDigestBundleFinal(rpmDigestBundle bundle, int id,
 			 void ** datap, size_t * lenp, int asAscii)
 {
-    int rc = 0;
+    int rc = -1;
     int ix = findID(bundle, id);
 
     if (ix >= 0) {
-- 
2.27.0

