Changeset c9118b9eb373ccfacaee9866e3344fce14eee5af

Show
Ignore:
Timestamp:
11/01/09 11:04:19 (2 years ago)
Author:
Erwan Velu <erwan.velu@…>
Children:
57689f219c5155e186ced1c9f5f972d5d0b340ed
Parents:
2ce2b5480bd81d34e80be6dc246303eb710313f4
git-author:
Pierre-Alexandre Meyer <pierre@mouraf.org> / 2009-10-31T19:45:30Z-0700
git-committer:
Erwan Velu <erwan.velu@free.fr> / 2009-11-01T12:04:19Z+0100
Message:

dmi: enhance SMBIOS/DMI detection

Add missing sanity checks when parsing the SMBIOS table entry point.

Signed-off-by: Pierre-Alexandre Meyer <pierre@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • com32/gpllib/dmi/dmi.c

    r01d211f rc9118b  
    445445} 
    446446 
    447 int dmi_checksum(uint8_t * buf, int len) 
     447int checksum(uint8_t * buf, int len) 
    448448{ 
    449449    uint8_t sum = 0; 
     
    482482        buf[11] << 24 | buf[10] << 16 | buf[9] << 8 | buf[8]; 
    483483 
     484    /* Version already found? */ 
    484485    if (dmi->dmitable.ver>0) return DMI_TABLE_PRESENT; 
    485486 
     
    491492     */ 
    492493    if (buf[14] != 0) { 
    493         dmi->dmitable.major_version = buf[14] >> 4; 
    494         dmi->dmitable.minor_version = buf[14] & 0x0F; 
     494        dmi->dmitable.major_version = buf[14] >> 4; 
     495        dmi->dmitable.minor_version = buf[14] & 0x0F; 
    495496    } else { 
    496         dmi->dmitable.major_version = 0; 
    497         dmi->dmitable.minor_version = 0; 
     497        dmi->dmitable.major_version = 0; 
     498        dmi->dmitable.minor_version = 0; 
    498499    } 
    499500    return DMI_TABLE_PRESENT; 
     
    503504int dmi_iterate(s_dmi * dmi) 
    504505{ 
    505     uint8_t buf[DMI_BUFFER_SIZE]; 
    506     char *p, *q; 
     506    uint8_t *p, *q; 
     507    int found = 0; 
    507508 
    508509    /* Cleaning structures */ 
     
    526527    dmi->system.filled = false; 
    527528 
    528     p = (char *)0xF0000;        /* The start address to look at the dmi table */ 
     529    p = (uint8_t *)0xF0000;     /* The start address to look at the dmi table */ 
     530    /* The anchor-string is 16-bytes aligned */ 
    529531    for (q = p; q < p + 0x10000; q += 16) { 
    530         memcpy(buf, q, 15); 
    531         if (memcmp(buf, "_SM_", 4) == 0) { 
    532                 smbios_decode(dmi,buf); 
    533         } 
    534         if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf,sizeof(buf))) { 
    535                 return legacy_decode(dmi,buf); 
    536         } 
    537     } 
     532        /* To validate the presence of SMBIOS: 
     533         * + the overall checksum must be correct 
     534         * + the intermediate anchor-string must be _DMI_ 
     535         * + the intermediate checksum must be correct 
     536         */ 
     537        if (memcmp(q, "_SM_", 4) == 0 && 
     538            checksum(q, q[0x05]) && 
     539            memcmp(q + 0x10, "_DMI_", 5)==0 && 
     540            checksum(q + 0x10, 0x0F)) { 
     541            /* Do not return, legacy_decode will need to be called 
     542             * on the intermediate structure to get the table length 
     543             * and address 
     544             */ 
     545            smbios_decode(dmi, q); 
     546        } else if (memcmp(q, "_DMI_", 5) == 0 && checksum(q, 0x0F)) { 
     547            found = 1; 
     548            legacy_decode(dmi, q); 
     549        } 
     550    } 
     551 
     552    if (found) 
     553        return DMI_TABLE_PRESENT; 
     554 
    538555    dmi->dmitable.base = 0; 
    539556    dmi->dmitable.num = 0;