Skip to content

Commit 9df483f

Browse files
authored
Merge pull request DeusData#2338 from DeusData/fix/issue-2044
fix(install): accept a Codex hook binary path that contains a space (DeusData#2044)
2 parents 30a410b + dad40cc commit 9df483f

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎src/cli/config_toml_edit.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,9 +2774,14 @@ static int toml_codex_executable_is_safe(const char *encoded, size_t len, size_t
27742774
*end = *start && len >= 2U && encoded[len - 1U] == '\'' ? len - 1U : len;
27752775
if (*start && *end == len)
27762776
return 0;
2777+
/* #2044: inside the single-quoted form a space is literal in sh and
2778+
* PowerShell alike, and cbm_shell_quote_word/cbm_powershell_quote_word
2779+
* emit it for a profile such as C:\Users\First Last. Only an unquoted
2780+
* word must be free of spaces, since the shell would split it. */
2781+
unsigned char lowest = *start ? 0x20U : 0x21U;
27772782
for (size_t pos = *start; pos < *end;) {
27782783
unsigned char ch = (unsigned char)encoded[pos++];
2779-
if (ch < 0x21U || ch == 0x7fU || (!*start && strchr("\"'`$;&|<>(){}[]*?!", ch))) {
2784+
if (ch < lowest || ch == 0x7fU || (!*start && strchr("\"'`$;&|<>(){}[]*?!", ch))) {
27802785
return 0;
27812786
}
27822787
if (*start && ch == '\'') {

‎tests/test_config_toml_edit.c‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,55 @@ TEST(config_toml_codex_reports_stable_failure_reasons) {
13911391
PASS();
13921392
}
13931393

1394+
/* #2044: an installed binary under a profile with a space (C:\Users\First Last)
1395+
* is rendered single-quoted by cbm_shell_quote_word / cbm_powershell_quote_word.
1396+
* The hook block must accept exactly what those writers emit, read it back as
1397+
* owned, and still refuse an unquoted word that the shell would split. */
1398+
TEST(config_toml_codex_accepts_quoted_binary_path_with_spaces) {
1399+
static const char command[] = "'/Users/First Last/.local/bin/codebase-memory-mcp' hook-augment";
1400+
static const char command_windows[] = "& 'C:/Users/First Last/AppData/Local/Programs/"
1401+
"codebase-memory-mcp/codebase-memory-mcp.exe' "
1402+
"hook-augment";
1403+
char dir[CTE_PATH_CAP];
1404+
char path[CTE_PATH_CAP];
1405+
char first[CTE_FILE_CAP];
1406+
char actual[CTE_FILE_CAP];
1407+
ASSERT_EQ(cte_fixture(dir, sizeof(dir), path, sizeof(path)), 0);
1408+
ASSERT_EQ(th_write_file(path, "keep = true\n"), 0);
1409+
1410+
cbm_toml_codex_hook_failure_t failure = CBM_TOML_CODEX_HOOK_FAILURE_INVALID_ARGUMENT;
1411+
ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
1412+
CBM_TOML_CODEX_HOOK_UPSERT, 1, &failure),
1413+
0);
1414+
ASSERT_STR_EQ(cbm_toml_codex_hook_failure_name(failure), "none");
1415+
ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
1416+
CBM_TOML_CODEX_HOOK_UPSERT, 0, &failure),
1417+
0);
1418+
ASSERT_EQ(cte_read(path, first, sizeof(first)), 0);
1419+
ASSERT(strstr(first, "First Last/.local/bin/codebase-memory-mcp' hook-augment") != NULL);
1420+
1421+
/* The written block is recognised as ours: a second upsert is a no-op. */
1422+
ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
1423+
CBM_TOML_CODEX_HOOK_UPSERT, 0, &failure),
1424+
0);
1425+
ASSERT_EQ(cte_read(path, actual, sizeof(actual)), 0);
1426+
ASSERT_STR_EQ(actual, first);
1427+
ASSERT_EQ(cte_codex_edit_commands_detailed(path, command, command_windows,
1428+
CBM_TOML_CODEX_HOOK_REMOVE, 0, &failure),
1429+
0);
1430+
ASSERT_EQ(cte_read(path, actual, sizeof(actual)), 0);
1431+
ASSERT_STR_EQ(actual, "keep = true\n");
1432+
1433+
/* Unquoted, the space splits the executable word: still refused. */
1434+
ASSERT_EQ(cte_codex_edit_commands_detailed(
1435+
path, "/Users/First Last/.local/bin/codebase-memory-mcp hook-augment",
1436+
command_windows, CBM_TOML_CODEX_HOOK_UPSERT, 1, &failure),
1437+
-1);
1438+
ASSERT_STR_EQ(cbm_toml_codex_hook_failure_name(failure), "command_render");
1439+
th_cleanup(dir);
1440+
PASS();
1441+
}
1442+
13941443
TEST(config_toml_codex_preserves_bom_crlf_and_foreign_aot) {
13951444
char dir[CTE_PATH_CAP];
13961445
char path[CTE_PATH_CAP];
@@ -1506,6 +1555,7 @@ SUITE(config_toml_edit) {
15061555
RUN_TEST(config_toml_codex_accepts_v0102_managed_windows_crlf);
15071556
RUN_TEST(config_toml_codex_rejects_ambiguous_inline_byte_identically);
15081557
RUN_TEST(config_toml_codex_reports_stable_failure_reasons);
1558+
RUN_TEST(config_toml_codex_accepts_quoted_binary_path_with_spaces);
15091559
RUN_TEST(config_toml_codex_preserves_bom_crlf_and_foreign_aot);
15101560
RUN_TEST(config_toml_legacy_remove_reports_foreign_table_without_mutation);
15111561
}

0 commit comments

Comments
 (0)