<div dir="ltr">I agree, thanks Jini for the clarification. And to talk about the other case of pread in the file for completeness:<div><br></div><div>- The pread that tests <= 0 actually is correct: as you state it is in a loop so there are two cases:</div><div>Â Â Â - pread returns -1 and it is a failure, we break and after the loop we check if there is any residual bytes that should be read, if so we fail</div><div>Â Â Â - pread returns 0 because it is the end was found (the len provided is a min of what is remaining and the map_info size)</div><div><br></div><div>So its test <=0 is the right thing to do.</div><div><br></div><div>- In the case of the code you changed, you are right; looking at the ELF format, the section header table is at the end of the file, so you can't have a segment that is at the end; hence it can never have a return 0 (or it would be an error as you stated).</div><div><br></div><div>Thanks for taking the time to look and explain it to me :),</div><div><br></div><div>Looks good to me (not a reviewer though),</div><div>Jc</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Sep 18, 2018 at 10:26 AM Jini George <<a href="mailto:jini.george@oracle.com">jini.george@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi JC,<br>
<br>
Thank you for looking into this. Since we are reading the PT_INTERP <br>
segment in this case to get the path of the dynamic linker, and since <br>
p_filesz denotes the size of the segment (in this case, it would be the <br>
size of the string denoting the path of the dynamic linker), if we end <br>
up reading anything less than p_filesz, it should be an error. If <br>
pread() returns a zero denoting an EOF while we are reading in the <br>
PT_INTERP segment, I guess it would mean that we are dealing with a <br>
truncated or a possibly corrupted file.<br>
<br>
Thanks!<br>
Jini.<br>
<br>
<br>
On 9/18/2018 7:46 PM, JC Beyler wrote:<br>
> Hi Jini,<br>
> <br>
> I was looking at the man page and am curious: it says that the method <br>
> returns 0 if the end-of-file is reached, does that never happen in this <br>
> case?<br>
> <br>
> (seems like -1 is the error code and another call to pread in the file <br>
> just checks for <= 0; which also is weird since 0 just means end of file).<br>
> <br>
> Thanks,<br>
> Jc<br>
> <br>
> On Tue, Sep 18, 2018 at 6:06 AM Thomas Stüfe <<a href="mailto:thomas.stuefe@gmail.com" target="_blank">thomas.stuefe@gmail.com</a> <br>
> <mailto:<a href="mailto:thomas.stuefe@gmail.com" target="_blank">thomas.stuefe@gmail.com</a>>> wrote:<br>
> <br>
>Â Â Â Looks good. Thanks for fixing.<br>
> <br>
>Â Â Â ..Thomas<br>
> <br>
>Â Â Â On Tue, Sep 18, 2018 at 1:52 PM, Jini George <<a href="mailto:jini.george@oracle.com" target="_blank">jini.george@oracle.com</a><br>
>Â Â Â <mailto:<a href="mailto:jini.george@oracle.com" target="_blank">jini.george@oracle.com</a>>> wrote:<br>
>Â Â Â > Hi all,<br>
>Â Â Â ><br>
>Â Â Â > Please review the small change for fixing the build failure in<br>
>Â Â Â > src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c with<br>
>Â Â Â > -Werror=unused-result.<br>
>Â Â Â ><br>
>Â Â Â > <a href="https://bugs.openjdk.java.net/browse/JDK-8210836" rel="noreferrer" target="_blank">https://bugs.openjdk.java.net/browse/JDK-8210836</a><br>
>Â Â Â > Webrev: <a href="http://cr.openjdk.java.net/~jgeorge/8210836/webrev.00/" rel="noreferrer" target="_blank">http://cr.openjdk.java.net/~jgeorge/8210836/webrev.00/</a><br>
>Â Â Â <<a href="http://cr.openjdk.java.net/%7Ejgeorge/8210836/webrev.00/" rel="noreferrer" target="_blank">http://cr.openjdk.java.net/%7Ejgeorge/8210836/webrev.00/</a>><br>
>Â Â Â ><br>
>Â Â Â > A quick review would be appreciated.<br>
>Â Â Â ><br>
>Â Â Â > Thank you!<br>
>Â Â Â > Jini.<br>
> <br>
> <br>
> <br>
> -- <br>
> <br>
> Thanks,<br>
> Jc<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><br></div>Thanks,<div>Jc</div></div></div>