mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-03 14:42:10 +01:00
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
This commit is contained in:
parent
9275be383f
commit
292fd1155a
@ -471,17 +471,22 @@ g_tls_certificate_new_from_pem (const gchar *data,
|
|||||||
gssize length,
|
gssize length,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
GError *child_error = NULL;
|
||||||
gchar *key_pem;
|
gchar *key_pem;
|
||||||
GTlsCertificate *cert;
|
GTlsCertificate *cert;
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, NULL);
|
g_return_val_if_fail (data != NULL, NULL);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
if (length == -1)
|
if (length == -1)
|
||||||
length = strlen (data);
|
length = strlen (data);
|
||||||
|
|
||||||
key_pem = parse_private_key (data, length, FALSE, error);
|
key_pem = parse_private_key (data, length, FALSE, &child_error);
|
||||||
if (error && *error)
|
if (child_error != NULL)
|
||||||
|
{
|
||||||
|
g_propagate_error (error, child_error);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
cert = parse_and_create_certificate (data, length, key_pem, error);
|
cert = parse_and_create_certificate (data, length, key_pem, error);
|
||||||
g_free (key_pem);
|
g_free (key_pem);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user