ReaderImplBase: Verify that the attribute type matches
... the one expected for the respective attribute. Before it was possible that e.g. a uint was read and then interpreted as a const char*, if a string was expected for that attribute.
This commit is contained in:
@@ -110,7 +110,8 @@ protected:
|
|||||||
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
|
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename Header, uint32 kMagic, uint16 kVersion>
|
template<typename Header, uint32 kMagic, uint16 kVersion,
|
||||||
|
uint16 kMinorVersion>
|
||||||
status_t Init(int fd, bool keepFD, Header& header,
|
status_t Init(int fd, bool keepFD, Header& header,
|
||||||
uint32 flags);
|
uint32 flags);
|
||||||
status_t InitHeapReader(uint32 compression,
|
status_t InitHeapReader(uint32 compression,
|
||||||
@@ -182,6 +183,7 @@ private:
|
|||||||
int fFD;
|
int fFD;
|
||||||
bool fOwnsFD;
|
bool fOwnsFD;
|
||||||
uint16 fMinorFormatVersion;
|
uint16 fMinorFormatVersion;
|
||||||
|
uint16 fCurrentMinorFormatVersion;
|
||||||
|
|
||||||
PackageFileHeapReader* fRawHeapReader;
|
PackageFileHeapReader* fRawHeapReader;
|
||||||
BAbstractBufferedDataReader* fHeapReader;
|
BAbstractBufferedDataReader* fHeapReader;
|
||||||
@@ -378,7 +380,7 @@ private:
|
|||||||
// #pragma mark - template and inline methods
|
// #pragma mark - template and inline methods
|
||||||
|
|
||||||
|
|
||||||
template<typename Header, uint32 kMagic, uint16 kVersion>
|
template<typename Header, uint32 kMagic, uint16 kVersion, uint16 kMinorVersion>
|
||||||
status_t
|
status_t
|
||||||
ReaderImplBase::Init(int fd, bool keepFD, Header& header, uint32 flags)
|
ReaderImplBase::Init(int fd, bool keepFD, Header& header, uint32 flags)
|
||||||
{
|
{
|
||||||
@@ -418,6 +420,7 @@ ReaderImplBase::Init(int fd, bool keepFD, Header& header, uint32 flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fMinorFormatVersion = B_BENDIAN_TO_HOST_INT16(header.minor_version);
|
fMinorFormatVersion = B_BENDIAN_TO_HOST_INT16(header.minor_version);
|
||||||
|
fCurrentMinorFormatVersion = kMinorVersion;
|
||||||
|
|
||||||
// header size
|
// header size
|
||||||
uint64 heapOffset = B_BENDIAN_TO_HOST_INT16(header.header_size);
|
uint64 heapOffset = B_BENDIAN_TO_HOST_INT16(header.header_size);
|
||||||
|
|||||||
@@ -335,8 +335,8 @@ status_t
|
|||||||
PackageReaderImpl::Init(int fd, bool keepFD, uint32 flags)
|
PackageReaderImpl::Init(int fd, bool keepFD, uint32 flags)
|
||||||
{
|
{
|
||||||
hpkg_header header;
|
hpkg_header header;
|
||||||
status_t error = inherited::Init<hpkg_header, B_HPKG_MAGIC, B_HPKG_VERSION>(
|
status_t error = inherited::Init<hpkg_header, B_HPKG_MAGIC, B_HPKG_VERSION,
|
||||||
fd, keepFD, header, flags);
|
B_HPKG_MINOR_VERSION>(fd, keepFD, header, flags);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
fHeapSize = UncompressedHeapSize();
|
fHeapSize = UncompressedHeapSize();
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ namespace BPrivate {
|
|||||||
|
|
||||||
static const size_t kScratchBufferSize = 64 * 1024;
|
static const size_t kScratchBufferSize = 64 * 1024;
|
||||||
|
|
||||||
|
static const uint16 kAttributeTypes[B_HPKG_ATTRIBUTE_ID_ENUM_COUNT] = {
|
||||||
|
#define B_DEFINE_HPKG_ATTRIBUTE(id, type, name, constant) \
|
||||||
|
B_HPKG_ATTRIBUTE_TYPE_##type,
|
||||||
|
#include <package/hpkg/PackageAttributes.h>
|
||||||
|
#undef B_DEFINE_HPKG_ATTRIBUTE
|
||||||
|
};
|
||||||
|
|
||||||
// #pragma mark - AttributeHandlerContext
|
// #pragma mark - AttributeHandlerContext
|
||||||
|
|
||||||
@@ -1035,18 +1041,26 @@ ReaderImplBase::_ReadAttribute(uint8& _id, AttributeValue& _value,
|
|||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the ID
|
||||||
|
_id = attribute_tag_id(tag);
|
||||||
|
if (_id < B_HPKG_ATTRIBUTE_ID_ENUM_COUNT) {
|
||||||
|
if (type != kAttributeTypes[_id]) {
|
||||||
|
fErrorOutput->PrintError("Error: Invalid %s section: "
|
||||||
|
"unexpected type %d for attribute id %d (expected %d)!\n",
|
||||||
|
fCurrentSection->name, type, _id, kAttributeTypes[_id]);
|
||||||
|
return B_BAD_DATA;
|
||||||
|
}
|
||||||
|
} else if (fMinorFormatVersion <= fCurrentMinorFormatVersion) {
|
||||||
|
fErrorOutput->PrintError("Error: Invalid %s section: "
|
||||||
|
"attribute id %d not supported!\n", fCurrentSection->name, _id);
|
||||||
|
return B_BAD_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
// get the value
|
// get the value
|
||||||
error = ReadAttributeValue(type, attribute_tag_encoding(tag),
|
error = ReadAttributeValue(type, attribute_tag_encoding(tag),
|
||||||
_value);
|
_value);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
_id = attribute_tag_id(tag);
|
|
||||||
if (_id >= B_HPKG_ATTRIBUTE_ID_ENUM_COUNT) {
|
|
||||||
fErrorOutput->PrintError("Error: Invalid %s section: "
|
|
||||||
"attribute id %d not supported!\n", fCurrentSection->name, _id);
|
|
||||||
return B_BAD_DATA;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_hasChildren != NULL)
|
if (_hasChildren != NULL)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ RepositoryReaderImpl::Init(int fd, bool keepFD)
|
|||||||
{
|
{
|
||||||
hpkg_repo_header header;
|
hpkg_repo_header header;
|
||||||
status_t error = inherited::Init<hpkg_repo_header, B_HPKG_REPO_MAGIC,
|
status_t error = inherited::Init<hpkg_repo_header, B_HPKG_REPO_MAGIC,
|
||||||
B_HPKG_REPO_VERSION>(fd, keepFD, header, 0);
|
B_HPKG_REPO_VERSION, B_HPKG_REPO_MINOR_VERSION>(fd, keepFD, header, 0);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user