From 949eb7599b0adfc62fbbb916631af09182f4c71a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 15 Mar 2024 00:23:29 +0100 Subject: [PATCH] btrfs-progs: handle internal errors in btrfs_assert_feature_buf_size() The buffer size check is needed and has already caught problems when adding the raid-stripe-tree, do a better error reporting. Signed-off-by: David Sterba --- common/fsfeatures.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common/fsfeatures.c b/common/fsfeatures.c index ededeae6..2ce11327 100644 --- a/common/fsfeatures.c +++ b/common/fsfeatures.c @@ -312,12 +312,21 @@ void btrfs_assert_feature_buf_size(void) for (i = 0; i < ARRAY_SIZE(mkfs_features); i++) /* The extra 2 bytes are for the ", " prefix. */ total_size += strlen(mkfs_features[i].name) + 2; - BUG_ON(BTRFS_FEATURE_STRING_BUF_SIZE < total_size); + + if (BTRFS_FEATURE_STRING_BUF_SIZE < total_size) { + internal_error("string buffer for freature list too small: want %d\n", + total_size); + abort(); + } total_size = 0; for (i = 0; i < ARRAY_SIZE(runtime_features); i++) total_size += strlen(runtime_features[i].name) + 2; - BUG_ON(BTRFS_FEATURE_STRING_BUF_SIZE < total_size); + if (BTRFS_FEATURE_STRING_BUF_SIZE < total_size) { + internal_error("string buffer for freature list too small: want %d\n", + total_size); + abort(); + } } static size_t get_feature_array_size(enum feature_source source)