summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2011-04-26 15:24:17 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2011-04-26 15:24:17 -0700
commit53f0aee26b574bfb127a09950a34159fa68f49fe (patch)
treeb83eb8523b1ce198d7a185edded1db35fa9295e0 /core
parent99e8e9b8043bc723486f5da22ceb640e2a340457 (diff)
downloadsyslinux-53f0aee26b574bfb127a09950a34159fa68f49fe.tar.gz
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@linux.intel.com>
Diffstat (limited to 'core')
-rw-r--r--core/dmi.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/core/dmi.c b/core/dmi.c
index 674d27c3..9c9e0ab2 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);
}
}