Fixed nasty bug in BAppFileInfo::_ReadData(). When an attribute

or resource to be read did not exist and the method was told to
allocate a buffer, it would try to allocate the buffer with an
uninitialized size value. This basically concerned SetSupportedTypes()
and methods using that one (IsSupportedType(), Supports()).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16131 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2006-01-28 22:34:36 +00:00
parent 7aa7880955
commit b4598d95e6
2 changed files with 16 additions and 4 deletions

View File

@ -1063,7 +1063,7 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
// check type and size, allocate a buffer, if required // check type and size, allocate a buffer, if required
if (error == B_OK && info.type != type) if (error == B_OK && info.type != type)
error = B_BAD_VALUE; error = B_BAD_VALUE;
if (allocatedBuffer) { if (error == B_OK && allocatedBuffer) {
buffer = malloc(info.size); buffer = malloc(info.size);
if (!buffer) if (!buffer)
error = B_NO_MEMORY; error = B_NO_MEMORY;
@ -1084,6 +1084,12 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
} }
foundData = (error == B_OK); foundData = (error == B_OK);
// free the allocated buffer on error
if (!foundData && allocatedBuffer && buffer) {
free(buffer);
buffer = NULL;
}
} }
if (!foundData && IsUsingResources()) { if (!foundData && IsUsingResources()) {
@ -1099,7 +1105,7 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
// check id and size, allocate a buffer, if required // check id and size, allocate a buffer, if required
if (error == B_OK && id >= 0 && idFound != id) if (error == B_OK && id >= 0 && idFound != id)
error = B_ENTRY_NOT_FOUND; error = B_ENTRY_NOT_FOUND;
if (allocatedBuffer) { if (error == B_OK && allocatedBuffer) {
buffer = malloc(sizeFound); buffer = malloc(sizeFound);
if (!buffer) if (!buffer)
error = B_NO_MEMORY; error = B_NO_MEMORY;

View File

@ -1063,7 +1063,7 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
// check type and size, allocate a buffer, if required // check type and size, allocate a buffer, if required
if (error == B_OK && info.type != type) if (error == B_OK && info.type != type)
error = B_BAD_VALUE; error = B_BAD_VALUE;
if (allocatedBuffer) { if (error == B_OK && allocatedBuffer) {
buffer = malloc(info.size); buffer = malloc(info.size);
if (!buffer) if (!buffer)
error = B_NO_MEMORY; error = B_NO_MEMORY;
@ -1084,6 +1084,12 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
} }
foundData = (error == B_OK); foundData = (error == B_OK);
// free the allocated buffer on error
if (!foundData && allocatedBuffer && buffer) {
free(buffer);
buffer = NULL;
}
} }
if (!foundData && IsUsingResources()) { if (!foundData && IsUsingResources()) {
@ -1099,7 +1105,7 @@ BAppFileInfo::_ReadData(const char *name, int32 id, type_code type,
// check id and size, allocate a buffer, if required // check id and size, allocate a buffer, if required
if (error == B_OK && id >= 0 && idFound != id) if (error == B_OK && id >= 0 && idFound != id)
error = B_ENTRY_NOT_FOUND; error = B_ENTRY_NOT_FOUND;
if (allocatedBuffer) { if (error == B_OK && allocatedBuffer) {
buffer = malloc(sizeFound); buffer = malloc(sizeFound);
if (!buffer) if (!buffer)
error = B_NO_MEMORY; error = B_NO_MEMORY;