Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(install): accept a Codex hook binary path that contains a space (#2044)

Martin Vogeldad40ccdb633
diff --git a/src/cli/config_toml_edit.c b/src/cli/config_toml_edit.c
index 745bdda0d..e14bcaffb 100644
--- a/src/cli/config_toml_edit.c
+++ b/src/cli/config_toml_edit.c
@@ -2774,9 +2774,14 @@ static int toml_codex_executable_is_safe(const char *encoded, size_t len, size_t
*end = *start && len >= 2U && encoded[len - 1U] == '\'' ? len - 1U : len;
if (*start && *end == len)
return 0;
+ /* #2044: inside the single-quoted form a space is literal in sh and
+ * PowerShell alike, and cbm_shell_quote_word/cbm_powershell_quote_word
+ * emit it for a profile such as C:\Users\First Last. Only an unquoted
+ * word must be free of spaces, since the shell would split it. */
+ unsigned char lowest = *start ? 0x20U : 0x21U;
for (size_t pos = *start; pos < *end;) {
unsigned char ch = (unsigned char)encoded[pos++];
- if (ch < 0x21U || ch == 0x7fU || (!*start && strchr("\"'`$;&|<>(){}[]*?!", ch))) {
+ if (ch < lowest || ch == 0x7fU || (!*start && strchr("\"'`$;&|<>(){}[]*?!", ch))) {
return 0;
}
if (*start && ch == '\'') {
diff --git a/tests/test_config_toml_edit.c b/tests/test_config_toml_edit.c
index cc64fd576..588b11316 100644
--- a/tests/test_config_toml_edit.c
+++ b/tests/test_config_toml_edit.c
@@ -1391,6 +1391,55 @@ TEST(config_toml_codex_reports_stable_failure_reasons) {
PASS();
}
+/* #2044: an installed binary under a profile with a space (C:\Users\First Last)
+ * is rendered single-quoted by cbm_shell_quote_word / cbm_powershell_quote_word.
+ * The hook block must accept exactly what those writers emit, read it back as
+ * owned, and still refuse an unquoted word that the shell would split. */
+TEST(config_toml_codex_accepts_quoted_binary_path_with_spaces) {
+ static const char command[] = "'/Users/First Last/.local/bin/codebase-memory-mcp' hook-augment";
+ static const char command_windows[] = "& 'C:/Users/First Last/AppData/Local/Programs/"
+ "codebase-memory-mcp/codebase-memory-mcp.exe' "
+ "hook-augment";
+ char dir[CTE_PATH_CAP];
+ char path[CTE_PATH_CAP];
+ char first[CTE_FILE_CAP];
+ char actual[CTE_FILE_CAP];
+ ASSERT_EQ(cte_fixture(dir, sizeof(dir), path, sizeof(path)), 0);
+ ASSERT_EQ(th_write_file(path, "keep = true\n"), 0);
+
+ cbm_toml_codex_hook_failure_t failure = CBM_TOML_CODEX_HOOK_FAILURE_INVALID_ARGUMENT;
+ ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
+ CBM_TOML_CODEX_HOOK_UPSERT, 1, &failure),
+ 0);
+ ASSERT_STR_EQ(cbm_toml_codex_hook_failure_name(failure), "none");
+ ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
+ CBM_TOML_CODEX_HOOK_UPSERT, 0, &failure),
+ 0);
+ ASSERT_EQ(cte_read(path, first, sizeof(first)), 0);
+ ASSERT(strstr(first, "First Last/.local/bin/codebase-memory-mcp' hook-augment") != NULL);
+
+ /* The written block is recognised as ours: a second upsert is a no-op. */
+ ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
+ CBM_TOML_CODEX_HOOK_UPSERT, 0, &failure),
+ 0);
+ ASSERT_EQ(cte_read(path, actual, sizeof(actual)), 0);
+ ASSERT_STR_EQ(actual, first);
+ ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
+ CBM_TOML_CODEX_HOOK_REMOVE, 0, &failure),
+ 0);
+ ASSERT_EQ(cte_read(path, actual, sizeof(actual)), 0);
+ ASSERT_STR_EQ(actual, "keep = true\n");
+
+ /* Unquoted, the space splits the executable word: still refused. */
+ ASSERT_EQ(cte_codex_edit_commands_detailed(
+ path, "/Users/First Last/.local/bin/codebase-memory-mcp hook-augment",
+ command_windows, CBM_TOML_CODEX_HOOK_UPSERT, 1, &failure),
+ -1);
+ ASSERT_STR_EQ(cbm_toml_codex_hook_failure_name(failure), "command_render");
+ th_cleanup(dir);
+ PASS();
+}
+
TEST(config_toml_codex_preserves_bom_crlf_and_foreign_aot) {
char dir[CTE_PATH_CAP];
char path[CTE_PATH_CAP];
@@ -1506,6 +1555,7 @@ SUITE(config_toml_edit) {
RUN_TEST(config_toml_codex_accepts_v0102_managed_windows_crlf);
RUN_TEST(config_toml_codex_rejects_ambiguous_inline_byte_identically);
RUN_TEST(config_toml_codex_reports_stable_failure_reasons);
+ RUN_TEST(config_toml_codex_accepts_quoted_binary_path_with_spaces);
RUN_TEST(config_toml_codex_preserves_bom_crlf_and_foreign_aot);
RUN_TEST(config_toml_legacy_remove_reports_foreign_table_without_mutation);
}