Skip to content

Commit 14fb39a

Browse files
zhaoxiangchen777simbit18
authored andcommitted
sched/misc: fix incomplete data emission in coredump elf_emit function
The elf_emit() function in coredump.c was only checking for negative returnvalues from lib_stream_puts() to detect write failures. However, lib_stream_puts()can return 0 to indicate that no bytes were written (e.g., due to stream full,end-of-file, or other non-error conditions that prevent data writing). This oversight meant that cases where lib_stream_puts() returned 0 would bypassthe error handling, leading to incomplete data emission in the core dump withoutany failure indication. The loop would continue attempting to write the remainingdata, resulting in partial or corrupted core dump files. This fix modifies the condition from ret < 0 to ret <= 0 to: 1. Catch both error conditions (negative return values) and zero-byte writes. 2. Immediately break the write loop and propagate the failure, ensuring the core dump process correctly aborts when data cannot be written. This change improves the reliability of core dump generation by ensuring allfailed or incomplete write attempts are properly handled, preventing corruptedcore dump files. Signed-off-by: chao an <anchao.archer@bytedance.com>
1 parent 4b09f34 commit 14fb39a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

sched/misc/coredump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
149149
while (total > 0)
150150
{
151151
ret = lib_stream_puts(cinfo->stream, ptr, total);
152-
if (ret < 0)
152+
if (ret <= 0)
153153
{
154154
break;
155155
}

0 commit comments

Comments
 (0)