Skip to content

Commit d995156

Browse files
authored
chore: address Value field issue for empty strings in dataflow analysis (#1281)
This patch addresses an issue in the dataflow analysis related to parsing single-quoted strings in bash scripts. Previously, for empty single-quoted strings the code incorrectly assumed that a Value field with an empty string would always be present. Signed-off-by: behnazh-w <[email protected]>
1 parent ed3a80f commit d995156

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/macaron/code_analyzer/dataflow_analysis/bash.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2025 - 2026, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

44
"""Dataflow analysis implementation for analysing Bash shell scripts."""
@@ -1811,7 +1811,7 @@ def convert_shell_word_to_value(
18111811
if dbl_quoted_parts is not None:
18121812
return convert_shell_value_sequence_to_fact_value(dbl_quoted_parts, context), True
18131813

1814-
sgl_quoted_str = parse_sql_quoted_string(word)
1814+
sgl_quoted_str = parse_sgl_quoted_string(word)
18151815
if sgl_quoted_str is not None:
18161816
return facts.StringLiteral(sgl_quoted_str), True
18171817

@@ -1842,7 +1842,7 @@ def parse_dbl_quoted_string(word: bashparser_model.Word) -> list[LiteralOrEnvVar
18421842
return None
18431843

18441844

1845-
def parse_sql_quoted_string(word: bashparser_model.Word) -> str | None:
1845+
def parse_sgl_quoted_string(word: bashparser_model.Word) -> str | None:
18461846
"""Parse single quoted string.
18471847
18481848
If the given word is a single quoted string, return the string
@@ -1851,6 +1851,8 @@ def parse_sql_quoted_string(word: bashparser_model.Word) -> str | None:
18511851
if len(word["Parts"]) == 1:
18521852
part = word["Parts"][0]
18531853
if bashparser_model.is_sgl_quoted(part):
1854+
if "Value" not in part:
1855+
return ""
18541856
return part["Value"]
18551857

18561858
return None

src/macaron/parsers/bashparser_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 - 2025, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2024 - 2026, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

44
"""Type definitions for Bash AST as produced (and json-serialised) by the "mvdan.cc/sh/v3/syntax" bash parser."""
@@ -159,7 +159,7 @@ class SglQuoted(TypedDict):
159159
Left: Pos
160160
Right: Pos
161161
Dollar: NotRequired[bool]
162-
Value: str
162+
Value: NotRequired[str]
163163

164164

165165
def is_sgl_quoted(part: WordPart) -> TypeGuard[SglQuoted]:

0 commit comments

Comments
 (0)