From 762eb2233b69cafb4a2ca943ff0b9c5748dc351e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 30 Dec 2005 13:53:34 +0000 Subject: [PATCH] * 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 --- src/kits/storage/NodeInfo.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/kits/storage/NodeInfo.cpp b/src/kits/storage/NodeInfo.cpp index 4de38c84de..c5dcb1699f 100644 --- a/src/kits/storage/NodeInfo.cpp +++ b/src/kits/storage/NodeInfo.cpp @@ -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; }