Fix undefined behavior, acessing dead object
Status from this message: Applied, thanks!
Get series with b4
b4 am [email protected]Versions newest first
Patches in v1 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | test/socket-rw-eagain: Fix UB, accessing dead objecttest/ | +7 | 0 replies | |
| 2/3 | test/socket-rw: Fix UB, accessing dead objecttest/ | +7 | 0 replies | |
| 3/3 | test/socket-rw-offset: Fix UB, accessing dead objecttest/ | +7 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH liburing 0/3] Fix undefined behavior, acessing dead object
This series fixes undefined behavior caused by accessing local variables that have been out of their scope.
FWIW, compile the following code with gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0:
```
#include <stdio.h>
int main(void)
{
int *pa, *pb;
{
int a;
pa = &a;
}
{
int b;
pb = &b;
}
*pa = 100;
*pb = 200;
printf("(pa == pb) = %d\n", pa == pb);
printf("*pa == %d; *pb == %d\n", *pa, *pb);
return 0;
}
```produces the following output:
``` ammarfaizi2@integral2:/tmp$ gcc q.c -o q ammarfaizi2@integral2:/tmp$ ./q (pa == pb) = 1 *pa == 200; *pb == 200 ammarfaizi2@integral2:/tmp$ ammarfaizi2@integral2:/tmp$ gcc -O3 q.c -o q ammarfaizi2@integral2:/tmp$ ./q (pa == pb) = 0 *pa == 100; *pb == 200 ammarfaizi2@integral2:/tmp$ ```
Note that the int a and int b lifetime have ended, but we still hold the references to them dereference them.
Also the result differs for the different optimization levels. That's to say, there is no guarantee due to UB. Compiler is free to reuse "out of scope variable"'s storage.
The same happens with test/socket-rw{,-eagain,-offset}.c.
---
Ammar Faizi (3):
test/socket-rw-eagain: Fix UB, accessing dead object test/socket-rw: Fix UB, accessing dead object test/socket-rw-offset: Fix UB, accessing dead object
test/socket-rw-eagain.c | 17 +++++++---------- test/socket-rw-offset.c | 17 +++++++---------- test/socket-rw.c | 17 +++++++---------- 3 files changed, 21 insertions(+), 30 deletions(-)
base-commit: 918d8061ffdfdf253806a1e8e141c71644e678bd
Signature · 1 line
2.32.0