Skip to content

Commit 4012c1f

Browse files
authored
[lldb][test] Avoid out-of-bounds reads in TestConflictingSymbol.py (#172792)
Generic data variables are considered to be of the type `void *&`, see `ClangExpressionDeclMap::AddOneGenericVariable()`. On 64-bit platforms (e.g. AArch64), this type is 8 bytes long, while the `conflicting_symbol` variables are defined as `int`, which is typically 4 bytes. `test_conflicting_symbols` could fail if the next 4 bytes in the memory after any of the variables are not zero. This can be reproduced by adding a variable with a non-zero value after `conflicting_symbol`: ``` --- a/lldb/test/API/lang/c/conflicting-symbol/One/OneConstant.c +++ b/lldb/test/API/lang/c/conflicting-symbol/One/OneConstant.c @@ -1 +1,2 @@ int __attribute__ ((visibility("hidden"))) conflicting_symbol = 11111; +int guard = 1; ``` In this case, the test fails with: ``` AssertionError: Ran command: "expr (unsigned long long)conflicting_symbol" Got output: (unsigned long long) $0 = 4294978407 Expecting sub string: "11111" (was not found) Symbol from One should be found ``` Note that 4294978407 = 0x100002B67 = 1 * 2^32 + 11111.
1 parent b184f00 commit 4012c1f

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
int __attribute__ ((visibility("hidden"))) conflicting_symbol = 11111;
1+
void *__attribute__((visibility("hidden"))) conflicting_symbol = (void *)0x1111;

lldb/test/API/lang/c/conflicting-symbol/TestConflictingSymbol.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ def test_conflicting_symbols(self):
5252

5353
# This should display correctly.
5454
self.expect(
55-
"expr (unsigned long long)conflicting_symbol",
55+
"expr conflicting_symbol",
5656
"Symbol from One should be found",
57-
substrs=["11111"],
57+
startstr="(void *)",
58+
patterns=["0x0+1111$"],
5859
)
5960

6061
self.runCmd("continue", RUN_SUCCEEDED)
@@ -69,9 +70,10 @@ def test_conflicting_symbols(self):
6970
lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
7071

7172
self.expect(
72-
"expr (unsigned long long)conflicting_symbol",
73+
"expr conflicting_symbol",
7374
"Symbol from Two should be found",
74-
substrs=["22222"],
75+
startstr="(void *)",
76+
patterns=["0x0+2222$"],
7577
)
7678

7779
self.runCmd("continue", RUN_SUCCEEDED)
@@ -86,7 +88,7 @@ def test_conflicting_symbols(self):
8688
lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
8789

8890
self.expect(
89-
"expr (unsigned long long)conflicting_symbol",
91+
"expr conflicting_symbol",
9092
"An error should be printed when symbols can't be ordered",
9193
error=True,
9294
substrs=["Multiple internal symbols"],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
int __attribute__ ((visibility("hidden"))) conflicting_symbol = 22222;
1+
void *__attribute__((visibility("hidden"))) conflicting_symbol = (void *)0x2222;

0 commit comments

Comments
 (0)