[PATCH] crypto/x509-utils: fix gnutls error code in crt_init failure path

yujun posted 1 patch 3 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260629111026.281185-1-yujun@kylinos.cn
Maintainers: "Daniel P. Berrangé" <berrange@redhat.com>
crypto/x509-utils.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] crypto/x509-utils: fix gnutls error code in crt_init failure path
Posted by yujun 3 weeks, 5 days ago
qcrypto_get_x509_cert_fingerprint() reports gnutls_strerror(ret) when
gnutls_x509_crt_init() fails, but ret is still the initial value -1.
Store the gnutls return code before formatting the error, matching
other gnutls call sites in the tree.

Fixes: 2183ab6251 ("crypto/x509-utils: Check for error from gnutls_x509_crt_init()")
Signed-off-by: yujun <yujun@kylinos.cn>
---
 crypto/x509-utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/crypto/x509-utils.c b/crypto/x509-utils.c
index 39bb6d4d8c..1843488bca 100644
--- a/crypto/x509-utils.c
+++ b/crypto/x509-utils.c
@@ -46,7 +46,8 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
         return -1;
     }
 
-    if (gnutls_x509_crt_init(&crt) < 0) {
+    ret = gnutls_x509_crt_init(&crt);
+    if (ret < 0) {
         error_setg(errp, "Unable to initialize certificate: %s",
                    gnutls_strerror(ret));
         return -1;
-- 
2.25.1
Re: [PATCH] crypto/x509-utils: fix gnutls error code in crt_init failure path
Posted by Daniel P. Berrangé 3 weeks, 5 days ago
On Mon, Jun 29, 2026 at 07:10:26PM +0800, yujun wrote:
> qcrypto_get_x509_cert_fingerprint() reports gnutls_strerror(ret) when
> gnutls_x509_crt_init() fails, but ret is still the initial value -1.
> Store the gnutls return code before formatting the error, matching
> other gnutls call sites in the tree.
> 
> Fixes: 2183ab6251 ("crypto/x509-utils: Check for error from gnutls_x509_crt_init()")
> Signed-off-by: yujun <yujun@kylinos.cn>
> ---
>  crypto/x509-utils.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

and queued.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|