Repository navigation
logread: don't crash on a time with a five-digit year - #10
Merged
Merged
Conversation
pylaterreur
force-pushed
the
logread-time-format
branch
from
November 15, 2026 15:10
8935027 to
031ec4a
Compare
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 @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>
robimarko
force-pushed
the
logread-time-format
branch
from
November 15, 2026 17:31
031ec4a to
b0635f4
Compare
|
Thanks! Rebased on top of master and merged! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
log_notify()inlogreadformats each message's time withctime(). musl'sasctime_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 killslogreadand 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 andlogreaddied on their timestamps.ctime()can also return NULL, which was not checked, and a NULL check alone would not help on musl, which crashes insideasctime_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:
ctime()for every year up to 9999, for 2,017,590 times in 6 time zones, on musl and glibc.logreaddies 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.-Werrorflags on glibc and musl.logreadgave 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