chore: consider switching from py to .sh +...#4499
Conversation
|
The container image build workflow finished with status: |
1d945d4 to
e1e3bf8
Compare
CI Feedback 🧐(Feedback updated until commit e1e3bf8)A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
|
The container image build workflow finished with status: |
| execFileSync('sh', ['-c', 'command -v "$1"', 'sh', name], { | ||
| stdio: 'ignore' | ||
| }); |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix this type of issue, avoid spawning a shell (sh -c ...) when checking for or invoking commands whose names or paths may come from the environment or other untrusted sources. Instead, call the desired executable directly with execFileSync/execFile (or similar) and pass arguments as an array, so the runtime bypasses shell parsing entirely.
Here, needCmd only wants to verify that a command or executable exists and is runnable. Rather than invoking sh -c 'command -v "$1"' sh name, we can simply try to run the command directly, e.g. execFileSync(name, ['--version']) or, more generically, run it with no arguments and ignore failures that come from its exit code while still detecting “command not found”. The minimal change that preserves semantics is to call execFileSync(name, ['--version']) (or just execFileSync(name, {stdio:'ignore'})), catch any error, and treat it as “required command not found”. Because the file only needs to know “does this run at all?”, not the command’s output, ignoring its stdio is acceptable.
Concretely, in scripts/install-dynamic-plugins/src/install.ts, update the needCmd function (around lines 39–46) to remove the sh -c 'command -v ...' pattern and instead call execFileSync directly with name as the command. No new imports or helper methods are needed; execFileSync is already imported from node:child_process. All other uses of execFileSync in the shown snippet already pass arguments directly and do not involve a shell, so they can remain unchanged.
| @@ -38,9 +38,8 @@ | ||
|
|
||
| function needCmd(name: string): void { | ||
| try { | ||
| execFileSync('sh', ['-c', 'command -v "$1"', 'sh', name], { | ||
| stdio: 'ignore' | ||
| }); | ||
| // Try to execute the command directly to verify that it exists and is runnable. | ||
| execFileSync(name, ['--version'], { stdio: 'ignore' }); | ||
| } catch { | ||
| die(`required command not found: ${name}`); | ||
| } |
|
The container image build workflow finished with status: |
|
The container image build workflow finished with status: |
generated-byt : cursor Signed-off-by: Nick Boldt <nboldt@redhat.com>
Signed-off-by: Nick Boldt <nboldt@redhat.com>
Signed-off-by: rhdh-bot service account <rhdh-bot@redhat.com>
…ping or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Nick Boldt <nboldt@redhat.com>
c97d0a4 to
82678c1
Compare
|
|
The container image build workflow finished with status: |
|
@nickboldt: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |




What does this PR do?
chore: consider switching from py to .sh + .cjs
generated-by: cursor slop factory
Signed-off-by: Nick Boldt nboldt@redhat.com
Screenshot/screencast of this PR
N/A
What issues does this PR fix or reference?
N/A (or see commit message above for issue number)
How to test this PR?
N/A
PR Checklist
As the author of this Pull Request I made sure that:
Reviewers
Reviewers, please comment how you tested the PR when approving it.