[PATCH v2] Add bounds checking to sys_getdents, sys_getdents64
zubin.mithra at gmail.com
zubin.mithra at gmail.com
Mon Aug 4 02:12:57 UTC 2014
From: Zubin Mithra <zubin.mithra at gmail.com>
* file.c (sys_getdents): Add d_reclen check.
(sys_getdents64): Add d_reclen check.
Signed-off-by: Zubin Mithra <zubin.mithra at gmail.com>
---
file.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/file.c b/file.c
index a92a7dc..0934ce1 100644
--- a/file.c
+++ b/file.c
@@ -2076,6 +2076,10 @@ sys_getdents(struct tcb *tcp)
i ? " " : "", d->d_ino, d->d_off);
tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
d->d_reclen, d->d_name);
+ if (i + d->d_reclen >= len) {
+ tprints("...}");
+ break;
+ }
printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
tprints("}");
}
@@ -2138,8 +2142,13 @@ sys_getdents64(struct tcb *tcp)
tprints("d_type=");
printxval(direnttypes, d->d_type, "DT_???");
tprints(", ");
- tprintf("d_reclen=%u, d_name=\"%s\"}",
+ tprintf("d_reclen=%u, d_name=\"%s\"",
d->d_reclen, d->d_name);
+ if (i + d->d_reclen >= len) {
+ tprints("...}");
+ break;
+ }
+ tprints("}");
}
if (!d->d_reclen) {
tprints("/* d_reclen == 0, problem here */");
--
1.8.4
More information about the Strace-devel
mailing list