[LEDE-DEV] Bug when processing long lines
Jakub Horák
jakub.horak at braiins.cz
Thu Jan 11 08:28:30 PST 2018
Hello LEDE developers,
I found a bug in procd that gets triggered when long lines are printed
by services whose stdout/stderr are being logged. The bug itself is
explained in the attached patch.
However, when I was testing the fix, I found out that the bug is present
in other places, mostly those that call "ustream_get_read_buf" function.
Some examples:
- ubox/log/logread.c:logread_fb_data_cb() - when buffer passed on the
descriptor is larger than 4096, reception stops
- netifd/main.c:netifd_process_log_read_cb - this is a place that seems
to have this bug fixed, but still has incorrect handling of NUL bytes
- libubox/examples/ustream-example.c:client_read_cb - this is probably
the place that originated this broken bit of code
- uhttpd/relay.c:relay_process_headers - another place that seems broken
I've attached an init script (that goes to /etc/init.d/flood) and three
Lua programs (flood[123].lua) that trigger this behavior:
- flood1.lua writes long message to stdout, that triggers this behavior
in procd
- flood2.lua writes message that gets correctly processed by procd, but
triggers the bug in logread
- flood3.lua writes message with embedded zeros
I don't post patches to mailing lists very often, so I apologize if I'm
sending this in a wrong format or in a too broken english.
Best regards,
Jakub Horak
-------------- next part --------------
#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
PROG=/bin/flood1.lua
start_service()
{
config_load cgminer
procd_open_instance
procd_set_param command "$PROG"
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-0}
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
stop_service()
{
echo stop
}
service_triggers()
{
procd_add_reload_trigger "flood"
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flood1.lua
Type: text/x-lua
Size: 183 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20180111/5fca3259/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flood2.lua
Type: text/x-lua
Size: 160 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20180111/5fca3259/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flood3.lua
Type: text/x-lua
Size: 180 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20180111/5fca3259/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-procd-Fix-behavior-when-parsing-long-lines.patch
Type: text/x-patch
Size: 2287 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20180111/5fca3259/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20180111/5fca3259/attachment.sig>
More information about the Lede-dev
mailing list