[PATCH V2] hfsplus: Return null terminated string from hfsplus_uni2asc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In case hfsplus_uni2asc() is called with reused buffer there is a
possibility that the buffer contains remains of the last string and the
null character is only after that. This can and has caused problems in
functions that call hfsplus_uni2asc().

Also correct the error handling for call to copy_name() where the above
problem caused error to be not passed in hfsplus_listxattr().

Fixes: 7dcbf17e3f91 ("hfsplus: refactor copy_name to not use strncpy")
Cc: stable@xxxxxxxxxxxxxxx
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Signed-off-by: Aaro Mäkinen <aaro@xxxxxxxxxx>
Reviewed-by: Anton Altaparmakov <anton@xxxxxxxxxx>
---
Changes in v2:
  - Add Cc tag to sign-off area 
---
 fs/hfsplus/unicode.c |  1 +
 fs/hfsplus/xattr.c   | 13 ++++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c
index 73342c925a4b..1f122e3c9583 100644
--- a/fs/hfsplus/unicode.c
+++ b/fs/hfsplus/unicode.c
@@ -246,6 +246,7 @@ int hfsplus_uni2asc(struct super_block *sb,
 	res = 0;
 out:
 	*len_p = (char *)op - astr;
+	*op = '\0';
 	return res;
 }
 
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index 9a1a93e3888b..f20487ad4e8a 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -746,9 +746,16 @@ ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)
 			if (size < (res + name_len(strbuf, xattr_name_len))) {
 				res = -ERANGE;
 				goto end_listxattr;
-			} else
-				res += copy_name(buffer + res,
-						strbuf, xattr_name_len);
+			} else {
+				err = copy_name(buffer + res,
+					strbuf, xattr_name_len);
+				if (err < 0) {
+					res = err;
+					goto end_listxattr;
+				}
+				else
+					res += err;
+			}
 		}
 
 		if (hfs_brec_goto(&fd, 1))
-- 
2.43.0





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux