Skip to content

Commit

Permalink
src/manifest: throw parser error for invalid slot hook combination
Browse files Browse the repository at this point in the history
When using an 'install' hook, the 'pre-install' and 'post-install' hooks
will not be called. To avoid confusion, prevent generating bundles with
having both 'install' and 'pre-install' (or 'post-install') hook set for
the same slot.

Signed-off-by: Enrico Joerns <[email protected]>
  • Loading branch information
ejoerns committed Sep 13, 2024
1 parent 98b5ba8 commit f115a80
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ static gboolean parse_image(GKeyFile *key_file, const gchar *group, RaucImage **
goto out;
}
}
if (iimage->hooks.install && (iimage->hooks.pre_install || iimage->hooks.post_install)) {
g_set_error_literal(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE,
"'install' hook must not be combined with 'pre-install' or 'post-install' hook");
goto out;
}
g_key_file_remove_key(key_file, group, "hooks", NULL);

iimage->filename = key_file_consume_string(key_file, group, "filename", &ierror);
Expand Down
31 changes: 31 additions & 0 deletions test/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,36 @@ hooks=doesnotexist\n\
g_assert_null(rm);
}

static void test_manifest_invalid_hook_combination(void)
{
g_autofree gchar *tmpdir;
g_autofree gchar *manifestpath = NULL;
g_autoptr(RaucManifest) rm = NULL;
gboolean res = FALSE;
g_autoptr(GError) error = NULL;
const gchar *mffile = "\
[update]\n\
compatible=FooCorp Super BarBazzer\n\
version=2015.04-1\n\
\n\
[image.rootfs]\n\
filename=rootfs-default.ext4\n\
sha256=0815\n\
size=1\n\
hooks=install;pre-install\n\
";

tmpdir = g_dir_make_tmp("rauc-XXXXXX", NULL);
g_assert_nonnull(tmpdir);

manifestpath = write_tmp_file(tmpdir, "manifest.raucm", mffile, NULL);
g_assert_nonnull(manifestpath);

res = load_manifest_file(manifestpath, &rm, &error);
g_assert_error(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
g_assert_false(res);
}

static void test_manifest_missing_hook_name(void)
{
g_autofree gchar *tmpdir;
Expand Down Expand Up @@ -740,6 +770,7 @@ int main(int argc, char *argv[])
g_test_add_func("/manifest/load_meta", test_manifest_load_meta);
g_test_add_func("/manifest/load_details", test_manifest_load_details);
g_test_add_func("/manifest/invalid_hook_name", test_manifest_invalid_hook_name);
g_test_add_func("/manifest/invalid_hook_combination", test_manifest_invalid_hook_combination);
g_test_add_func("/manifest/missing_hook_name", test_manifest_missing_hook_name);
g_test_add_func("/manifest/missing_image_size", test_manifest_missing_image_size);
g_test_add_func("/manifest/invalid_data", test_invalid_data);
Expand Down

0 comments on commit f115a80

Please sign in to comment.