Ticket #10186: 0001-Devices-Fix-crash-for-devices-that-returned-unexpect.patch

File 0001-Devices-Fix-crash-for-devices-that-returned-unexpect.patch, 2.4 KB (added by PieterPanman, 11 years ago)

Patch that checks the array bounds and should fix the crash

  • src/apps/devices/Device.cpp

    From c4c413f5daea4b6b8ffcf4825e7e627500d19b73 Mon Sep 17 00:00:00 2001
    From: PieterPan <haiku@panman.eu>
    Date: Sat, 16 Nov 2013 23:17:44 +0000
    Subject: [PATCH] Devices: Fix crash for devices that returned unexpected
     categoryindex * Store the length of the category strings array * Check that
     before indexing the array * Improve comment * Should fix #10186
    
    ---
     src/apps/devices/Device.cpp      | 3 ++-
     src/apps/devices/Device.h        | 1 +
     src/apps/devices/DevicesView.cpp | 7 +++++++
     3 files changed, 10 insertions(+), 1 deletion(-)
    
    diff --git a/src/apps/devices/Device.cpp b/src/apps/devices/Device.cpp
    index d306bc8..bc92b7b 100644
    a b  
    1616#undef B_TRANSLATION_CONTEXT
    1717#define B_TRANSLATION_CONTEXT "Device"
    1818
    19 // This list comes from the pciid list, except for the last one
     19// This list comes from the pciid list, except for the last ones
    2020const char* kCategoryString[] = {
    2121    B_TRANSLATE("Unclassified device"),                 // 0x00
    2222    B_TRANSLATE("Mass storage controller"),             // 0x01
    const char* kCategoryString[] = {  
    3939    B_TRANSLATE("Computer"),                            // 0x12 (added later)
    4040    B_TRANSLATE("ACPI controller")                      // 0x13 (added later)
    4141};
     42const int kCategoryStringLength = sizeof(kCategoryString)/sizeof(char *);
    4243
    4344// This list is only used to translate Device properties
    4445B_TRANSLATE_MARK_VOID("unknown");
  • src/apps/devices/Device.h

    diff --git a/src/apps/devices/Device.h b/src/apps/devices/Device.h
    index caf36db..32b2e03 100644
    a b typedef enum {  
    6868
    6969
    7070extern const char* kCategoryString[];
     71extern const int kCategoryStringLength;
    7172
    7273
    7374class Device : public BStringItem {
  • src/apps/devices/DevicesView.cpp

    diff --git a/src/apps/devices/DevicesView.cpp b/src/apps/devices/DevicesView.cpp
    index c14111b..96db804 100644
    a b DevicesView::CreateCategoryMap()  
    146146    CategoryMapIterator iter;
    147147    for (unsigned int i = 0; i < fDevices.size(); i++) {
    148148        Category category = fDevices[i]->GetCategory();
     149        if (category < 0 || category >= kCategoryStringLength) {
     150            std::cerr << "CreateCategoryMap: device " << fDevices[i]->GetName()
     151                << " returned category index " << category << ", which is not known. "
     152                << "Skipping device." << std::endl;
     153            continue;
     154        }           
     155
    149156        const char* categoryName = kCategoryString[category];
    150157
    151158        iter = fCategoryMap.find(category);