You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
treewide: avoid 'static sstring' in favor of 'constexpr string_view'
I had problems with fuzzer+address sanitizer `-fsanitize=fuzzer,address`. It worked fine with `SEASTAR_SSTRING` undefined. Enabling `SEASTAR_ASAN_ENABLED` didn't help.
What I gathered is that it was static sstring destructors being called at exit.
IIUC, there is no reason to use `sstring` for static constants, except to avoid copies like in `tls.cc`.
Luckily, it doesn't seem like the `_blobs` map stores any keys that are external to `tls.cc` itself,
which means it should be safe to use `std::string_view` instead.
* Replaced `extern sstring magic_key_suffix` in the websocket header with `constexpr std::string_view` in the `.cc` file.
* Replaced `static const sstring` in `tls.cc` with `constexpr std::string_view`.
* Replaced the `sstring` key in the `credentials_builder::_blobs` map with `std::string_view`.
The Seastar memory allocator + ASAN is quite a complex interaction I can't entirely grasp.
The issue might be deeper and the solution should be different, but this patch seems good to me anyway.
Fixes the following issue:
```
munmap_chunk(): invalid pointer
==350803== ERROR: libFuzzer: deadly signal
#0 0x560609c161aa in __sanitizer_print_stack_trace (iobuf_fuzz_test+0x1df1aa)
#1 0x560609b0fc50 in fuzzer::PrintStackTrace() (iobuf_fuzz_test+0xd8c50)
scylladb#2 0x560609aea8b6 in fuzzer::Fuzzer::CrashCallback() (.part.0) (iobuf_fuzz_test+0xb38b6)
scylladb#3 0x560609aea97a in fuzzer::Fuzzer::StaticCrashSignalCallback() (iobuf_fuzz_test+0xb397a)
scylladb#4 0x7f96d4c4146f (/lib/libc.so.6+0x4146f)
scylladb#5 0x7f96d4c99cdb in __pthread_kill_implementation (/lib/libc.so.6+0x99cdb)
scylladb#6 0x7f96d4c413c5 in gsignal (/lib/libc.so.6+0x413c5)
scylladb#7 0x7f96d4c28939 in abort (/lib/libc.so.6+0x28939)
scylladb#8 0x7f96d4c299a2 in __libc_message_impl.cold (/lib/libc.so.6+0x299a2)
scylladb#9 0x7f96d4ca44e6 in malloc_printerr (/lib/libc.so.6+0xa44e6)
scylladb#10 0x7f96d4ca471b in munmap_chunk (/lib/libc.so.6+0xa471b)
scylladb#11 0x7f96d4ca91df in cfree@GLIBC_2.2.5 (/lib/libc.so.6+0xa91df)
scylladb#12 0x7f96d5d5cba7 in seastar::memory::cpu_pages::do_foreign_free(void*) (libseastar.so+0x35cba7)
scylladb#13 0x7f96d5d5a901 in seastar::basic_sstring<char, unsigned int, 15u, true>::~basic_sstring() (libseastar.so+0x35a901)
scylladb#14 0x7f96d4c436a8 in __cxa_finalize (/lib/libc.so.6+0x436a8)
scylladb#15 0x7f96d5cf2516 in __do_global_dtors_aux (libseastar.so+0x2f2516)
```
```
(lldb) rbreak seastar::basic_sstring<.*>::~basic_sstring
(lldb) r
[...]
* thread #1, name = 'iobuf_fuzz_test', stop reason = breakpoint 1.1
frame #0: 0x00007ffff775a870 libseastar.so`seastar::basic_sstring<char, unsigned int, 15u, true>::~basic_sstring()
libseastar.so`seastar::basic_sstring<char, unsigned int, 15u, true>::~basic_sstring:
-> 0x7ffff775a870 <+0>: pushq %rbp
0x7ffff775a871 <+1>: movq %rsp, %rbp
0x7ffff775a874 <+4>: pushq %r14
0x7ffff775a876 <+6>: pushq %rbx
(lldb) bt
* thread #1, name = 'iobuf_fuzz_test', stop reason = breakpoint 1.1
* frame #0: 0x00007ffff775a870 libseastar.so`seastar::basic_sstring<char, unsigned int, 15u, true>::~basic_sstring()
frame #1: 0x00007ffff68436a9 libc.so.6`__cxa_finalize + 361
frame scylladb#2: 0x00007ffff76f2517 libseastar.so`__do_global_dtors_aux + 39
frame scylladb#3: 0x00007ffff7fc60f2 ld-linux-x86-64.so.2`_dl_call_fini + 82
frame scylladb#4: 0x00007ffff7fc946e ld-linux-x86-64.so.2`_dl_fini + 494
frame scylladb#5: 0x00007ffff6843bf1 libc.so.6`__run_exit_handlers + 433
frame scylladb#6: 0x00007ffff6843cb0 libc.so.6`exit + 32
frame scylladb#7: 0x0000555555598567 iobuf_fuzz_test`fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) + 12311
frame scylladb#8: 0x00005555555d79f3 iobuf_fuzz_test`main + 35
frame scylladb#9: 0x00007ffff682a47e libc.so.6`__libc_start_call_main + 126
frame scylladb#10: 0x00007ffff682a539 libc.so.6`__libc_start_main@@GLIBC_2.34 + 137
frame scylladb#11: 0x0000555555581e25 iobuf_fuzz_test`_start + 37
(lldb) register read rdi
rdi = 0x00007ffff7a57558 libseastar.so`seastar::experimental::websocket::magic_key_suffix
```
Closesscylladb#3159
0 commit comments