Skip to content

Commit

Permalink
src/bundle: simplify flow of check_bundle_payload()
Browse files Browse the repository at this point in the history
Remove 'res' variable and 'out' label and use immediate returns instead.

Signed-off-by: Enrico Joerns <[email protected]>
  • Loading branch information
ejoerns committed Nov 6, 2023
1 parent a3b7e57 commit d222a43
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2175,42 +2175,37 @@ gboolean check_bundle(const gchar *bundlename, RaucBundle **bundle, CheckBundleP
gboolean check_bundle_payload(RaucBundle *bundle, GError **error)
{
GError *ierror = NULL;
gboolean res = FALSE;

g_return_val_if_fail(bundle != NULL, FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

if (bundle->verification_disabled || bundle->payload_verified) {
r_context_begin_step("skip_bundle_payload", "Bundle payload verification not needed", 0);
r_context_end_step("skip_bundle_payload", TRUE);
res = TRUE;
goto out;
return TRUE;
}

g_message("Verifying bundle payload... ");

if (!bundle->stream) {
g_set_error(error, R_BUNDLE_ERROR, R_BUNDLE_ERROR_UNSAFE,
"Refused to verify remote bundle. Provide a local bundle instead.");
res = FALSE;
goto out;
return FALSE;
}

if (!bundle->exclusive_verified) {
g_set_error(error, R_BUNDLE_ERROR, R_BUNDLE_ERROR_UNSAFE,
"cannot check bundle payload without exclusive access: %s", bundle->exclusive_check_error);
res = FALSE;
goto out;
return FALSE;
}

if (!bundle->manifest) { /* plain format */
g_error("plain bundles must be verified during signature check");
/* g_error always aborts the program */
} else {
res = check_manifest_external(bundle->manifest, &ierror);
if (!res) {
if (!check_manifest_external(bundle->manifest, &ierror)) {
g_propagate_error(error, ierror);
goto out;
return FALSE;
}
}

Expand All @@ -2230,20 +2225,16 @@ gboolean check_bundle_payload(RaucBundle *bundle, GError **error)
if (r_verity_hash_verify(bundlefd, data_size/4096, root_digest, salt)) {
g_set_error(error, R_BUNDLE_ERROR, R_BUNDLE_ERROR_PAYLOAD,
"bundle payload is corrupted");
res = FALSE;
goto out;
return FALSE;
}
} else {
g_error("unsupported bundle format");
res = FALSE;
goto out;
return FALSE;
}

bundle->payload_verified = TRUE;

res = TRUE;
out:
return res;
return TRUE;
}

gboolean replace_signature(RaucBundle *bundle, const gchar *insig, const gchar *outpath, CheckBundleParams params, GError **error)
Expand Down

0 comments on commit d222a43

Please sign in to comment.