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

UBSan seems to have started to complain that a null pointer is passed as argument 1 to qsort #10096

Closed
evverx opened this issue Sep 16, 2018 · 3 comments
Labels
bug 🐛 Programming errors, that need preferential fixing login

Comments

@evverx
Copy link
Member

evverx commented Sep 16, 2018

It seems that qsort that UBSan is complaining about was introduced in 0a16658. Below is the full backtrace:

../src/libsystemd/sd-device/device-enumerator.c:833:9: runtime error: null pointer passed as argument 1, which is declared to never be null
    #0 0x7fa017d893bf in device_enumerator_scan_devices ../src/libsystemd/sd-device/device-enumerator.c:833
    #1 0x7fa017d89514 in sd_device_enumerator_get_device_first ../src/libsystemd/sd-device/device-enumerator.c:846
    #2 0x55d41d24f8bb in manager_enumerate_devices ../src/login/logind.c:178
    #3 0x55d41d25aa85 in manager_startup ../src/login/logind.c:1095
    #4 0x55d41d25bd75 in main ../src/login/logind.c:1212
    #5 0x7fa01605af29 in __libc_start_main (/lib64/libc.so.6+0x20f29)
    #6 0x55d41d24d4f9 in _start (/usr/lib/systemd/systemd-logind+0x874f9)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/libsystemd/sd-device/device-enumerator.c:833:9 in

@yuwata could you take a look?

@evverx evverx added bug 🐛 Programming errors, that need preferential fixing login labels Sep 16, 2018
evverx added a commit to evverx/systemd that referenced this issue Sep 16, 2018
This should make it easier to get backtraces that can be
pasted into issues like systemd#10096.
@evverx
Copy link
Member Author

evverx commented Sep 16, 2018

Looking at 7ff7394, I think replacing qsort with qsort_safe should be enough to fix the issue.

yuwata added a commit to yuwata/systemd that referenced this issue Sep 16, 2018
The number of found devices may be zero. So, let's use qsort_safe().

Fixes systemd#10096.
yuwata added a commit to yuwata/systemd that referenced this issue Sep 16, 2018
The number of found devices may be zero. So, let's use qsort_safe().

Follow-up for 0a16658.
Fixes systemd#10096.
@yuwata
Copy link
Member

yuwata commented Sep 16, 2018

Thank you!

@evverx
Copy link
Member Author

evverx commented Sep 16, 2018

Interestingly, I've just learnt that an even safer version of "qsort" called "typesafe_qsort" was added recently. It's not to say that #10099 should be changed. Just something to think about later.

@yuwata thanks again for fixing it!

yuwata added a commit that referenced this issue Sep 16, 2018
The number of found devices may be zero. So, let's use qsort_safe().

Follow-up for 0a16658.
Fixes #10096.
keszybz pushed a commit that referenced this issue Sep 16, 2018
This should make it easier to get backtraces that can be
pasted into issues like #10096.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Programming errors, that need preferential fixing login
Development

No branches or pull requests

2 participants