From 8a30a9adfb81491af5d25d99c0f8f9470f2ed25a Mon Sep 17 00:00:00 2001 From: aien-spark Date: Sun, 1 Nov 2026 12:08:16 -0600 Subject: [PATCH 1/2] Potential fix for code scanning alert no. 64: Uncontrolled data used in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- tools/ampere_corpus.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/ampere_corpus.c b/tools/ampere_corpus.c index dce73811..88c3fac8 100644 --- a/tools/ampere_corpus.c +++ b/tools/ampere_corpus.c @@ -9,6 +9,15 @@ #include #include +static int is_safe_corpus_dir(const char *dir) +{ + if (!dir || !*dir) return 0; + if (dir[0] == '.') return 0; + if (strstr(dir, "..")) return 0; + if (strchr(dir, '/') || strchr(dir, '\\')) return 0; + return 1; +} + static void save(const char *dir, unsigned serial, const char *suffix, const void *data, size_t size) { char path[4096]; @@ -22,7 +31,7 @@ static void save(const char *dir, unsigned serial, const char *suffix, const voi void omega_ampere_corpus_capture(const BlackwellIRProgram *prog, const uint8_t *sm121, size_t len) { const char *dir = getenv("OMEGA_AMPERE_CORPUS_DIR"); - if (!dir || !*dir) return; + if (!is_safe_corpus_dir(dir)) return; static unsigned serial; const unsigned id = serial++; uint8_t code[16384], reference[16384]; From c3562903726ad92636bf95f529eb01e8d0dfaf28 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:38:15 +0000 Subject: [PATCH 2/2] Allow safe absolute Ampere corpus paths Co-authored-by: aien-spark <330927100+aien-spark@users.noreply.github.com> --- tools/ampere_corpus.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/ampere_corpus.c b/tools/ampere_corpus.c index 88c3fac8..99208f9e 100644 --- a/tools/ampere_corpus.c +++ b/tools/ampere_corpus.c @@ -12,9 +12,14 @@ static int is_safe_corpus_dir(const char *dir) { if (!dir || !*dir) return 0; - if (dir[0] == '.') return 0; - if (strstr(dir, "..")) return 0; - if (strchr(dir, '/') || strchr(dir, '\\')) return 0; + if (strchr(dir, '\\')) return 0; + for (const char *component = dir; *component;) { + while (*component == '/') ++component; + const char *start = component; + while (*component && *component != '/') ++component; + if ((size_t)(component - start) == 2 && + start[0] == '.' && start[1] == '.') return 0; + } return 1; }