diff options
author | David Sommerseth <davids@redhat.com> | 2009-06-11 10:50:31 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2009-06-11 10:50:31 +0200 |
commit | 9864a51dafd953c497210b6f11e49bb299080dc8 (patch) | |
tree | 06b7515718f13eb1c30c8d3e5db9c3b042265b94 /src | |
parent | b3f5e9f97e283f2f23f36251b971458f805c6893 (diff) | |
download | python-dmidecode-9864a51dafd953c497210b6f11e49bb299080dc8.tar.gz python-dmidecode-9864a51dafd953c497210b6f11e49bb299080dc8.tar.xz python-dmidecode-9864a51dafd953c497210b6f11e49bb299080dc8.zip |
Fixed crashes and unexpected behaviour on unknown DMI/SMBIOS types
Also provide more useful information, both on unsupported types and
types not found on the hardware
Diffstat (limited to 'src')
-rw-r--r-- | src/dmidecode.c | 65 | ||||
-rw-r--r-- | src/dmidecode.h | 2 | ||||
-rw-r--r-- | src/dmidecodemodule.h | 1 |
3 files changed, 48 insertions, 20 deletions
diff --git a/src/dmidecode.c b/src/dmidecode.c index f819adf..63b8040 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -3688,15 +3688,13 @@ void dmi_additional_info(xmlNode *node, const struct dmi_header *h) ** Main */ -xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver) +xmlNode *dmi_decode(xmlNode *prnt_n, dmi_codes_major *dmiMajor, struct dmi_header * h, u16 ver) { const u8 *data = h->data; xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL; //. 0xF1 --> 0xF100 //int minor = h->type<<8; - dmi_codes_major *dmiMajor = (dmi_codes_major *) &dmiCodesMajor[h->type]; - sect_n = xmlNewChild(prnt_n, NULL, (xmlChar *) dmiMajor->tagname, NULL); assert( sect_n != NULL ); @@ -4942,20 +4940,33 @@ int dump(const char *dumpfile) if(ret == 0) { free(buf); - - //. TODO: Exception - if(!found) + if(!found) { ret = -1; + } } return ret == 0 ? found : ret; } + +dmi_codes_major *find_dmiMajor(const struct dmi_header *h) +{ + int i = 0; + + for( i = 0; dmiCodesMajor[i].id != NULL; i++ ) { + if( h->type == dmiCodesMajor[i].code ) { + return (dmi_codes_major *)&dmiCodesMajor[i]; + } + } + return NULL; +} + static void dmi_table(int type, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode) { u8 *buf; u8 *data; int i = 0; + int decoding_done = 0; if( type == -1 ) { xmlNode *info_n = NULL; @@ -5021,29 +5032,47 @@ static void dmi_table(int type, u32 base, u16 len, u16 num, u16 ver, const char xmlNode *handle_n = NULL; if( h.type == type ) { if(next - buf <= len) { + dmi_codes_major *dmiMajor = NULL; /* TODO: ... * if(opt->flags & FLAG_DUMP) { * PyDict_SetItem(hDict, PyString_FromString("lookup"), dmi_dump(&h)); - * } else { - * //. TODO: //. Is the value of `i' important?... - * //. TODO: PyDict_SetItem(hDict, PyInt_FromLong(i), dmi_decode(&h, ver)); - * //. TODO: ...removed and replaced with `data'... - * PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver)); - * PyDict_SetItem(pydata, PyString_FromString(hid), hDict); * } */ - handle_n = dmi_decode(xmlnode, &h, ver); - } else - fprintf(stderr, "<TRUNCATED>"); - } - if( handle_n != NULL ) { + + dmiMajor = find_dmiMajor(&h); + if( dmiMajor != NULL ) { + handle_n = dmi_decode(xmlnode, dmiMajor, &h, ver); + } else { + handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMImessage", NULL); + assert( handle_n != NULL ); + dmixml_AddTextContent(handle_n, "DMI/SMBIOS type 0x%02X is not supported " + "by dmidecode", h.type); + dmixml_AddAttribute(handle_n, "type", "%i", h.type); + dmixml_AddAttribute(handle_n, "unsupported", "1"); + } + } else { + handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMIerror", NULL); + assert( handle_n != NULL ); + dmixml_AddTextContent(handle_n, "Data is truncated"); + dmixml_AddAttribute(handle_n, "type", "%i", h.type); + dmixml_AddAttribute(handle_n, "truncated", "1"); + } dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle); dmixml_AddAttribute(handle_n, "size", "%d", h.length); + decoding_done = 1; } - data = next; i++; } + if( decoding_done == 0 ) { + xmlNode *handle_n = xmlNewChild(xmlnode, NULL, (xmlChar *) "DMImessage", NULL); + assert( handle_n != NULL ); + dmixml_AddTextContent(handle_n, "DMI/SMBIOS type 0x%02X is not found on this hardware", + type); + dmixml_AddAttribute(handle_n, "type", "%i", type); + dmixml_AddAttribute(handle_n, "notfound", "1"); + } + if(i != num) fprintf(stderr, "Wrong DMI structures count: %d announced, only %d decoded.\n", num, i); diff --git a/src/dmidecode.h b/src/dmidecode.h index f0cb1ab..81cd249 100644 --- a/src/dmidecode.h +++ b/src/dmidecode.h @@ -30,7 +30,7 @@ struct dmi_header { }; void dmi_dump(xmlNode *node, struct dmi_header * h); -xmlNode *dmi_decode(xmlNode *parent_n, struct dmi_header * h, u16 ver); +xmlNode *dmi_decode(xmlNode *parent_n, dmi_codes_major *dmiMajor, struct dmi_header * h, u16 ver); int address_from_efi(size_t * address); void to_dmi_header(struct dmi_header *h, u8 * data); diff --git a/src/dmidecodemodule.h b/src/dmidecodemodule.h index 9699e82..378ad2a 100644 --- a/src/dmidecodemodule.h +++ b/src/dmidecodemodule.h @@ -25,7 +25,6 @@ xmlNode *dmidecode_get_version(options *); extern void dmi_dump(xmlNode *node, struct dmi_header *h); -extern xmlNode *dmi_decode(xmlNode *parent_n, struct dmi_header * h, u16 ver); extern int address_from_efi(size_t * address); extern void to_dmi_header(struct dmi_header *h, u8 * data); extern int smbios_decode(int type, u8 *buf, const char *devmem, xmlNode *node); |