]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commit
src/listxattr: Fix reading past the end of the user buffer
authorNikolay Borisov <nborisov@suse.com>
Tue, 30 May 2017 14:10:07 +0000 (17:10 +0300)
committerEryu Guan <eguan@redhat.com>
Fri, 2 Jun 2017 03:15:40 +0000 (11:15 +0800)
commit63a912525aabd64b8026bb7bcd02b7a0f504eec4
tree4e5033e4635390f81ac39291a7e2eea7fdbdebaa
parentab6cd253daebc2976fbbf58a359fa01152197445
src/listxattr: Fix reading past the end of the user buffer

listxattr reaturns a null-terminated list of entries that represent
the xattr names. However, if it is passed larger buffer than it
requires it won't zero-out the rest of the memory. The way the
loop iterator in listxattr.c is written makes it go print every
null-terminated entry up to bufsize (which is user passed parameter).
This can lead to a situation where listxattr users N bytes out of
M bytes big buffer ( M > N). This will leave the rest (M-N)
as garbage, which in turn will be printed by listxattr. Fix this
by converting the 'for' loop to 'while' and properly ensuring
we are reading at most howevermany elements the syscall reported
it returned

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
src/listxattr.c