From: Sam James <sam@gentoo.org>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: avoid using fixed char array size for tree names
Date: Fri, 19 Jul 2024 07:07:37 +0100 [thread overview]
Message-ID: <874j8lzzh2.fsf@gentoo.org> (raw)
In-Reply-To: <09fa6dc7de3c7033d92ec7d320a75038f8a94c89.1721364593.git.wqu@suse.com> (Qu Wenruo's message of "Fri, 19 Jul 2024 14:20:39 +0930")
[-- Attachment #1: Type: text/plain, Size: 1710 bytes --]
Qu Wenruo <wqu@suse.com> writes:
> [BUG]
> There is a bug report that using the latest trunk GCC, btrfs would cause
> unterminated-string-initialization warning:
>
> linux-6.6/fs/btrfs/print-tree.c:29:49: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> 29 | { BTRFS_BLOCK_GROUP_TREE_OBJECTID, "BLOCK_GROUP_TREE" },
> |
> ^~~~~~~~~~~~~~~~~~
>
> [CAUSE]
> To print tree names we have an array of root_name_map structure, which
> uses "char name[16];" to store the name string of a tree.
>
> But the following trees have names exactly at 16 chars length:
> - "BLOCK_GROUP_TREE"
> - "RAID_STRIPE_TREE"
>
> This means we will have no space for the terminating '\0', and can lead
> to unexpected access when printing the name.
>
> [FIX]
> Instead of "char name[16];" use "const char *" instead.
>
> Since the name strings are all read-only data, and are all NULL
> terminated by default, there is not much need to bother the length at
> all.
>
> Reported-by: Sam James <sam@gentoo.org>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
Thank you for the quick fix! I agree that this seems like the cleanest
change.
Tested-by: Sam James <sam@gentoo.org>
> ---
> fs/btrfs/print-tree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
> index 32dcea662da3..fc821aa446f0 100644
> --- a/fs/btrfs/print-tree.c
> +++ b/fs/btrfs/print-tree.c
> @@ -14,7 +14,7 @@
>
> struct root_name_map {
> u64 id;
> - char name[16];
> + const char *name;
> };
>
> static const struct root_name_map root_map[] = {
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 377 bytes --]
next prev parent reply other threads:[~2024-07-19 6:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 4:50 [PATCH] btrfs: avoid using fixed char array size for tree names Qu Wenruo
2024-07-19 6:07 ` Sam James [this message]
2024-07-19 13:07 ` Josef Bacik
2024-07-19 23:53 ` David Sterba
2024-07-20 0:31 ` Qu Wenruo
2024-07-21 0:24 ` Qu Wenruo
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=874j8lzzh2.fsf@gentoo.org \
--to=sam@gentoo.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.