From 2d6a1945f0f879d88980f3bc9748dc5f32957426 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 28 Aug 2025 19:38:12 -0400 Subject: [PATCH] ramfs: Put key length in the type in Attribute::GetKey. Many of the callers of this method didn't initialize the length parameter properly, which led to uninitialized memory being used as part of the min() calculation, which caused all sorts of problems. Now we don't require them to pass in anything, and use the constant directly. Fixes #19252. --- src/add-ons/kernel/file_systems/ramfs/Attribute.cpp | 8 +++----- src/add-ons/kernel/file_systems/ramfs/Attribute.h | 5 +++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp index dc83f45c11..1ab167a228 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp @@ -7,7 +7,6 @@ #include "Attribute.h" #include "Misc.h" #include "Node.h" -#include "ramfs.h" #include "Volume.h" // constructor @@ -102,7 +101,7 @@ Attribute::_Changed(uint8* oldKey, size_t oldLength, off_t changeOffset, ssize_t // update live queries uint8 newKey[kMaxIndexKeyLength]; - size_t newLength = kMaxIndexKeyLength; + size_t newLength; GetKey(newKey, &newLength); GetVolume()->UpdateLiveQueries(NULL, fNode, GetName(), fType, oldKey, oldLength, newKey, newLength); @@ -125,10 +124,9 @@ Attribute::SetIndex(AttributeIndex *index, bool inIndex) // GetKey void -Attribute::GetKey(uint8 *key, size_t *length) +Attribute::GetKey(uint8 key[kMaxIndexKeyLength], size_t *length) { - *length = min(*length, kMaxIndexKeyLength); - ReadAt(0, key, *length, length); + ReadAt(0, key, kMaxIndexKeyLength, length); } // AttachAttributeIterator diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.h b/src/add-ons/kernel/file_systems/ramfs/Attribute.h index 5cf007c673..9dca961985 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Attribute.h +++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.h @@ -11,6 +11,7 @@ #include "AttributeIterator.h" #include "DataContainer.h" #include "String.h" +#include "ramfs.h" class AllocationInfo; class Node; @@ -36,13 +37,13 @@ public: off_t GetSize() const { return DataContainer::GetSize(); } virtual status_t WriteAt(off_t offset, const void *buffer, size_t size, - size_t *bytesWritten); + size_t *bytesWritten); // index support void SetIndex(AttributeIndex *index, bool inIndex); AttributeIndex *GetIndex() const { return fIndex; } bool IsInIndex() const { return fInIndex; } - void GetKey(uint8 *key, size_t *length); + void GetKey(uint8 key[kMaxIndexKeyLength], size_t *length); // iterator management void AttachAttributeIterator(AttributeIterator *iterator);