Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "Aaro Mäkinen" <aaro@tuxera.com>
To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Cc: linux-fsdevel@vger.kernel.org, stable@vger.kernel.org,
	anton@tuxera.com, "Aaro Mäkinen" <aaro@tuxera.com>
Subject: [PATCH] hfsplus: Return null terminated string from hfsplus_uni2asc()
Date: Tue, 25 Mar 2025 15:29:47 +0200	[thread overview]
Message-ID: <20250325132947.55401-1-aaro@tuxera.com> (raw)

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")
Signed-off-by: Aaro Mäkinen <aaro@tuxera.com>
Reviewed-by: Anton Altaparmakov <anton@tuxera.com>
---
 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


             reply	other threads:[~2025-03-25 13:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-25 13:29 Aaro Mäkinen [this message]
2025-03-25 13:47 ` [PATCH] hfsplus: Return null terminated string from hfsplus_uni2asc() kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250325132947.55401-1-aaro@tuxera.com \
    --to=aaro@tuxera.com \
    --cc=akpm@linux-foundation.org \
    --cc=anton@tuxera.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox