* Fix a bug where a string longer than INT_MAX can cause IsValid() to falsely

report a valid mimetype because strlen() returns a result than when stored
  in an int is treated as a negative number.

* Style fixes in the same method
This commit is contained in:
John Scipione
2012-03-14 18:56:54 -04:00
parent 08de244f9c
commit 395167071d
+8 -8
View File
@@ -1152,25 +1152,25 @@ BMimeType::GetWildcardApps(BMessage *wild_ones)
bool bool
BMimeType::IsValid(const char *string) BMimeType::IsValid(const char *string)
{ {
if (!string) if (string == NULL)
return false; return false;
bool foundSlash = false; bool foundSlash = false;
int len = strlen(string); size_t len = strlen(string);
if (len >= B_MIME_TYPE_LENGTH || len == 0) if (len >= B_MIME_TYPE_LENGTH || len == 0)
return false; return false;
for (int i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
char ch = string[i]; char ch = string[i];
if (ch == '/') { if (ch == '/') {
if (foundSlash || i == 0 || i == len-1) if (foundSlash || i == 0 || i == len - 1)
return false; return false;
else else
foundSlash = true; foundSlash = true;
} else if (!isValidMimeChar(ch)) { } else if (!isValidMimeChar(ch)) {
return false; return false;
} }
} }
return true; return true;
} }