-
-
Notifications
You must be signed in to change notification settings - Fork 604
-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
[BUG] segfault if a non-UTF-8 locale is being used #3
Comments
@NexAdn
As I understood it, std::thread is not guaranteed to be using posix threads which I need to block the signal handlers inside the thread. Was using std::thread when I started writing, but changed since I didn't know if the blocking would work in every case. Thanks for suggested fixes :) |
Fixed in commit fca1d8c |
v1.0.1 "Bug fixes" released. Closing. |
First of all: Nice work! I'm looking forward to using btop++ on my machines.
Describe the bug
When
$LANG
has a non-UTF-8 locale set (or a locale without the exact suffixUTF-8
, e.g. ´de_DE.utf8`), the program terminates with a segfault.To Reproduce
$ LANG=de_DE.utf8 ./bin/btop # for a build inside the repo
Expected behavior
The program should accept the locale and start as expected or don't accept the locale and exit with an error message.
Screenshots
No screenshots, but see this gdb output:
Info (please complete the following information):
5.4.80-gentoo-x86_64
Additional context
contents of
~/.config/btop/error.log
: file non-existent since the program couldn't start properlySince I have
LANG=de_DE.utf8
set and thus a UTF-8-capable locale, starting btop with--utf-force
helped as a workaround. However, the proper behavior should be thatLANG=de_DE.utf8
should be recognized as UTF-8-capable locale and thus the program shouldn't even get to the point of trying to generate an error message.I've already found the offending line:
btop/src/btop.cpp
Line 728 in 480b421
with a bit of context:
btop/src/btop.cpp
Lines 705 to 728 in 480b421
So one issue is that the locale didn't get recognized as UTF-8 properly.
The more important issue here is that btop probably tries to join a pthread which it never created–more or less a use-before-malloc:
btop/src/btop.cpp
Lines 705 to 728 in 480b421
So the proper fix for the second issue is probably just checking if
Runner::runner_id
is a valid thread (i.e. has been created).But on that notice, why bother using pthread directly and not
std::thread
?If it's because an
std::thread
on the stack automatically starts a thread, just wrap it inside astd::unique_ptr
.A check using
std::unique_ptr::operator bool
then is a very convenient method to check if there is a thread possibly running.Also, you don't have to take care of cleaning up after the thread since
std::unique_ptr
does that for you.But that's just an idea.
I suppose you had a valid reason to use pthread directly.
The text was updated successfully, but these errors were encountered: