[glib] gtlscertificate: Fix error reporting if a GError is not passed in
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gtlscertificate: Fix error reporting if a GError is not passed in
- Date: Sat, 3 Oct 2015 09:59:53 +0000 (UTC)
commit 292fd1155ae502df9aadc343cdbbd5d6b3149090
Author: Philip Withnall <philip withnall collabora co uk>
Date: Sat Oct 3 10:58:18 2015 +0100
gtlscertificate: Fix error reporting if a GError is not passed in
If the certificate constructor is called as:
g_tls_certificate_new_from_pem (data, length, NULL);
and PEM parsing fails for the private key, the function would have
continued to try and create a certificate using a NULL key_pem value,
which would have failed or crashed.
Use g_propagate_error() correctly to avoid this.
Coverity CID: 1325403
gio/gtlscertificate.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gio/gtlscertificate.c b/gio/gtlscertificate.c
index d7dff70..e43c2ce 100644
--- a/gio/gtlscertificate.c
+++ b/gio/gtlscertificate.c
@@ -471,17 +471,22 @@ g_tls_certificate_new_from_pem (const gchar *data,
gssize length,
GError **error)
{
+ GError *child_error = NULL;
gchar *key_pem;
GTlsCertificate *cert;
g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (length == -1)
length = strlen (data);
- key_pem = parse_private_key (data, length, FALSE, error);
- if (error && *error)
- return NULL;
+ key_pem = parse_private_key (data, length, FALSE, &child_error);
+ if (child_error != NULL)
+ {
+ g_propagate_error (error, child_error);
+ return NULL;
+ }
cert = parse_and_create_certificate (data, length, key_pem, error);
g_free (key_pem);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]