public inbox for linux-bcachefs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: linux-bcachefs@vger.kernel.org
Cc: David Disseldorp <ddiss@suse.de>
Subject: [PATCH] bcachefs: avoid copy from NULL printbuf
Date: Tue, 24 Sep 2024 02:52:15 +0000	[thread overview]
Message-ID: <20240924025215.29891-1-ddiss@suse.de> (raw)

printbuf.buf may be NULL if allocation_failure is set. Check for this
prior to using it as a seq_puts() source.

Fixes: fa8e94faeece1 ("bcachefs: Heap allocate printbufs")
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
test test

 fs/bcachefs/fs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c
index 1aee5bafaae54..6e270bf24591d 100644
--- a/fs/bcachefs/fs.c
+++ b/fs/bcachefs/fs.c
@@ -1931,13 +1931,16 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root)
 {
 	struct bch_fs *c = root->d_sb->s_fs_info;
 	struct printbuf buf = PRINTBUF;
+	int ret = 0;
 
 	bch2_opts_to_text(&buf, c->opts, c, c->disk_sb.sb,
 			  OPT_MOUNT, OPT_HIDDEN, OPT_SHOW_MOUNT_STYLE);
 	printbuf_nul_terminate(&buf);
-	seq_puts(seq, buf.buf);
+	if (buf.allocation_failure)
+		ret = -ENOMEM;
+	else
+		seq_puts(seq, buf.buf);
 
-	int ret = buf.allocation_failure ? -ENOMEM : 0;
 	printbuf_exit(&buf);
 	return ret;
 }
-- 
2.46.1


             reply	other threads:[~2024-09-24  2:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24  2:52 David Disseldorp [this message]
2024-09-25  2:21 ` [PATCH] bcachefs: avoid copy from NULL printbuf Hongbo Li
2024-09-25  4:24   ` David Disseldorp
2024-09-26  1:53     ` Hongbo Li

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=20240924025215.29891-1-ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=linux-bcachefs@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