public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: Andrey Albershteyn <aalbersh@redhat.com>,
	xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] xfs_scrub: fix buffer overflow in string_escape
Date: Mon, 24 Feb 2025 15:11:03 +0100	[thread overview]
Message-ID: <20250224141103.GB931@lst.de> (raw)
In-Reply-To: <20250220220758.GT21808@frogsfrogsfrogs>

On Thu, Feb 20, 2025 at 02:07:58PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Need to allocate one more byte for the null terminator, just in case the
> /entire/ input string consists of non-printable bytes e.g. emoji.
> 
> Cc: <linux-xfs@vger.kernel.org> # v4.15.0
> Fixes: 396cd0223598bb ("xfs_scrub: warn about suspicious characters in directory/xattr names")
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> ---
>  scrub/common.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scrub/common.c b/scrub/common.c
> index 6eb3c026dc5ac9..7ea0277bc511ce 100644
> --- a/scrub/common.c
> +++ b/scrub/common.c
> @@ -320,7 +320,7 @@ string_escape(
>  	char			*q;
>  	int			x;
>  
> -	str = malloc(strlen(in) * 4);
> +	str = malloc((strlen(in) * 4) + 1);

Nit: no need for the inner braces.

But this open code string allocation and manipulation makes me feel
really bad.  Assuming we don't have a good alternative, can you
at least throw in a comment explaining the allocation length here?


  parent reply	other threads:[~2025-02-24 14:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 22:07 [PATCH] xfs_scrub: fix buffer overflow in string_escape Darrick J. Wong
2025-02-20 22:10 ` [RFC PATCH] generic/45[34]: add colored emoji variants to unicode tests Darrick J. Wong
2025-02-24 14:34   ` Christoph Hellwig
2025-02-24  8:36 ` [PATCH] xfs_scrub: fix buffer overflow in string_escape Andrey Albershteyn
2025-02-24 14:11 ` Christoph Hellwig [this message]
2025-02-24 17:54   ` Darrick J. Wong

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=20250224141103.GB931@lst.de \
    --to=hch@lst.de \
    --cc=aalbersh@redhat.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@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