Hi, Prasad!
It looks like this is a clang optimization issue.
I`ve made a simple experiment:
When environ is mentioned somewhere in the source code -
everything is fine - test passed.
The value of envp is equal to environ and is always
0x514000000040 (reproducible).
When environ is absent (not mentioned in the source code)
The value of envp is also 0x514000000040 (reproducible),
but the behavior may be each time different.
Mostly test fails with error, with or without ASAN report.
Thus, it seems, that when environ variable is not used -
it`s being optimized, the corresponding memory is being
freed, but envp pointer still points to the freed memory.
Thanks a lot!
With best regards,
Dmitry.
On 12.11.2024 10:11, Prasad Pandit wrote:
On Tue, 12 Nov 2024 at 12:08, Dmitry Frolov <[email protected]> wrote:
"int main(int argc, char **argv, char** envp)" is non-standart
standart -> standard
Microsoft`s extention of the C language and it`s not portable.
* But it looks widely supported.
In my particular case (Debian 13, clang-16) this raises wild-pointer
dereference with ASAN message "heap-use-after-free".
v2: changed confusing commit header
* We need to include a pointer to the earlier version/discussion:
v1: ->
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
Thank you.
---
- Prasad