Skip to content

Commit d7749b2

Browse files
committed
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.
1 parent 3b45f46 commit d7749b2

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

Diff for: CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* dmidecode.c: Fix up invalid DMI type 34 structure length.
44
* dmioem.c: Decode HP-specific DMI types 212 and 219.
5+
* dmioem.c: Move function is_printable to dmidecode.c.
56

67
2015-05-13 Jean Delvare <[email protected]>
78

Diff for: dmidecode.c

+18-10
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ static const char *bad_index = "<BAD INDEX>";
8181
* Type-independant Stuff
8282
*/
8383

84+
/* Returns 1 if the buffer contains only printable ASCII characters */
85+
int is_printable(const u8 *data, int len)
86+
{
87+
int i;
88+
89+
for (i = 0; i < len; i++)
90+
if (data[i] < 32 || data[i] >= 127)
91+
return 0;
92+
93+
return 1;
94+
}
95+
8496
const char *dmi_string(const struct dmi_header *dm, u8 s)
8597
{
8698
char *bp = (char *)dm->data;
@@ -2937,18 +2949,14 @@ static void dmi_64bit_memory_error_address(u64 code)
29372949
static void dmi_fixup_type_34(struct dmi_header *h)
29382950
{
29392951
u8 *p = h->data;
2940-
int i;
2941-
2942-
if (h->length != 0x10)
2943-
return;
29442952

29452953
/* Make sure the hidden data is ASCII only */
2946-
for (i = 0x0B; i < 0x10; i++)
2947-
if (p[i] < 32 || p[i] >= 127)
2948-
return;
2949-
2950-
printf("Invalid entry length (%u). Fixed up to %u.\n", 0x10, 0x0B);
2951-
h->length = 0x0B;
2954+
if (h->length == 0x10
2955+
&& is_printable(p + 0x0B, 0x10 - 0x0B))
2956+
{
2957+
printf("Invalid entry length (%u). Fixed up to %u.\n", 0x10, 0x0B);
2958+
h->length = 0x0B;
2959+
}
29522960
}
29532961

29542962
static const char *dmi_management_device_type(u8 code)

Diff for: dmidecode.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ struct dmi_header
2828
u8 *data;
2929
};
3030

31+
int is_printable(const u8 *data, int len);
3132
const char *dmi_string(const struct dmi_header *dm, u8 s);

Diff for: dmioem.c

-11
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ void dmi_set_vendor(const char *s)
6262
dmi_vendor = VENDOR_ACER;
6363
}
6464

65-
static int is_printable(const u8 *data, int len)
66-
{
67-
int i;
68-
69-
for (i = 0; i < len; i++)
70-
if (data[i] < 32 || data[i] >= 127)
71-
return 0;
72-
73-
return 1;
74-
}
75-
7665
/*
7766
* HP-specific data structures are decoded here.
7867
*

0 commit comments

Comments
 (0)