From 6e8ca48cbb22c328deab56b1740be04ea7ddba6e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 11 Jan 2012 12:04:34 -0600 Subject: Reorder some operations in sig check for efficiency We don't need to open the data to be checked if we don't have a signature to check against, so postpone that open until we know we have either the base64_data or a valid signature file. Signed-off-by: Dan McGee --- lib/libalpm/signing.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index c4cb077f..3ff83ba0 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -430,8 +430,13 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path, if(!base64_sig) { sigpath = _alpm_sigpath(handle, path); - /* this will just help debugging */ - _alpm_access(handle, NULL, sigpath, R_OK); + if(_alpm_access(handle, NULL, sigpath, R_OK) != 0 + || (sigfile = fopen(sigpath, "rb")) == NULL) { + _alpm_log(handle, ALPM_LOG_DEBUG, "sig path %s could not be opened\n", + sigpath); + handle->pm_errno = ALPM_ERR_SIG_MISSING; + goto error; + } } /* does the file we are verifying exist? */ @@ -441,17 +446,6 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path, goto error; } - /* does the sig file exist (if we didn't get the data directly)? */ - if(!base64_sig) { - sigfile = fopen(sigpath, "rb"); - if(sigfile == NULL) { - _alpm_log(handle, ALPM_LOG_DEBUG, "sig path %s could not be opened\n", - sigpath); - handle->pm_errno = ALPM_ERR_SIG_MISSING; - goto error; - } - } - if(init_gpgme(handle)) { /* pm_errno was set in gpgme_init() */ goto error; -- cgit v1.2.3-70-g09d2