nuttx/drivers/syslog
Marco Casaroli 5a7f1b5005
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
drivers/syslog: fix syslog_write() returning -EIO on every write
syslog_write_foreach() compares an unsigned count against a signed
accumulator:

  size_t  nwritten     = 0;
  ssize_t nwritten_max = -EIO;
  ...
  if (nwritten > nwritten_max)
    {
      nwritten_max = nwritten;
    }
  return nwritten_max;

The usual arithmetic conversions promote nwritten_max to size_t, so -EIO
becomes 4294967291 on a 32-bit target, and the comparison is never true.
nwritten_max keeps its initial value and the function returns -EIO no
matter how many bytes actually went out.  Observed under gdb on a running
target: nwritten == 64, nwritten_max == -5, (nwritten > nwritten_max) == 0.

Most callers discard the result -- syslog() itself returns void -- so this
is normally invisible.  It becomes fatal when /dev/console is backed by
syslog_console_write(), because then stdio acts on it.
lib_fflush_unlocked() sees a negative return, sets __FS_FLAG_ERROR and
returns early, before resetting fs_bufpos.  The bytes have already been
emitted, but the buffer is never cleared, so every subsequent stdio call
re-flushes the same CONFIG_STDIO_BUFFER_SIZE bytes.  The console fills
with one repeated fragment and the system makes no further progress.

Reaching that state needs CONFIG_CONSOLE_SYSLOG=y together with no driver
claiming /dev/console ahead of syslog_console_init().  Three in-tree
defconfigs qualify: x86/qemu-i486:ostest, renesas/skp16c26:ostest and
x86_64/qemu-intel64:earlyfb.  The other 56 CONSOLE_SYSLOG configurations
have a serial console that registers /dev/console first, which is why this
has gone unnoticed.

Introduced by 1685e8ff7b ("syslog: avoid an infinite loop if one channel
fails"), which changed nwritten_max from size_t to ssize_t = -EIO so that
an all-channels-failed case could be reported.  Give nwritten the same type
so the comparison is signed, which preserves that intent: nwritten_max
stays -EIO only when no channel wrote anything.  nwritten is never negative,
so the remaining comparisons against buflen are unaffected.

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-29 07:57:29 +02:00
..
CMakeLists.txt sched/syslog: Add early_syslog() for early boot or system down debugging 2025-10-31 08:29:17 -03:00
Kconfig drivers/syslog: add millisecond option for syslog timestamp formatting 2026-02-27 08:09:31 -03:00
Make.defs Documentation: Add description for early_syslog() 2025-10-31 08:29:17 -03:00
ramlog.c drivers/: Multiple Drivers Are Registered With World Writable - Part 2 2026-07-15 15:27:28 +08:00
syslog.h syslog/inbuffer: refactor intbuffer to circbuf 2024-12-17 20:48:23 +08:00
syslog_channel.c drivers/syslog/syslog_channel.c: fix incompatible-pointer-types compile errors 2025-08-07 10:16:20 -03:00
syslog_chardev.c drivers/: Multiple Drivers Are Registered With World Writable - Part 2 2026-07-15 15:27:28 +08:00
syslog_console.c drivers/: Multiple Drivers Are Registered With World Writable - Part 2 2026-07-15 15:27:28 +08:00
syslog_consolechannel.c drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
syslog_devchannel.c drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
syslog_device.c style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
syslog_early.c sched/syslog: Add early_syslog() for early boot or system down debugging 2025-10-31 08:29:17 -03:00
syslog_filechannel.c drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
syslog_flush.c drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
syslog_initialize.c drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
syslog_intbuffer.c sched/spin_lock: rename raw_spin_lock to spin_lock_notrace 2025-02-13 20:48:15 +08:00
syslog_rpmsg.c drivers/: Multiple Drivers Are Registered With World Writable - Part 2 2026-07-15 15:27:28 +08:00
syslog_rpmsg.h drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
syslog_rpmsg_server.c drivers/: Multiple Drivers Are Registered With World Writable - Part 2 2026-07-15 15:27:28 +08:00
syslog_stream.c drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
syslog_write.c drivers/syslog: fix syslog_write() returning -EIO on every write 2026-07-29 07:57:29 +02:00
vsyslog.c !nuttx: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-19 16:21:28 +08:00
vsyslog_rfc5424.c drivers/syslog: Add RFC 5424 protocol support 2025-06-13 20:26:57 +08:00