From: David van Moolenbroek Date: Sun, 1 Feb 2015 15:29:13 +0000 (+0000) Subject: libsffs, libvtreefs: fix getdents bug X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=f912036bae268f57981b9669ff4eec080a61f3cf;p=minix.git libsffs, libvtreefs: fix getdents bug Bad logic introduced as part of the fsdriver changes could cause getdents to terminate early in these libraries. Issue reported by r0ller. Change-Id: If450d5ea85e830584878d8a4ec0f00519355a353 --- diff --git a/minix/lib/libsffs/read.c b/minix/lib/libsffs/read.c index 58586102b..bb922f9a1 100644 --- a/minix/lib/libsffs/read.c +++ b/minix/lib/libsffs/read.c @@ -98,7 +98,7 @@ ssize_t do_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, * the "." entry, the second position is for the ".." entry, and the next * position numbers each represent a file in the directory. */ - do { + for (;;) { /* Determine which inode and name to use for this entry. * We have no idea whether the host will give us "." and/or "..", * so generate our own and skip those from the host. @@ -165,7 +165,9 @@ ssize_t do_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, if (r < 0) return r; - } while (r > 0); + if (r == 0) + break; + } return fsdriver_dentry_finish(&fsdentry); } diff --git a/minix/lib/libvtreefs/file.c b/minix/lib/libvtreefs/file.c index 3d3b2c9fe..2542ebc8e 100644 --- a/minix/lib/libvtreefs/file.c +++ b/minix/lib/libvtreefs/file.c @@ -223,7 +223,7 @@ fs_getdents(ino_t ino_nr, struct fsdriver_data * data, size_t bytes, fsdriver_dentry_init(&fsdentry, data, bytes, buf, bufsize); - do { + for (;;) { /* Determine which inode and name to use for this entry. */ pos = (*posp)++; @@ -287,7 +287,9 @@ fs_getdents(ino_t ino_nr, struct fsdriver_data * data, size_t bytes, IFTODT(child->i_stat.mode)); if (r < 0) return r; - } while (r > 0); + if (r == 0) + break; + } return fsdriver_dentry_finish(&fsdentry); }