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.
This commit is contained in:
Augustin Cavalier
2025-08-28 19:38:12 -04:00
parent 8f7bb51e20
commit 2d6a1945f0
2 changed files with 6 additions and 7 deletions
@@ -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
@@ -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);