{"thread":{"id":"66863","subject":"[PATCH] fast-import: do not show the path when \"feature export-marks\" is forbidden","startedAt":"2026-11-17T16:03:05Z","lastAt":"2026-11-19T18:53:05Z","messageCount":3,"participants":["Kaartic Sivaraam","Karthik Nayak","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558625","messageId":"20261117-ks-fast-import-consistent-check-unsafe-v1-1-fc1ed53c79b2@gmail.com","threadId":"66863","inReplyTo":null,"subject":"[PATCH] fast-import: do not show the path when \"feature export-marks\" is forbidden","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2026-11-17T16:03:05Z","receivedAt":"2026-11-17T16:03:05Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Since 68061e3470 (fast-import: disallow \"feature export-marks\" by\ndefault, 2019-08-29), a stream that uses \"feature export-marks=<path>\"\nwithout --allow-unsafe-features dies with\n\n    feature 'export-marks=<path>' forbidden in input without --allow-unsafe-features\n\nbecause the whole feature string, including the \"=<path>\" argument,\nis passed to check_unsafe_feature(). The import-marks variants pass\njust the feature name, so their messages do not include the path.\n\nPass \"export-marks\" to match, and make the existing test check the\nmessage, not just that the command fails.\n\nSigned-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n---\nWhile backporting patches for a security release, I noticed this.\nWas waiting for the security fix to go out before sending it.\n---\n builtin/fast-import.c  | 2 +-\n t/t9300-fast-import.sh | 3 ++-\n 2 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex ab5d2a2344..998167794c 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -3918,7 +3918,7 @@ static int parse_one_feature(struct fast_import_state *state,\n \t\tcheck_unsafe_feature(state, \"import-marks-if-exists\");\n \t\toption_import_marks(state, arg, 1, 1);\n \t} else if (skip_prefix(feature, \"export-marks=\", &arg)) {\n-\t\tcheck_unsafe_feature(state, feature);\n+\t\tcheck_unsafe_feature(state, \"export-marks\");\n \t\toption_export_marks(state, arg);\n \t} else if (!strcmp(feature, \"alias\")) {\n \t\t; /* Don't die - this feature is supported */\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex 15f511fb6b..33c04e0315 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -2337,7 +2337,8 @@ test_expect_success 'R: only one import-marks feature allowed per stream' '\n \n test_expect_success 'R: export-marks feature forbidden by default' '\n \techo \"feature export-marks=git.marks\" >input &&\n-\ttest_must_fail git fast-import <input\n+\ttest_must_fail git fast-import <input 2>err &&\n+\ttest_grep \"feature .export-marks. forbidden\" err\n '\n \n test_expect_success 'R: export-marks feature results in a marks file being created' '\n\n---\nbase-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4\nchange-id: 20261104-ks-fast-import-consistent-check-unsafe-0a94ffda7518\n\n\n"},{"id":"558694","messageId":"CAOLa=ZSYkXMP0pOX824B9rZEJyV4kQ9FqU44zW4Z76R05HUxnA@mail.gmail.com","threadId":"66863","inReplyTo":"20261117-ks-fast-import-consistent-check-unsafe-v1-1-fc1ed53c79b2@gmail.com","subject":"Re: [PATCH] fast-import: do not show the path when \"feature export-marks\" is forbidden","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-18T11:21:19Z","receivedAt":"2026-11-18T11:21:19Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n> Since 68061e3470 (fast-import: disallow \"feature export-marks\" by\n> default, 2019-08-29), a stream that uses \"feature export-marks=<path>\"\n> without --allow-unsafe-features dies with\n>\n>     feature 'export-marks=<path>' forbidden in input without --allow-unsafe-features\n>\n> because the whole feature string, including the \"=<path>\" argument,\n> is passed to check_unsafe_feature(). The import-marks variants pass\n> just the feature name, so their messages do not include the path.\n>\n> Pass \"export-marks\" to match, and make the existing test check the\n> message, not just that the command fails.\n>\n\nIt's not just 'import-marks', but all other features provide a static\nstring. So makes sense.\n\n> Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>\n> ---\n> While backporting patches for a security release, I noticed this.\n> Was waiting for the security fix to go out before sending it.\n> ---\n>  builtin/fast-import.c  | 2 +-\n>  t/t9300-fast-import.sh | 3 ++-\n>  2 files changed, 3 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/fast-import.c b/builtin/fast-import.c\n> index ab5d2a2344..998167794c 100644\n> --- a/builtin/fast-import.c\n> +++ b/builtin/fast-import.c\n> @@ -3918,7 +3918,7 @@ static int parse_one_feature(struct fast_import_state *state,\n>  \t\tcheck_unsafe_feature(state, \"import-marks-if-exists\");\n>  \t\toption_import_marks(state, arg, 1, 1);\n>  \t} else if (skip_prefix(feature, \"export-marks=\", &arg)) {\n> -\t\tcheck_unsafe_feature(state, feature);\n> +\t\tcheck_unsafe_feature(state, \"export-marks\");\n\nChange looks sensible!\n\n>  \t\toption_export_marks(state, arg);\n>  \t} else if (!strcmp(feature, \"alias\")) {\n>  \t\t; /* Don't die - this feature is supported */\n> diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\n> index 15f511fb6b..33c04e0315 100755\n> --- a/t/t9300-fast-import.sh\n> +++ b/t/t9300-fast-import.sh\n> @@ -2337,7 +2337,8 @@ test_expect_success 'R: only one import-marks feature allowed per stream' '\n>\n>  test_expect_success 'R: export-marks feature forbidden by default' '\n>  \techo \"feature export-marks=git.marks\" >input &&\n> -\ttest_must_fail git fast-import <input\n> +\ttest_must_fail git fast-import <input 2>err &&\n> +\ttest_grep \"feature .export-marks. forbidden\" err\n>  '\n>\n\nSigh, this will conflict with my long series [1]. So one of us will have\nto merge the other topic in and send in a new version. Let's see how\nthings go :)\n\n\n>  test_expect_success 'R: export-marks feature results in a marks file being created' '\n>\n> ---\n> base-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4\n> change-id: 20261104-ks-fast-import-consistent-check-unsafe-0a94ffda7518\n\n[1]: https://lore.kernel.org/git/20261112-kn-fast-import-tests-1-v2-0-b8c3a0ab27e8@gmail.com/\n"},{"id":"558873","messageId":"xmqqbj7ky7ou.fsf@gitster.g","threadId":"66863","inReplyTo":"20261117-ks-fast-import-consistent-check-unsafe-v1-1-fc1ed53c79b2@gmail.com","subject":"Re: [PATCH] fast-import: do not show the path when \"feature export-marks\" is forbidden","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T18:53:05Z","receivedAt":"2026-11-19T18:53:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n> diff --git a/builtin/fast-import.c b/builtin/fast-import.c\n> index ab5d2a2344..998167794c 100644\n> --- a/builtin/fast-import.c\n> +++ b/builtin/fast-import.c\n> @@ -3918,7 +3918,7 @@ static int parse_one_feature(struct fast_import_state *state,\n>  \t\tcheck_unsafe_feature(state, \"import-marks-if-exists\");\n>  \t\toption_import_marks(state, arg, 1, 1);\n>  \t} else if (skip_prefix(feature, \"export-marks=\", &arg)) {\n> -\t\tcheck_unsafe_feature(state, feature);\n> +\t\tcheck_unsafe_feature(state, \"export-marks\");\n>  \t\toption_export_marks(state, arg);\n>  \t} else if (!strcmp(feature, \"alias\")) {\n>  \t\t; /* Don't die - this feature is supported */\n\nThis is an obviously correct change, but doesn't this bug caused by\nforced repetition annoy anybody?  This if/else if/else cascade is an\nobvious trap waiting for another similar bug to be added.\n\nWouldn't it be much nicer if the above hunk can be rewritten like\nso,\n\n \t\toption_import_marks(state, arg, 1, 1);\n-\t} else if (skip_prefix(feature, \"export-marks=\", &arg)) {\n+\t} else if (check_unsafe(state, feature, \"export-marks\", &arg)) {\n-\t\tcheck_unsafe_feature(state, feature);\n \t\toption_export_marks(state, arg);\n \t} else if (!strcmp(feature, \"alias\")) {\n \t\t; /* Don't die - this feature is supported */\n\nso a separate call to check_unsafe_feature() can be lost, and we no\nlonger have to repeat \"export-marks=\" and \"export-marks\" for all\nthese \"unsafe\" features?\n\nIf we plan to ever add an argument-less unsafe feature, the helper\nneeds to be updated to require NUL (instead of '=') after we find\nthe end of the feature name with skip_prefix() when the feature is\nan argument-less one (perhaps signaled by arg==NULL or something),\nbut you get the idea.\n\n builtin/fast-import.c | 33 ++++++++++++++++++---------------\n 1 file changed, 18 insertions(+), 15 deletions(-)\n\ndiff --git i/builtin/fast-import.c w/builtin/fast-import.c\nindex ab5d2a2344..673d3f2289 100644\n--- i/builtin/fast-import.c\n+++ w/builtin/fast-import.c\n@@ -3896,12 +3896,20 @@ static int parse_one_option(struct fast_import_state *state, const char *option)\n \treturn 1;\n }\n \n-static void check_unsafe_feature(struct fast_import_state *state,\n-\t\t\t\t const char *feature)\n+static int check_unsafe(struct fast_import_state *state,\n+\t\t\tconst char *feature, const char *prefix,\n+\t\t\tconst char **arg)\n {\n-\tif (!state->allow_unsafe_features)\n-\t\tdie(_(\"feature '%s' forbidden in input without --allow-unsafe-features\"),\n-\t\t    feature);\n+\tconst char *arg_;\n+\n+\tif (skip_prefix(feature, prefix, &arg_) && *arg_ == '=') {\n+\t\tif (!state->allow_unsafe_features)\n+\t\t\tdie(_(\"feature '%s' forbidden in input \"\n+\t\t\t      \"without --allow-unsafe-features\"), prefix);\n+\t\t*arg = arg_ + 1;\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n }\n \n static int parse_one_feature(struct fast_import_state *state,\n\n"}]}