[syslinux:lwip] dmi: strip whitespace from DMI strings
syslinux-bot for H. Peter Anvin
hpa at linux.intel.com
Tue Apr 26 15:30:02 PDT 2011
Commit-ID: 53f0aee26b574bfb127a09950a34159fa68f49fe
Gitweb: http://syslinux.zytor.com/commit/53f0aee26b574bfb127a09950a34159fa68f49fe
Author: H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Tue, 26 Apr 2011 15:24:17 -0700
Committer: H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Tue, 26 Apr 2011 15:24:17 -0700
dmi: strip whitespace from DMI strings
Some BIOS vendors seem to have large spaces in DMI strings, presumably
for easy patching. Therefore, clean up the strings before we use
them.
Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>
---
core/dmi.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/core/dmi.c b/core/dmi.c
index 674d27c..9c9e0ab 100644
--- a/core/dmi.c
+++ b/core/dmi.c
@@ -232,6 +232,50 @@ static const struct sysappend_dmi_strings dmi_strings[] = {
{ NULL, 0, 0, 0 }
};
+/*
+ * Install the string in the string table, if nonempty, after
+ * removing leading and trailing whitespace.
+ */
+static bool is_ctl_or_whitespace(char c)
+{
+ return (c <= ' ' || c == '\x7f');
+}
+
+static const char *dmi_install_string(const char *pfx, const char *str)
+{
+ const char *p, *ep;
+ size_t pfxlen;
+ char *nstr, *q;
+
+ if (!str)
+ return NULL;
+
+ while (*str && is_ctl_or_whitespace(*str))
+ str++;
+
+ if (!*str)
+ return NULL;
+
+ ep = p = str;
+ while (*p) {
+ if (!is_ctl_or_whitespace(*p))
+ ep = str+1;
+ p++;
+ }
+
+ pfxlen = strlen(pfx);
+ q = nstr = malloc(pfxlen + (ep-p) + 1);
+ if (!nstr)
+ return NULL;
+ memcpy(q, pfx, pfxlen);
+ q += pfxlen;
+ memcpy(q, str, ep-p);
+ q += (ep-p);
+ *q = '\0';
+
+ return nstr;
+}
+
void dmi_init(void)
{
const struct sysappend_dmi_strings *ds;
@@ -249,8 +293,6 @@ void dmi_init(void)
free((char *)sysappend_strings[ds->sa]);
sysappend_strings[ds->sa] = NULL;
}
- if (str)
- asprintf((char **)&sysappend_strings[ds->sa],
- "%s%s", ds->prefix, str);
+ sysappend_strings[ds->sa] = dmi_install_string(ds->prefix, str);
}
}
More information about the Syslinux-commits
mailing list