scoutfs: don't return uninit index entries

Initially the index walking ioctl only ever output a single entry per
iteration.  So the number of entries to return and the next entry
pointer to copy to userspace were maintained in the post-increment of
the for loop.

When we added locking of the index item results we made it possible to
not copy any entries in a loop iteration.  When that happened the nr and
pointer would be incremented without initializing the entry.  The ioctl
caller would see a garbage entry in the results.

This was visible in scoutfs/002 test results on a volume that had an
interesting file population after having run through all the other
scoutfs tests.  The uninitialized entries would show up as garbage in
the size index portion of the test.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2017-08-29 11:03:49 -07:00
parent a8db7e5b74
commit 599269e539

View File

@@ -123,8 +123,7 @@ static long scoutfs_ioc_walk_inodes(struct file *file, unsigned long arg)
if (ret < 0)
goto out;
for (nr = 0; nr < walk.nr_entries;
nr++, walk.entries_ptr += sizeof(ent)) {
for (nr = 0; nr < walk.nr_entries; ) {
ret = scoutfs_item_next_same(sb, &key, &last_key, NULL, lock->end);
if (ret < 0 && ret != -ENOENT)
@@ -178,6 +177,9 @@ static long scoutfs_ioc_walk_inodes(struct file *file, unsigned long arg)
break;
}
nr++;
walk.entries_ptr += sizeof(ent);
scoutfs_key_inc_cur_len(&key);
}