<div dir="ltr"><div class="gmail_extra">Hi Mike, <br><br><div class="gmail_quote">On Fri, Aug 1, 2014 at 4:25 PM, Mike Frysinger <span dir="ltr"><<a href="mailto:vapier@gentoo.org" target="_blank">vapier@gentoo.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu 03 Jul 2014 17:45:41 <a href="mailto:zubin.mithra@gmail.com">zubin.mithra@gmail.com</a> wrote:<br>
> From: Zubin Mithra <<a href="mailto:zubin.mithra@gmail.com">zubin.mithra@gmail.com</a>><br>
><br>
> * file.c (sys_getdents): Add d_reclen check.<br>
> (sys_getdents64): Add d_reclen check.<br>
><br>
> Signed-off-by: Zubin Mithra <<a href="mailto:zubin.mithra@gmail.com">zubin.mithra@gmail.com</a>><br>
> ---<br>
> file.c | 12 ++++++++++--<br>
> 1 file changed, 10 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/file.c b/file.c<br>
> index a92a7dc..d739df6 100644<br>
> --- a/file.c<br>
> +++ b/file.c<br>
> @@ -2041,7 +2041,8 @@ sys_readdir(struct tcb *tcp)<br>
> int<br>
> sys_getdents(struct tcb *tcp)<br>
> {<br>
> - int i, len, dents = 0;<br>
> + unsigned int i;<br>
> + int len, dents = 0;<br>
> char *buf;<br>
><br>
> if (entering(tcp)) {<br>
> @@ -2076,6 +2077,10 @@ sys_getdents(struct tcb *tcp)<br>
> i ? " " : "", d->d_ino, d->d_off);<br>
> tprintf("d_reclen=%u, d_name=\"%s\", d_type=",<br>
> d->d_reclen, d->d_name);<br>
> + if (i + d->d_reclen >= len) {<br>
> + tprints("}");<br>
> + break;<br>
> + }<br>
<br>
</div></div>you shouldn't compare signed & unsigned values. i'm not sure this code needs<br>
to have "i" converted to unsigned considering the top of it makes sure to<br>
clamp the value of len to [0, 1024*1024].<br>
<br>
also, should it be "...}" to indicate that there's something, but we're<br>
ignoring it ? maybe not since we already silently clamp the result ...</blockquote><div><br></div><div>Thank you for the review, Mike ! I've made the two changes and sent over a patch for the same.</div><div><br></div>
<div><br></div><div><br></div><div>Thanks!</div><div>Zubin </div></div></div></div>