Devices: Check out of bound array access on category strings.

* Computes the length of the category strings array.
* Checks against this length before accessing the array
* Improves comment
* Should fix #10186

Signed-off-by: Jérôme Duval <[email protected]>
This commit is contained in:
PieterPan
2013-11-17 17:59:07 +01:00
committed by Jérôme Duval
parent f584c0ca5f
commit bca4535239
3 changed files with 10 additions and 1 deletions
+2 -1
View File
@@ -16,7 +16,7 @@
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Device"
// This list comes from the pciid list, except for the last one
// This list comes from the pciid list, except for the last ones
const char* kCategoryString[] = {
B_TRANSLATE("Unclassified device"), // 0x00
B_TRANSLATE("Mass storage controller"), // 0x01
@@ -39,6 +39,7 @@ const char* kCategoryString[] = {
B_TRANSLATE("Computer"), // 0x12 (added later)
B_TRANSLATE("ACPI controller") // 0x13 (added later)
};
const int kCategoryStringLength = sizeof(kCategoryString)/sizeof(char *);
// This list is only used to translate Device properties
B_TRANSLATE_MARK_VOID("unknown");
+1
View File
@@ -68,6 +68,7 @@ typedef enum {
extern const char* kCategoryString[];
extern const int kCategoryStringLength;
class Device : public BStringItem {
+7
View File
@@ -146,6 +146,13 @@ DevicesView::CreateCategoryMap()
CategoryMapIterator iter;
for (unsigned int i = 0; i < fDevices.size(); i++) {
Category category = fDevices[i]->GetCategory();
if (category < 0 || category >= kCategoryStringLength) {
std::cerr << "CreateCategoryMap: device " << fDevices[i]->GetName()
<< " returned an unknown category index (" << category << "). "
<< "Skipping device." << std::endl;
continue;
}
const char* categoryName = kCategoryString[category];
iter = fCategoryMap.find(category);