If the command `upower -d` is run while a device with no history is attached, the command can crash with a segfault.
Relevant backtrace when compiled from the master branch (f3706d7) with debugging:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff76d8444 in g_variant_unref () from /usr/lib/libglib-2.0.so.0
(gdb) bt
#0 0x00007ffff76d8444 in g_variant_unref () from /usr/lib/libglib-2.0.so.0
#1 0x00007ffff7bc27b2 in up_device_get_history_sync (device=0x7ffff0003c70,
type=0x7ffff7bd23af "charge", timespec=120, resolution=10, cancellable=0x0,
error=0x0) at up-device.c:484
#2 0x00007ffff7bc192d in up_device_to_text_history (device=0x7ffff0003c70,
string=0x7ffff0001920, type=0x7ffff7bd23af "charge") at up-device.c:194
#3 0x00007ffff7bc2391 in up_device_to_text (device=0x7ffff0003c70)
at up-device.c:375
#4 0x0000000000401d14 in main (argc=1, argv=0x7fffffffe748) at up-tool.c:321
(gdb)
This appears to be caused by the fact that if the call to 'up_device_glue_call_get_history_sync' within the 'up_device_get_history_sync' function fails, the 'gva' variable will be left uninitialized. The function later tries to call 'g_variant_unref' on it and fails.
A patch which initializes 'gva' to NULL is attached and resolves the issue for me. A similar fix may also be needed for the 'up_device_get_statistics_sync' function (which follows the same pattern of leaving 'gva' uninitialized).
Created attachment 114095
Patch to fix issue
If the command `upower -d` is run while a device with no history is attached, the command can crash with a segfault.
Relevant backtrace when compiled from the master branch (f3706d7) with debugging:
Program received signal SIGSEGV, Segmentation fault. libglib- 2.0.so. 0 libglib- 2.0.so. 0 get_history_ sync (device= 0x7ffff0003c70, 0x7ffff7bd23af "charge", timespec=120, resolution=10, cancellable=0x0, to_text_ history (device= 0x7ffff0003c70, 0x7ffff0001920, type=0x7ffff7bd23af "charge") at up-device.c:194 0x7ffff0003c70) e748) at up-tool.c:321
0x00007ffff76d8444 in g_variant_unref () from /usr/lib/
(gdb) bt
#0 0x00007ffff76d8444 in g_variant_unref () from /usr/lib/
#1 0x00007ffff7bc27b2 in up_device_
type=
error=0x0) at up-device.c:484
#2 0x00007ffff7bc192d in up_device_
string=
#3 0x00007ffff7bc2391 in up_device_to_text (device=
at up-device.c:375
#4 0x0000000000401d14 in main (argc=1, argv=0x7fffffff
(gdb)
This appears to be caused by the fact that if the call to 'up_device_ glue_call_ get_history_ sync' within the 'up_device_ get_history_ sync' function fails, the 'gva' variable will be left uninitialized. The function later tries to call 'g_variant_unref' on it and fails.
A patch which initializes 'gva' to NULL is attached and resolves the issue for me. A similar fix may also be needed for the 'up_device_ get_statistics_ sync' function (which follows the same pattern of leaving 'gva' uninitialized).