main/openrc-0.42-r17: rc-status segfaults
running rc-status segfaults (on armv7 postmarketOS device, probably irrelevant)
with musl-dbg, gdb, openrc-dbg installed I can get backtrace:
$ gdb rc-status
...
Reading symbols from rc-status...
Reading symbols from /usr/lib/debug//bin/rc-status.debug...
(gdb) r
Starting program: /bin/rc-status
Runlevel: default
udev-postmount [ started ]
Program received signal SIGSEGV, Segmentation fault.
0xb6fb84a4 in memchr (src=src@entry=0xe, c=c@entry=0, n=n@entry=2147483647) at src/string/memchr.c:16
16 src/string/memchr.c: No such file or directory.
(gdb) bt
#0 0xb6fb84a4 in memchr (src=src@entry=0xe, c=c@entry=0, n=n@entry=2147483647) at src/string/memchr.c:16
#1 0xb6fb8dae in strnlen (s=s@entry=0xe <error: Cannot access memory at address 0xe>, n=2147483647) at src/string/strnlen.c:5
#2 0xb6f8f3d0 in printf_core (f=f@entry=0xbefffb40, fmt=fmt@entry=0x4039c9 "%ld day(s) %02ld:%02ld:%02ld (%s)", ap=ap@entry=0xbefffa3c, nl_arg=nl_arg@entry=0xbefffa68, nl_type=<optimized out>,
nl_type@entry=0xbefffa40) at src/stdio/vfprintf.c:594
#3 0xb6fb7642 in vfprintf (f=0xbefffb40, fmt=fmt@entry=0x4039c9 "%ld day(s) %02ld:%02ld:%02ld (%s)", ap=..., ap@entry=...) at src/stdio/vfprintf.c:683
#4 0xb6fa4e68 in vsnprintf (s=s@entry=0xb6ff6790 "", n=n@entry=4096, fmt=fmt@entry=0x4039c9 "%ld day(s) %02ld:%02ld:%02ld (%s)", ap=..., ap@entry=...) at src/stdio/vsnprintf.c:54
#5 0x004022c8 in vsnprintf (__v=..., __f=0x4039c9 "%ld day(s) %02ld:%02ld:%02ld (%s)", __n=4096, __s=0xb6ff6790 "") at /usr/include/fortify/stdio.h:77
#6 xasprintf (strp=strp@entry=0xbefffc58, fmt=0x4039c9 "%ld day(s) %02ld:%02ld:%02ld (%s)") at ../includes/helpers.h:152
#7 0x00402540 in get_uptime (service=0xb6f42900 "dbus") at rc-status.c:130
#8 print_service (service=0xb6f42900 "dbus", format=format@entry=FORMAT_DEFAULT) at rc-status.c:175
#9 0x00402748 in print_services (runlevel=0xb6f74c90 "default", svcs=0xb6f46dd0, format=format@entry=FORMAT_DEFAULT) at rc-status.c:242
#10 0x00401e0c in main (argc=<optimized out>, argv=<optimized out>) at rc-status.c:386
(gdb)
possible reason: device has invalid time during early startup (until networking works and chronyd synchronizes time), so like 1 jan 1970 and so service uptime string is too long and some buffer overflows?
======================================= edit
(gdb) frame 7
(gdb) info locals
diff_days = 18063
diff_mins = 36
diff_secs = 50
state = <optimized out>
start_count = 0xb6f42ef0 "0"
time_diff = <optimized out>
diff_hours = 8
now = <optimized out>
start_time_string = <optimized out>
start_time = <optimized out>
uptime = 0x0
state = <optimized out>
start_count = <optimized out>
now = <optimized out>
start_time_string = <optimized out>
start_time = <optimized out>
time_diff = <optimized out>
diff_days = <optimized out>
diff_hours = <optimized out>
diff_mins = <optimized out>
diff_secs = <optimized out>
uptime = <optimized out>
edit 2
during compilation gcc complains about printf format mismatch for each time_t argumnet
rc-status.c:134:10: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'time_t' {aka 'long long int'} [-Wformat=]
134 | "%ld day(s) %02ld:%02ld:%02ld (%s)",
| ~~^
| |
| long int
| %lld
135 | diff_days, diff_hours, diff_mins, diff_secs,
| ~~~~~~~~~
| |
| time_t {aka long long int}
Edited by Alexey Minnekhanov