From 61d47c1e92166293e76126fb4b7bc207bbce4ea7 Mon Sep 17 00:00:00 2001 From: Dave Slusher Date: Wed, 15 Jan 2025 20:38:30 -0500 Subject: [PATCH] buffer truncation looking up MIME types Per subsequent discussions, switching to BString::SetToFormat which completely eliminates the need for allocating a fixed buffer and will avoid truncation. Change-Id: Ic2a803594877a0a6fb1bc4eba937268351e6f45c Reviewed-on: https://review.haiku-os.org/c/haiku/+/8837 Haiku-Format: Haiku-format Bot Reviewed-by: Adrien Destugues Tested-by: Commit checker robot --- src/kits/storage/mime/AssociatedTypes.cpp | 5 ++--- src/kits/storage/mime/SnifferRules.cpp | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/kits/storage/mime/AssociatedTypes.cpp b/src/kits/storage/mime/AssociatedTypes.cpp index f207ddaa49..d3e208b7b4 100644 --- a/src/kits/storage/mime/AssociatedTypes.cpp +++ b/src/kits/storage/mime/AssociatedTypes.cpp @@ -375,9 +375,8 @@ AssociatedTypes::BuildAssociatedTypesTable() if (subEntry.GetName(subtype) == B_OK) { BPrivate::Storage::to_lower(subtype); - char fulltype[B_PATH_NAME_LENGTH]; - snprintf(fulltype, B_PATH_NAME_LENGTH, "%s/%s", - supertype, subtype); + BString fulltype; + fulltype.SetToFormat("%s/%s", supertype, subtype); // Process the subtype ProcessType(fulltype); diff --git a/src/kits/storage/mime/SnifferRules.cpp b/src/kits/storage/mime/SnifferRules.cpp index f9211fb674..de9ade3122 100644 --- a/src/kits/storage/mime/SnifferRules.cpp +++ b/src/kits/storage/mime/SnifferRules.cpp @@ -373,9 +373,8 @@ SnifferRules::BuildRuleList() if (subEntry.GetName(subtype) == B_OK) { BPrivate::Storage::to_lower(subtype); - char fulltype[B_PATH_NAME_LENGTH]; - snprintf(fulltype, B_PATH_NAME_LENGTH, "%s/%s", - supertype, subtype); + BString fulltype; + fulltype.SetToFormat("%s/%s", supertype, subtype); // Process the subtype ProcessType(fulltype, &bytesNeeded);