khvzak / bluez-tools

A set of tools to manage bluetooth devices for linux
GNU General Public License v2.0
176 stars 51 forks source link

Possibly improper error handling #50

Open musteresel opened 3 years ago

musteresel commented 3 years ago

https://github.com/khvzak/bluez-tools/blob/f65321736475429316f07ee94ec0deac8e46ec4a/src/bt-obex.c#L587-L589

device here can be NULL. If it is, it causes an assertion in device_get_address to fail (so at least it crashes early):

(gdb) run -a "60:57:18:21:55:5B" -p "24:41:8C:A8:7D:5B" main.qml
Starting program: /nix/store/blrjp452yrhyy2i3yadfd60bral7ps75-bluez-tools-2016-12-12/bin/bt-obex -a "60:57:18:21:55:5B" -p "24:41:8C:A8:7D:5B" main.qml
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libthread_db.so.1".
[New Thread 0x7fffea693700 (LWP 32736)]
[New Thread 0x7fffe9e92700 (LWP 32737)]
**
ERROR:lib/bluez/device.c:265:device_get_address: assertion failed: (DEVICE_IS(self))
Bail out! ERROR:lib/bluez/device.c:265:device_get_address: assertion failed: (DEVICE_IS(self))

Thread 1 "bt-obex" received signal SIGABRT, Aborted.
0x00007ffff7aa508a in raise () from /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7aa508a in raise () from /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libc.so.6
#1  0x00007ffff7a8f528 in abort () from /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libc.so.6
#2  0x00007ffff7ec1dd3 in g_assertion_message.cold () from /nix/store/m7f15ibdd637dy3aysakk47xkqzj956l-glib-2.64.5/lib/libglib-2.0.so.0
#3  0x00007ffff7f1d61b in g_assertion_message_expr () from /nix/store/m7f15ibdd637dy3aysakk47xkqzj956l-glib-2.64.5/lib/libglib-2.0.so.0
#4  0x000000000040d1b1 in device_get_address ()
#5  0x0000000000404a18 in main ()

Not sure why device is NULL for me, but that's a different story.

Also not sure about the level of "NULL checks" in general, so feel free to ignore/close if this is "normal" and wanted behavior (the assertion at least catches it).