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:
@@ -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");
|
||||
|
||||
@@ -68,6 +68,7 @@ typedef enum {
|
||||
|
||||
|
||||
extern const char* kCategoryString[];
|
||||
extern const int kCategoryStringLength;
|
||||
|
||||
|
||||
class Device : public BStringItem {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user