michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone
45afda
From bcdd8505e792fd67c1480d43d987b92a61710e53 Mon Sep 17 00:00:00 2001
45afda
From: Panu Matilainen <pmatilai@redhat.com>
45afda
Date: Tue, 10 Oct 2017 14:43:58 +0300
45afda
Subject: [PATCH 06/33] Assume failure in rpmSignFiles()
45afda
45afda
Doesn't make it any shorter yet, but makes more sense in the next steps.
45afda
Just refactoring.
45afda
---
45afda
 sign/rpmsignfiles.c | 16 ++++++++--------
45afda
 1 file changed, 8 insertions(+), 8 deletions(-)
45afda
45afda
diff --git a/sign/rpmsignfiles.c b/sign/rpmsignfiles.c
45afda
index 2dcc50400..c1d227a07 100644
45afda
--- a/sign/rpmsignfiles.c
45afda
+++ b/sign/rpmsignfiles.c
45afda
@@ -88,23 +88,24 @@ rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
45afda
     uint32_t siglen;
45afda
     const char *algoname;
45afda
     const char *digest;
45afda
-    char *signature;
45afda
-    rpmRC rc = RPMRC_OK;
45afda
+    char *signature = NULL;
45afda
+    rpmRC rc = RPMRC_FAIL;
45afda
 
45afda
+    rpmtdReset(&digests);
45afda
     algo = headerGetNumber(h, RPMTAG_FILEDIGESTALGO);
45afda
     if (!algo) {
45afda
         /* use default algorithm */
45afda
         algo = PGPHASHALGO_MD5;
45afda
     } else if (algo < 0 || algo >= ARRAY_SIZE(hash_algo_name)) {
45afda
 	rpmlog(RPMLOG_ERR, _("File digest algorithm id is invalid"));
45afda
-	return RPMRC_FAIL;
45afda
+	goto exit;
45afda
     }
45afda
 
45afda
     diglen = rpmDigestLength(algo);
45afda
     algoname = hash_algo_name[algo];
45afda
     if (!algoname) {
45afda
 	rpmlog(RPMLOG_ERR, _("hash_algo_name failed\n"));
45afda
-	return RPMRC_FAIL;
45afda
+	goto exit;
45afda
     }
45afda
 
45afda
     headerDel(sigh, RPMTAG_FILESIGNATURELENGTH);
45afda
@@ -129,20 +130,19 @@ rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
45afda
 	signature = signFile(algoname, digest, diglen, key, keypass);
45afda
 	if (!signature) {
45afda
 	    rpmlog(RPMLOG_ERR, _("signFile failed\n"));
45afda
-	    rc = RPMRC_FAIL;
45afda
 	    goto exit;
45afda
 	}
45afda
 	td.data = &signature;
45afda
 	if (!headerPut(sigh, &td, HEADERPUT_APPEND)) {
45afda
-	    free(signature);
45afda
 	    rpmlog(RPMLOG_ERR, _("headerPutString failed\n"));
45afda
-	    rc = RPMRC_FAIL;
45afda
 	    goto exit;
45afda
 	}
45afda
-	free(signature);
45afda
+	signature = _free(signature);
45afda
     }
45afda
+    rc = RPMRC_OK;
45afda
 
45afda
 exit:
45afda
+    free(signature);
45afda
     rpmtdFreeData(&digests);
45afda
     return rc;
45afda
 }
45afda
-- 
45afda
2.27.0
45afda