Skip to content

Commit 09178da

Browse files
authored
Merge pull request #1005: Fix CI parser regressions and isolate TOML service lookup
Fix bounded multiline printf inspection and keep TOML regression checks independent of vulnerability-service availability.
2 parents f06ca15 + f1cb2b8 commit 09178da

4 files changed

Lines changed: 77 additions & 13 deletions

File tree

‎src/skillspector/nodes/analyzers/static_patterns_tool_misuse.py‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,13 +2463,24 @@ def walk(begin: int, end: int, depth: int = 0) -> bool:
24632463
continue
24642464
if quote is not None and character == quote:
24652465
closers.add(cursor)
2466-
if (
2467-
not ansi_c
2468-
and "\n" not in content[quote_start:cursor]
2469-
and "\r" not in content[quote_start:cursor]
2470-
):
2466+
if not ansi_c:
2467+
single_line = (
2468+
"\n" not in content[quote_start:cursor]
2469+
and "\r" not in content[quote_start:cursor]
2470+
)
24712471
for position in candidates:
2472-
limits[position] = cursor
2472+
if single_line or (
2473+
quote == '"'
2474+
and content.startswith("$(", position)
2475+
and substitution_cache.get(position) == cursor
2476+
and _static_printf_substitution(
2477+
content, position, cursor, quoted_result=True
2478+
)
2479+
is not None
2480+
):
2481+
# Only a proved literal printf at the quote's end
2482+
# may refine a multiline substitution candidate.
2483+
limits[position] = cursor
24732484
quote = None
24742485
cursor += 1
24752486
continue
@@ -2622,6 +2633,13 @@ def _quoted_candidate_is_complete(
26222633
end = quote_limits.get(start) if quote_limits is not None else None
26232634
if end is None:
26242635
return False
2636+
if (
2637+
quoted_printf_allowed
2638+
and content.startswith("$(", start)
2639+
and _skip_command_substitution(content, start, end, check_runtime) == end
2640+
and _static_printf_substitution(content, start, end, quoted_result=True) is not None
2641+
):
2642+
return True
26252643
fragment = content[start:end]
26262644
parsed = _parse_shell_command_word(
26272645
fragment, 0, check_runtime=check_runtime, quoted_printf_allowed=quoted_printf_allowed
@@ -2903,7 +2921,11 @@ def _has_shell_command_word_exhaustion(
29032921
substitution_end,
29042922
check_runtime=check_runtime,
29052923
):
2906-
return True
2924+
if not _quoted_candidate_is_complete(
2925+
content, start, quote_limits, check_runtime, quoted_printf_allowed
2926+
):
2927+
return True
2928+
continue
29072929
if content[start] == "`":
29082930
substitution_end = _skip_backtick_substitution(
29092931
content, start, len(content), check_runtime, end_cache=backtick_end_cache

‎tests/nodes/analyzers/test_dependency_source_review_regressions.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ def test_oversized_toml_integer_does_not_drop_existing_supply_chain_findings(mon
102102
earlier = Finding(
103103
rule_id="SC5", severity="HIGH", file="requirements.txt", message="Existing risk"
104104
)
105+
monkeypatch.setattr(
106+
supply_chain, "query_batch", lambda packages, *_args, **_kwargs: [[] for _ in packages]
107+
)
108+
monkeypatch.setattr(supply_chain, "was_osv_reachable", lambda: True)
105109
monkeypatch.setattr(
106110
supply_chain.static_runner,
107111
"run_static_patterns_with_ledger",

‎tests/nodes/analyzers/test_powershell_shell_ownership.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ def test_powershell_comments_and_messages_have_complete_analysis(
5858
content: str, newline: str
5959
) -> None:
6060
content = content.replace("\n", newline)
61-
# Each case exercises a host-syntax false positive present before #711.
62-
assert tm.has_bounded_parse_exhaustion(content, lambda: None, file_type="shell") is True
63-
61+
# These are PowerShell regressions. Shell quote ownership can independently
62+
# accept some of their strings, so shell-mode failure is not a precondition.
6463
result = _scan(content)
6564

6665
assert _limited(content) is False

‎tests/nodes/analyzers/test_shell_quote_ownership.py‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,14 @@ def test_runtime_and_unresolved_controls_remain_partial(source: str, padding: in
571571
assert tm.has_bounded_parse_exhaustion(source, lambda: None, file_type="shell")
572572

573573

574-
@pytest.mark.parametrize("file_type", ["markdown", "python", "powershell"])
575-
def test_ownership_does_not_apply_to_other_languages(file_type: str) -> None:
574+
@pytest.mark.parametrize(
575+
"file_type, partial", [("markdown", True), ("python", True), ("powershell", False)]
576+
)
577+
def test_quote_ownership_respects_host_language(file_type: str, partial: bool) -> None:
576578
source = 'echo "hello $(printf x) ${DELAY}s"\n' + "#" * 6000
577-
assert tm.has_bounded_parse_exhaustion(source, lambda: None, file_type=file_type)
579+
# Complete PowerShell has its own projection; other host languages cannot
580+
# borrow shell ownership for this source.
581+
assert tm.has_bounded_parse_exhaustion(source, lambda: None, file_type=file_type) is partial
578582

579583

580584
def test_fragment_cannot_prove_initial_quote_state() -> None:
@@ -709,6 +713,41 @@ def test_quoted_printf_preserves_multiline_literal_value(newline: str) -> None:
709713
)
710714

711715

716+
@pytest.mark.parametrize("newline", ["\n", "\r\n"])
717+
@pytest.mark.parametrize(
718+
"prefix, argument, suffix, complete_context",
719+
[
720+
("", '"$VALUE"', "", True),
721+
("", '"$($CMD -rf /)"', "", True),
722+
('printf() { "$CMD" "$@"; }\n', '"known value"', "", True),
723+
("", '"known value"', "$CMD -rf /\n", True),
724+
("", '"known value"', 'echo "\n' + "#" * 6000, True),
725+
("", '"known value"', "", False),
726+
],
727+
)
728+
def test_multiline_printf_quote_proof_keeps_unresolved_commands_partial(
729+
prefix: str, argument: str, suffix: str, complete_context: bool, newline: str
730+
) -> None:
731+
source = prefix + 'test x = "$(printf "%s\\n" "first value" \\\n ' + argument + ')"\n' + suffix
732+
733+
assert tm.has_bounded_parse_exhaustion(
734+
source.replace("\n", newline),
735+
lambda: None,
736+
file_type="shell",
737+
complete_context=complete_context,
738+
)
739+
740+
741+
@pytest.mark.parametrize("newline", ["\n", "\r\n"])
742+
def test_multiline_printf_quote_proof_preserves_destructive_execution(newline: str) -> None:
743+
source = '"$(printf "%s%s" r \\\n m)" -rf /\n'.replace("\n", newline)
744+
result = static_runner.run_static_patterns_with_ledger(
745+
{"components": ["run.sh"], "file_cache": {"run.sh": source}}, [tm]
746+
)
747+
748+
assert any(finding.rule_id == "TM1" for finding in result["findings"])
749+
750+
712751
@pytest.mark.parametrize(
713752
("body", "expected"),
714753
[

0 commit comments

Comments
 (0)