Skip to content

logread: don't crash on a time with a five-digit year - #10

Merged
openwrt-bot merged 1 commit into
openwrt:masterfrom
pylaterreur:logread-time-format
Nov 15, 2026
Merged

openwrt-bot merged 1 commit into
openwrt:masterfrom
pylaterreur:logread-time-format

Conversation

@pylaterreur

Copy link
Copy Markdown
Contributor

log_notify() in logread formats each message's time with ctime(). musl's asctime_r() aborts on purpose when the result does not fit its 26-byte buffer, which is the case for any year after 9999, so one message with a bogus time kills logread and cuts off the rest of its output. That is how the ring buffer bug of FS#4118 showed up (see #9): logd handed out stale entries and logread died on their timestamps. ctime() can also return NULL, which was not checked, and a NULL check alone would not help on musl, which crashes inside asctime_r() before it can return.

The message is now skipped when its time cannot be converted or its year is after 9999, as a message with a missing field is skipped. Linux cannot set its clock past 2262, so only corrupt entries are skipped; every other time is printed as before. I did not use strftime(): on musl it costs about 9% more instructions for a whole read.

Tested:

  • Output is byte-identical to ctime() for every year up to 9999, for 2,017,590 times in 6 time zones, on musl and glibc.
  • With a fake log server sending chosen times, stock musl logread dies on the first year-10000 entry and loses the rest of the output; with this change it skips the 3 impossible entries and prints the rest.
  • Builds with ubox's -Werror flags on glibc and musl.
  • With stock logd and the FS#4118 reproducer, the patched logread gave no crash; with the fix of logd: don't hand out stale entries after the ring wraps #9 as well, no crash and no bad line.

This is independent of #9, and still useful once #9 is in, as a guard against one bad entry.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN

@pylaterreur

pylaterreur commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Gentle ping: rebased on the latest master, now that #9 and #11 are merged. A real clock can't reach a five-digit year, so this is only a guard: one corrupt message time (as in FS#4118) makes musl's asctime_r() abort and logread loses the rest of its output. The patch skips such a message; output is unchanged for every other time. It's a 7-line change, fine to close if you think it's not needed now that the ring buffer bugs are fixed.

@robimarko, @Ansuel, could one of you take a look? Thanks!

log_notify() formats each message's time with ctime(). musl's
asctime_r() aborts on purpose when the result does not fit in its
26-byte buffer, which happens for any year after 9999. So one message
with a bogus time kills logread and cuts off the rest of its output.
That is how the ring buffer bug of FS#4118 showed up: logd handed out
stale entries, and logread died on their timestamps. ctime() can also
return NULL, which was not checked.

Skip a message whose time cannot be converted or has a year after
9999, as a message with a missing field is skipped. Linux cannot set
its clock past 2262, so only corrupt entries are skipped. All other
times are printed as before.

Assisted-by: Claude:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
Signed-off-by: Pierre-Yves Le Borgne <pylaterreur@gmail.com>
Link: openwrt#10
Signed-off-by: Robert Marko <robimarko@gmail.com>
@openwrt-bot
openwrt-bot merged commit b0635f4 into openwrt:master Nov 15, 2026
@robimarko

Copy link
Copy Markdown

Thanks! Rebased on top of master and merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants