michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone
Blob Blame History Raw
From bcdd8505e792fd67c1480d43d987b92a61710e53 Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Tue, 10 Oct 2017 14:43:58 +0300
Subject: [PATCH 06/33] Assume failure in rpmSignFiles()

Doesn't make it any shorter yet, but makes more sense in the next steps.
Just refactoring.
---
 sign/rpmsignfiles.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/sign/rpmsignfiles.c b/sign/rpmsignfiles.c
index 2dcc50400..c1d227a07 100644
--- a/sign/rpmsignfiles.c
+++ b/sign/rpmsignfiles.c
@@ -88,23 +88,24 @@ rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
     uint32_t siglen;
     const char *algoname;
     const char *digest;
-    char *signature;
-    rpmRC rc = RPMRC_OK;
+    char *signature = NULL;
+    rpmRC rc = RPMRC_FAIL;
 
+    rpmtdReset(&digests);
     algo = headerGetNumber(h, RPMTAG_FILEDIGESTALGO);
     if (!algo) {
         /* use default algorithm */
         algo = PGPHASHALGO_MD5;
     } else if (algo < 0 || algo >= ARRAY_SIZE(hash_algo_name)) {
 	rpmlog(RPMLOG_ERR, _("File digest algorithm id is invalid"));
-	return RPMRC_FAIL;
+	goto exit;
     }
 
     diglen = rpmDigestLength(algo);
     algoname = hash_algo_name[algo];
     if (!algoname) {
 	rpmlog(RPMLOG_ERR, _("hash_algo_name failed\n"));
-	return RPMRC_FAIL;
+	goto exit;
     }
 
     headerDel(sigh, RPMTAG_FILESIGNATURELENGTH);
@@ -129,20 +130,19 @@ rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
 	signature = signFile(algoname, digest, diglen, key, keypass);
 	if (!signature) {
 	    rpmlog(RPMLOG_ERR, _("signFile failed\n"));
-	    rc = RPMRC_FAIL;
 	    goto exit;
 	}
 	td.data = &signature;
 	if (!headerPut(sigh, &td, HEADERPUT_APPEND)) {
-	    free(signature);
 	    rpmlog(RPMLOG_ERR, _("headerPutString failed\n"));
-	    rc = RPMRC_FAIL;
 	    goto exit;
 	}
-	free(signature);
+	signature = _free(signature);
     }
+    rc = RPMRC_OK;
 
 exit:
+    free(signature);
     rpmtdFreeData(&digests);
     return rc;
 }
-- 
2.27.0