* NodeInfo::GetType() now returns B_BAD_DATA instead of B_BAD_VALUE if the
attribute is longer than B_MIME_TYPE_LENGTH. * NodeInfo::GetType() now null terminates the attribute; you cannot expect that strings in attributes are null terminated (it already wrote the null byte to B_MIME_TYPE_LENGTH - 1 for safety, but why not do it right?). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15740 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
38030e0477
commit
762eb2233b
@ -145,7 +145,8 @@ BNodeInfo::GetType(char *type) const
|
||||
if (error == B_OK && attrInfo.type != B_MIME_STRING_TYPE)
|
||||
error = B_BAD_TYPE;
|
||||
if (error == B_OK && attrInfo.size > B_MIME_TYPE_LENGTH)
|
||||
error = B_BAD_VALUE; // TODO: B_BAD_DATA?
|
||||
error = B_BAD_DATA;
|
||||
|
||||
// read the data
|
||||
if (error == B_OK) {
|
||||
ssize_t read = fNode->ReadAttr(kNITypeAttribute, attrInfo.type, 0,
|
||||
@ -154,9 +155,11 @@ BNodeInfo::GetType(char *type) const
|
||||
error = read;
|
||||
else if (read != attrInfo.size)
|
||||
error = B_ERROR;
|
||||
// to be save, null terminate the string at the very end
|
||||
if (error == B_OK)
|
||||
type[B_MIME_TYPE_LENGTH - 1] = '\0';
|
||||
|
||||
if (error == B_OK) {
|
||||
// attribute strings doesn't have to be null terminated
|
||||
type[min_c(attrInfo.size, B_MIME_TYPE_LENGTH - 1)] = '\0';
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user