dmidecode-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dmidecode] [PATCH] dmioem: Move function is_printable to dmidecode.c


From: Jean Delvare
Subject: [dmidecode] [PATCH] dmioem: Move function is_printable to dmidecode.c
Date: Wed, 13 May 2015 14:37:33 +0200

Move function is_printable to dmidecode.c so that a single implementation
can be used in both dmidecode.c and dmioem.c.
---
 dmidecode.c |   28 ++++++++++++++++++----------
 dmidecode.h |    1 +
 dmioem.c    |   11 -----------
 3 files changed, 19 insertions(+), 21 deletions(-)

--- dmidecode.orig/dmidecode.c  2015-05-13 10:25:35.620144793 +0200
+++ dmidecode/dmidecode.c       2015-05-13 11:02:47.170794198 +0200
@@ -81,6 +81,18 @@ static const char *bad_index = "<BAD IND
  * 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_addre
 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)
--- dmidecode.orig/dmioem.c     2015-05-13 10:38:00.257085027 +0200
+++ dmidecode/dmioem.c  2015-05-13 11:03:03.574144699 +0200
@@ -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.
  *
--- dmidecode.orig/dmidecode.h  2015-04-28 13:01:07.939765776 +0200
+++ dmidecode/dmidecode.h       2015-05-13 11:02:30.625440678 +0200
@@ -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);


-- 
Jean Delvare
SUSE L3 Support



reply via email to

[Prev in Thread] Current Thread [Next in Thread]