reg is unsigned type and used here for getting array element from the end by negating it.
negation of unsigned can result in large number and array access with that index will result in segmentation
fault.
As a Fix we cast reg to int then negate it.
Fixes this.
https://bugs.llvm.org/show_bug.cgi?id=43872
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
This looks good to me, but I must admit I'm surprised this problem has never come up before (this code is very old), and also I don't know what the code is trying to do. Adding Saleem and Nick who have more experience with libunwind just to double-check.
Comment Actions
Is it tested? Intuitively I would expect DW_OP_pick to be kind of an unusual operator, unlikely to be seen in the wild.
Comment Actions
`I do not have a test related to libunwind ,but I do simulated this behavior in c and got segfault. ------ int main(){ int stack[10]={0}; int* sp=stack; *(sp)=1; *(++sp)=2; *(++sp)=3; unsigned int r=1; int d=sp[-r]; return 0; } ---------`
Comment Actions
The fix LGTM. Do you have a reproducer that can be used as a testcase? We should really add more tests for libunwind.
Comment Actions
Ok. We will need to come back dealing with test coverage in the future. I can commit it for you.
Comment Actions
Commited in: 9366397f057d18401e680b2cb28a0ee17c59d4a6
Phabriactor might not update this because the patch was created on libunwind repo, not the monorepo.