]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
test/erasure-code: fix stack-use-after-scope by replacing initializer_list with array
authorKefu Chai <tchaikov@gmail.com>
Sun, 29 Jun 2025 02:15:25 +0000 (10:15 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sun, 29 Jun 2025 02:26:52 +0000 (10:26 +0800)
commit125557ab040e4f65e5af448904a589b3dd0a3703
treed9fe6f032123c1522339407f5f57f85635a8cead
parent5aeaa104d86517f4a289f377c72c2ed63e476f76
test/erasure-code: fix stack-use-after-scope by replacing initializer_list with array

Previously, we used std::array<std::initializer_list<int>, 27> to store
a multi-dimensional array. However, initializer_list objects only hold
pointers to their underlying data, not the data itself. When initialized
with brace-enclosed lists like {0,1,2,3}, the temporary arrays created
by these literals are destroyed after the initialization expression
completes, leaving the initializer_list objects pointing to deallocated
memory.

This caused AddressSanitizer to detect stack-use-after-scope errors when
getint() attempted to iterate over the initializer_list contents:

```
==2085499==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7f5fe9803580 at pc 0x55d851bea586 bp 0x7ffc9816a5b0 sp 0x7ffc9816a5a8
READ of size 4 at 0x7f5fe9803580 thread T0
    #0 0x55d851bea585 in getint(std::initializer_list<int>) /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/erasure-code/TestErasureCodeShec_arguments.cc:46:21
    #1 0x55d851bf0258 in int std::__invoke_impl<int, int (*&)(std::initializer_list<int>), std::initializer_list<int>&>(std::__invoke_other, int (*&)(std::initializer_list<int>), std::initializer_list<int>&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:14
...
Address 0x7f5fe9803580 is located in stack of thread T0 at offset 1408 in frame
    #0 0x55d851bdd07f in create_table_shec432() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/erasure-code/TestErasureCodeShec_arguments.cc:52
```

Fix this by using std::array<std::array<int, 4>, 27> instead, which
actually owns and stores the data rather than just pointing to it.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/test/erasure-code/TestErasureCodeShec_arguments.cc