summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkhali <khali>2015-05-21 19:14:57 +0000
committerkhali <khali>2015-05-21 19:14:57 +0000
commit866a482faa9688bc37da818a641d71c7d6a880d3 (patch)
treebacc7361411ce2d535e51c31ce27d21f4d17292a
parent4df0a85e758390a6cc54df5aa45fe1659c2a9a0b (diff)
downloaddmidecode-866a482faa9688bc37da818a641d71c7d6a880d3.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.
-rw-r--r--CHANGELOG1
-rw-r--r--dmidecode.c28
-rw-r--r--dmidecode.h1
-rw-r--r--dmioem.c11
4 files changed, 20 insertions, 21 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f161d4c..5234fad 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@
* dmidecode.c: Fix up invalid DMI type 34 structure length.
* dmioem.c: Decode HP-specific DMI types 212 and 219.
+ * dmioem.c: Move function is_printable to dmidecode.c.
2015-05-13 Jean Delvare <jdelvare@suse.de>
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)
diff --git a/dmidecode.h b/dmidecode.h
index 0e5a782..20e7e96 100644
--- a/dmidecode.h
+++ b/dmidecode.h
@@ -28,4 +28,5 @@ struct dmi_header
u8 *data;
};
+int is_printable(const u8 *data, int len);
const char *dmi_string(const struct dmi_header *dm, u8 s);
diff --git a/dmioem.c b/dmioem.c
index ae1370a..fb43c79 100644
--- a/dmioem.c
+++ b/dmioem.c
@@ -62,17 +62,6 @@ void dmi_set_vendor(const char *s)
dmi_vendor = VENDOR_ACER;
}
-static 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;
-}
-
/*
* HP-specific data structures are decoded here.
*