<div dir="ltr">Hi guys,<div><br></div><div>I don't see my previous email in the <a href="https://lists.linutronix.de/pipermail/minicoredumper/" target="_blank">https://lists.linutronix.de/pipermail/minicoredumper/</a><br>And I also don't see any feedback. Not sure whether you received the email. </div><div>So I re-sent the email again.  :) </div><div><br></div><div>Best Regards,</div><div>Dongyang</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Dongyang <<a href="mailto:dongyang626@gmail.com" target="_blank">dongyang626@gmail.com</a>> 于2023年3月20日周一 22:17写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Dear all,</div><div><br></div><div>I created an issue at  <a href="https://github.com/diamon/minicoredumper/issues/8" target="_blank">https://github.com/diamon/minicoredumper/issues/8</a></div><div>Maybe some guys only check their email. So I also forward the contents to this mailing list, thanks :) </div><div><br></div><div>In the below situation, the read will in an infinite loop:<br><br>If the PID 123 triggered the core dump and Minicoredumper started to read the /proc/123/mem (dump_compressed_tar-->copy_data-->read_file_fd).<br>At this time, if the OOM is triggered, then the PID 123 is killed by SIGKILL.<br>The read will return zero. <br><br>But in the read_file_fd, the code doesn't check the zero condition.   When the "r" is 0,  the "len" will never to 0,  then into an infinite loop. <div dir="auto" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,47);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px;overflow:visible"><pre style="box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace;font-size:11.9px;margin-top:0px;margin-bottom:0px;padding:16px;overflow:auto;line-height:1.45;border-radius:6px;word-break:normal"><span style="box-sizing:border-box">static</span> <span style="box-sizing:border-box">ssize_t</span> <span style="box-sizing:border-box">read_file_fd</span>(<span style="box-sizing:border-box">int</span> fd, <span style="box-sizing:border-box">char</span> *dst, <span style="box-sizing:border-box">int</span> len)
{
        <span style="box-sizing:border-box">size_t</span> size = <span style="box-sizing:border-box">0</span>;
        <span style="box-sizing:border-box">int</span> r;

        <span style="box-sizing:border-box">do</span> {
                r = <span style="box-sizing:border-box">read</span>(fd, dst + size, len);

                <span style="box-sizing:border-box">if</span> (r == -<span style="box-sizing:border-box">1</span>) {
                        <span style="box-sizing:border-box">info</span>(<span style="box-sizing:border-box"><span style="box-sizing:border-box">"</span>Couldn't read file fd=<span style="box-sizing:border-box">%d</span>; error <span style="box-sizing:border-box">%s</span><span style="box-sizing:border-box">"</span></span>, fd,
                             <span style="box-sizing:border-box">strerror</span>(errno));
                        <span style="box-sizing:border-box">return</span> r;
                }

                <span style="box-sizing:border-box">if</span> (r > <span style="box-sizing:border-box">0</span>) {

                        size += r;
                        len -= r;
                }
        } <span style="box-sizing:border-box">while</span> (len > <span style="box-sizing:border-box">0</span>);

        <span style="box-sizing:border-box">return</span> size;
}</pre></div>I'm also checking whether the read return zero is reasonable.  Maybe it should return -1 (Input/output error)?<br><br>Anyway, I think we need to add a check for "read return 0". <br><br>Here is our patch, please check it, thanks :)<p dir="auto" style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,47);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px"><a href="https://github.com/diamon/minicoredumper/files/11019031/0001-minicoredumper-add-return-check-for-read-funcfion.patch" style="box-sizing:border-box;background-color:transparent;text-decoration-line:none" target="_blank">0001-minicoredumper-add-return-check-for-read-funcfion.patch</a></p></div><div><br></div><div>Best Regards,</div><div>Dongyang</div></div>
</blockquote></div></div>