Repository navigation
fix(bash): resolve the script-dir idiom written inline in source (#5562) - #5570
yashsaxena wants to merge 1 commit into
Conversation
…phify-Labs#5562) . "$(cd "$(dirname "$0")/.." && pwd)/lib/x.sh" now loads lib/x.sh, gated by _resolve_safe like the other source forms. A .. after the idiom is not followed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the pull request, @yashsaxena. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify review 
1 bug · 1 possible issue to check · High impact
The extractor adds static resolution for inline Bash script-directory source paths.
Inline sources through subdirectories can point at the wrong file ·
bash.py:135
1 possible issue we couldn't confirm
- Duplicated
..-hop loop in_bash_inline_script_dir_pathrepeats the logic in_bash_assignment_base·graphify/extractors/bash.py:154
They don't change the score.
Code graph · 625 functions depend on this change
- 2 functions became more coupled.
extract_bash()(54 callers),walk()(1 callers). - Gate, test list and every flagged function: in the Graphify check.
Reviewed 671649e
| # The literal path after the idiom's closing `&& pwd)` when the idiom is written | ||
| # inline in a `source` argument (#5562): | ||
| # `$(cd "$(dirname "$0")/.." && pwd)/lib/x.sh` -> `lib/x.sh`. | ||
| _BASH_INLINE_PWD_PATH = re.compile( |
There was a problem hiding this comment.
Inline sources through subdirectories can point at the wrong file
A source path that adds a directory after dirname "$0" can be linked to a different file than the script actually sources.
Update _bash_inline_script_dir_path to include subdirectories after dirname "$0".
Evidence · checked against the code
- Independent source review: The caller checks that the inferred path is safe and exists, but does not compare it with the shell-resolved target. The inspected tests cover a
/..idiom and reject a..suffix; they do not test an intervening directory such as/sub.
Prompt to fix with AI
In graphify/extractors/bash.py, _bash_inline_script_dir_path (lines 132-135):
Problem: Inline sources through subdirectories can point at the wrong file
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
|
Shipped in v0.9.123, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @yashsaxena! |
What does this PR do?
Fixes #5562.
A
source(or.) argument with the script-dir idiom written inline, as in. "$(cd "$(dirname "$0")/.." && pwd)/lib/greet.sh", gave no edge: the leading-expansion rules strip${VAR}/$VAR, not$(cd … && pwd).A new helper,
_bash_inline_script_dir_path, reads that form the way_bash_assignment_basereads it in an assignment (the script's folder, up one per/..), then the literal path afterpwd).The target goes through
_resolve_safeandis_file(), like the othersourceforms.This is the f4 form #3416 listed; the
$0and/..spelling still gave nothing on 0.9.122.Type of change
Verification & Invariants
Invariant (B-1, GHSA-g6c9-j4vm-mwq4): a path a corpus names is only probed through
_resolve_safe, and a..after a guessed base is not followed.The literal path accepts only
[A-Za-z0-9._-]segments and rejects.... "$(cd "$(dirname "$0")/.." && pwd)/lib/f.sh"(the script-dir idiom inline in source) gets no edge #5562, on graphifyy 0.9.122 from PyPI).test_extract_bash_source_inline_script_dir_idiomfails without the fix (nobash_sourcesentry, noimports_fromedge);..._rejects_traversalguards the..case./..outside the inner quotes ("$(dirname "$0")"/..) is not counted, the same as in assignments today.How was this tested?
I could not run the suite on my machine, so this repo's own CI workflow ran on the branch in my fork:
Graphify-specific checklist
_resolve_safe.