diff options
| author | camc <69519329+camc@users.noreply.github.com> | 2025-10-27 14:51:36 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-27 15:51:36 +0100 |
| commit | b2da8eff961fc05a51a9de08c40e805e1f19d81a (patch) | |
| tree | 7059215456228a9671cfda2f950369de00af6b59 | |
| parent | 48cc443a72d639b226038571958a2464f1fc02b2 (diff) | |
| download | llvm-b2da8eff961fc05a51a9de08c40e805e1f19d81a.zip llvm-b2da8eff961fc05a51a9de08c40e805e1f19d81a.tar.gz llvm-b2da8eff961fc05a51a9de08c40e805e1f19d81a.tar.bz2 | |
[clang][bytecode] Fix crash when array index is past end of array in C (#165186)
Fixes #165090
Make sure to reject invalid array pointer offsets in C.
Co-authored-by: camc <pushy-crop-cartel@duck.com>
| -rw-r--r-- | clang/lib/AST/ByteCode/Interp.h | 2 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/c.c | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 43c3ab7..5ab9c8e 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2283,7 +2283,7 @@ std::optional<Pointer> OffsetHelper(InterpState &S, CodePtr OpPC, } } - if (Invalid && S.getLangOpts().CPlusPlus) + if (Invalid && (S.getLangOpts().CPlusPlus || Ptr.inArray())) return std::nullopt; // Offset is valid - compute it on unsigned. diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c index cfdc9d0..3360d4f 100644 --- a/clang/test/AST/ByteCode/c.c +++ b/clang/test/AST/ByteCode/c.c @@ -381,3 +381,9 @@ static char foo_(a) // all-warning {{definition without a prototype}} static void bar_(void) { foo_(foo_(1)); } + +void foo2(void*); +void bar2(void) { + int a[2][3][4][5]; // all-note {{array 'a' declared here}} + foo2(&a[0][4]); // all-warning {{array index 4 is past the end of the array}} +} |
