Skip to content

Commit 162fc8a

Browse files
committed
Fix SMBIOS version validation
1 parent 75c24b7 commit 162fc8a

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ The pointer to the current SMBIOS entry is stored in the variable specified as t
7676
|TYPE_MANAGEMENT_DEVICE_THRESHOLD_DATA | management_device_threshold_data |
7777
|TYPE_ONBOARD_DEVICES_EXTENDED_INFO | onboard_devices_extended_info |
7878
79-
The library do not make heap allocations: everything is done in-place using the provided SMBIOS buffer and the context.
79+
The library do not make heap allocations; everything is done in-place using the provided SMBIOS buffer and the context.
8080
8181
## API
8282
83-
The following functions are available. If you're using the library in a C++ code, the functions will be defined in the `smbios` namespace.
83+
The following functions are available.
8484
8585
### smbios_initialize
8686
@@ -93,7 +93,7 @@ If the actual version of the SMBIOS data is smaller than the value of the parame
9393
* **context**: Parser context.
9494
* **data**: SMBIOS data.
9595
* **size**: Size of the SMBIOS data.
96-
* **version**: Preferred SMBIOS version.
96+
* **version**: Preferred SMBIOS version. If set with `SMBIOS_ANY`, the latest version will be used (currently 3.0).
9797
9898
The function returns SMBERR_OK on success or a negative error code.
9999

smbios.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int smbios_initialize(struct ParserContext *context, const uint8_t *data, size_t
5050

5151
memset(context, 0, sizeof(struct ParserContext));
5252
context->ptr = NULL;
53-
context->sversion = VALID_VERSION(version) ? SMBIOS_3_0 : version;
53+
context->sversion = VALID_VERSION(version) ? version : SMBIOS_3_0;
5454

5555
// we have a valid SMBIOS entry point?
5656
#ifndef _WIN32
@@ -102,10 +102,12 @@ int smbios_initialize(struct ParserContext *context, const uint8_t *data, size_t
102102
context->size = smBiosData->Length;
103103
#endif
104104

105-
if (!VALID_VERSION(context->oversion))
106-
return SMBERR_INVALID_DATA;
107105
if (context->sversion > context->oversion)
106+
{
107+
if (!VALID_VERSION(context->oversion))
108+
return SMBERR_INVALID_DATA;
108109
context->sversion = context->oversion;
110+
}
109111

110112
return SMBERR_OK;
111113
}

smbios.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ struct Entry
382382

383383
enum SpecVersion
384384
{
385+
SMBIOS_ANY = 0,
385386
SMBIOS_2_0 = 0x0200,
386387
SMBIOS_2_1 = 0x0201,
387388
SMBIOS_2_2 = 0x0202,

smbios_decode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ bool printSMBIOS( struct ParserContext *parser, FILE *output )
101101
if (smbios_get_version(parser, &version, NULL) != SMBERR_OK)
102102
return false;
103103

104+
fprintf(output, "SMBIOS version %d.%d\n", version >> 8, version & 0xFF);
105+
104106
const struct Entry *entry = NULL;
105107
while (true)
106108
{
@@ -480,7 +482,7 @@ int main(int argc, char ** argv)
480482
}
481483

482484
struct ParserContext parser;
483-
if (smbios_initialize(&parser, buffer, size, SMBIOS_3_0) == SMBERR_OK)
485+
if (smbios_initialize(&parser, buffer, size, SMBIOS_ANY) == SMBERR_OK)
484486
printSMBIOS(&parser, stdout);
485487
else
486488
fputs("Invalid SMBIOS data", stderr);

0 commit comments

Comments
 (0)