Skip to content

Stop PKGMAN_Exec from parsing its arguments - #158

Open
fingolfin wants to merge 1 commit into
masterfrom
mh/exec-args
Open

fingolfin wants to merge 1 commit into
masterfrom
mh/exec-args

Conversation

@fingolfin

Copy link
Copy Markdown
Member

Claude writing here:

PKGMAN_Exec joins its arguments with spaces and runs the result with sh -c, so an argument with a space is split and one with $(...) or ; is executed. Archive names are the last component of a PackageInfo.g's ArchiveURL, so a crafted URL runs code at tar xf.

gap> PKGMAN_Exec(".", "printf", "[%s]", "a  b", "$(echo injected)").output;
"[a][b][injected]"          # before
"[a  b][$(echo injected)]"  # after

The shell now gets command and arguments as positional parameters (sh -c 'exec "$0" "$@" 2>&1' cmd arg...): it still merges stderr, but never parses them. #104 is unaffected.

Two callers passed "" to mean "no option" (non-GNU tar, hg status); they now pass nothing.

PKGMAN_Exec joined its arguments with spaces and handed the result to
'sh -c', so an argument containing a space was split, and one containing
'$(...)' or ';' was executed.  Such arguments include URLs and archive
names taken from PackageInfo.g files fetched from the network.

Pass command and arguments to the shell as positional parameters
instead; it still adds the '2>&1', but never parses them.  Two callers
passed an empty string meaning "no option", which is now an argument of
its own, so they pass nothing instead.

Assisted-by: Generative AI
@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.14%. Comparing base (9e40dc4) to head (15d33cf).

Files with missing lines Patch % Lines
gap/archive.gi 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #158      +/-   ##
==========================================
+ Coverage   85.12%   85.14%   +0.01%     
==========================================
  Files          22       22              
  Lines        1022     1023       +1     
==========================================
+ Hits          870      871       +1     
  Misses        152      152              
Files with missing lines Coverage Δ
gap/PackageManager.gi 94.80% <100.00%> (ø)
gap/archive.gi 92.42% <75.00%> (+0.11%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtorpey

mtorpey commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

I'm having a bit of trouble with this. What is the problem that this PR is attempting to solve, and what is the intention of Concatenation(["-c", "exec \"$0\" \"$@\" 2>&1", fullcmd], on line 302?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants