From 11af509006c2410fd5e7abf5e60d624ba0c8723e Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Sat, 14 Sep 2024 00:10:25 +0200 Subject: [PATCH] src/manifest: throw parser error for invalid slot hook combination When using an 'install' hook, the 'pre-install' and 'post-install' hooks will not be called. To avoid confusion, prevent generating bundles having both 'install' and 'pre-install' (or 'post-install') hook set for the same slot. Signed-off-by: Enrico Joerns --- src/manifest.c | 5 +++++ test/manifest.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/manifest.c b/src/manifest.c index a41b214ec..a1a571c54 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -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); diff --git a/test/manifest.c b/test/manifest.c index 5247da314..2c2ebd900 100644 --- a/test/manifest.c +++ b/test/manifest.c @@ -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; @@ -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);