diff options
| author | Jean Delvare <jdelvare@suse.de> | 2015-05-21 19:14:57 +0000 |
|---|---|---|
| committer | Jean Delvare <jdelvare@suse.de> | 2015-05-21 19:14:57 +0000 |
| commit | d7749b2dc6f2350b52685fc96b37e4565a0a7a2e (patch) | |
| tree | bacc7361411ce2d535e51c31ce27d21f4d17292a /dmidecode.c | |
| parent | 3b45f460e1b446fd4e75b0ce2d0839c57f97f171 (diff) | |
| download | dmidecode-git-d7749b2dc6f2350b52685fc96b37e4565a0a7a2e.tar.gz | |
dmioem: Move function is_printable to dmidecode.c
Move function is_printable to dmidecode.c so that a single implementation
can be used in both dmidecode.c and dmioem.c.
Diffstat (limited to 'dmidecode.c')
| -rw-r--r-- | dmidecode.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/dmidecode.c b/dmidecode.c index 621f882..419f661 100644 --- a/dmidecode.c +++ b/dmidecode.c @@ -81,6 +81,18 @@ static const char *bad_index = "<BAD INDEX>"; * Type-independant Stuff */ +/* Returns 1 if the buffer contains only printable ASCII characters */ +int is_printable(const u8 *data, int len) +{ + int i; + + for (i = 0; i < len; i++) + if (data[i] < 32 || data[i] >= 127) + return 0; + + return 1; +} + const char *dmi_string(const struct dmi_header *dm, u8 s) { char *bp = (char *)dm->data; @@ -2937,18 +2949,14 @@ static void dmi_64bit_memory_error_address(u64 code) static void dmi_fixup_type_34(struct dmi_header *h) { u8 *p = h->data; - int i; - - if (h->length != 0x10) - return; /* Make sure the hidden data is ASCII only */ - for (i = 0x0B; i < 0x10; i++) - if (p[i] < 32 || p[i] >= 127) - return; - - printf("Invalid entry length (%u). Fixed up to %u.\n", 0x10, 0x0B); - h->length = 0x0B; + if (h->length == 0x10 + && is_printable(p + 0x0B, 0x10 - 0x0B)) + { + printf("Invalid entry length (%u). Fixed up to %u.\n", 0x10, 0x0B); + h->length = 0x0B; + } } static const char *dmi_management_device_type(u8 code) |
