Skip to content

Commit

Permalink
Merge pull request #60 from ejoerns/v0/topic/error-handling-fixes
Browse files Browse the repository at this point in the history
Error handling fixes
  • Loading branch information
jluebbe committed Aug 24, 2016
2 parents b58e926 + e4148fc commit f57985c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bootchooser.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static gboolean barebox_state_set(GPtrArray *pairs) {
sub = g_subprocess_newv((const gchar * const *)args->pdata,
G_SUBPROCESS_FLAGS_NONE, &error);
if (!sub) {
g_warning("getting state failed: %s", error->message);
g_warning("starting " BAREBOX_STATE_NAME " failed: %s", error->message);
g_clear_error(&error);
goto out;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ gboolean create_bundle(const gchar *bundlename, const gchar *contentdir, GError
error,
ierror,
"failed signing bundle: ");
res = FALSE;
goto out;
}

Expand All @@ -196,6 +197,7 @@ gboolean create_bundle(const gchar *bundlename, const gchar *contentdir, GError
error,
ierror,
"failed to open bundle for appending: ");
res = FALSE;
goto out;
}

Expand Down Expand Up @@ -230,8 +232,6 @@ gboolean create_bundle(const gchar *bundlename, const gchar *contentdir, GError
goto out;
}


res = TRUE;
out:
g_clear_object(&bundlestream);
g_clear_object(&bundlefile);
Expand Down
14 changes: 12 additions & 2 deletions src/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void signature_init(void) {
static EVP_PKEY *load_key(const gchar *keyfile, GError **error) {
EVP_PKEY *res = NULL;
BIO *key = NULL;
unsigned long err;
const gchar *data;
int flags;

g_assert(error == NULL || *error == NULL);

Expand All @@ -50,11 +53,13 @@ static EVP_PKEY *load_key(const gchar *keyfile, GError **error) {

res = PEM_read_bio_PrivateKey(key, NULL, NULL, NULL);
if (res == NULL) {
err = ERR_get_error_line_data(NULL, NULL, &data, &flags);
g_set_error(
error,
R_SIGNATURE_ERROR,
R_SIGNATURE_ERROR_PARSE_ERROR,
"failed to parse key file '%s'", keyfile);
"failed to parse key file '%s': %s", keyfile,
(flags & ERR_TXT_STRING) ? data : ERR_error_string(err, NULL));
goto out;
}
out:
Expand All @@ -65,6 +70,9 @@ static EVP_PKEY *load_key(const gchar *keyfile, GError **error) {
static X509 *load_cert(const gchar *certfile, GError **error) {
X509 *res = NULL;
BIO *cert = NULL;
unsigned long err;
const gchar *data;
int flags;

g_return_val_if_fail (error == NULL || *error == NULL, NULL);

Expand All @@ -80,11 +88,13 @@ static X509 *load_cert(const gchar *certfile, GError **error) {

res = PEM_read_bio_X509(cert, NULL, NULL, NULL);
if (res == NULL) {
err = ERR_get_error_line_data(NULL, NULL, &data, &flags);
g_set_error(
error,
R_SIGNATURE_ERROR,
R_SIGNATURE_ERROR_PARSE_ERROR,
"failed to parse cert file '%s'", certfile);
"failed to parse cert file '%s': %s", certfile,
(flags & ERR_TXT_STRING) ? data : ERR_error_string(err, NULL));
goto out;
}
out:
Expand Down

0 comments on commit f57985c

Please sign in to comment.