Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASAN fails on extern(C) structs (zero sized structs) when passing stack variable to class member #4816

Open
ljmf00-wekaio opened this issue Jan 9, 2025 · 2 comments

Comments

@ljmf00-wekaio
Copy link

class Foo
{
    this(Bar bar) { this.bar = bar; }
    Bar bar;
}

extern(C) struct Bar {}

void main()
{
	auto bar = Bar();
    auto foo = new Foo(bar);
}

With ldc2 -fsanitize=address %

AddressSanitizer:DEADLYSIGNAL
=================================================================
==27==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x55e3bea07532 bp 0x7ffdd7f55120 sp 0x7ffdd7f55100 T0)
==27==The signal is caused by a READ memory access.
==27==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
    #0 0x55e3bea07532 in D main /sandbox/onlineapp.d:12:5
    #1 0x55e3beab788c in _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv (/tmp/onlineapp-433482+0xce88c) (BuildId: 8e61071a375c929d9dfe0882c992f5960dc2fae5)
    #2 0x55e3beab7786 in _d_run_main2 (/tmp/onlineapp-433482+0xce786) (BuildId: 8e61071a375c929d9dfe0882c992f5960dc2fae5)
    #3 0x55e3beab75dc in _d_run_main (/tmp/onlineapp-433482+0xce5dc) (BuildId: 8e61071a375c929d9dfe0882c992f5960dc2fae5)
    #4 0x55e3bea07591 in main /dlang/ldc-1.38.0/bin/../import/core/internal/entrypoint.d:42:17
    #5 0x7f3f5704c1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 08134323d00289185684a4cd177d202f39c2a5f3)
    #6 0x7f3f5704c28a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 08134323d00289185684a4cd177d202f39c2a5f3)
    #7 0x55e3bea073c4 in _start (/tmp/onlineapp-433482+0x1e3c4) (BuildId: 8e61071a375c929d9dfe0882c992f5960dc2fae5)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /sandbox/onlineapp.d:12:5 in D main
==27==ABORTING
Error: /tmp/onlineapp-433482 failed with status: 1
@ljmf00-wekaio
Copy link
Author

This also triggers:

class Foo
{
    this(void[0] bar) { this.bar = bar; }
    void[0] bar;
}

void main()
{
	void[0] bar;
    auto foo = new Foo(bar);
}

@ljmf00-wekaio
Copy link
Author

Simplest form:

auto foo(void[0] bar) { }

void main()
{
	void[0] bar;
    foo(bar);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant