Date: Sun, 23 Oct 2011 16:47:38 GMT From: Ryan Steinmetz <zi@FreeBSD.org> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/161936: [openbsm][patch] praudit can produce invalid XML output Message-ID: <201110231647.p9NGlcm9029317@red.freebsd.org> Resent-Message-ID: <201110231650.p9NGo3lG017129@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 161936
>Category: bin
>Synopsis: [openbsm][patch] praudit can produce invalid XML output
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sun Oct 23 16:50:03 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: Ryan Steinmetz
>Release: 8.2-RELEASE
>Organization:
Rochester Institute of Technology
>Environment:
>Description:
When using praudit to display audit entries, the XML output argument (-x) will cause praudit to print invalid XML in certain circumstances.
This surfaces anytime a command is audited that contains invalid XML characters (& or <).
>How-To-Repeat:
Ensure command logging is enabled and execute a command like the following:
% echo hi < test && ls
% praudit -x >file.tmp
Then use an XML parser to try to parse file.tmp, it will complain about invalid characters due to the presence of & and < in places they should not be.
>Fix:
Applying the attached patch to contrib/openbsm/libbsm/bsm_io.c properly sanitizes the entries as they are printed by replacing instances of & with & and < with <
cd /usr/src
patch < /path/to/bsm_io.c.diff
cd lib/libbsm && make clean;make obj && make depend && make && make install
Patch attached with submission follows:
--- contrib/openbsm/libbsm/bsm_io.c.orig 2011-10-23 12:10:40.000000000 -0400
+++ contrib/openbsm/libbsm/bsm_io.c 2011-10-23 12:35:31.000000000 -0400
@@ -214,6 +214,28 @@
}
/*
+ * Prints the given data bytes as an XML-sanitized string
+ */
+static void
+print_xml_string(FILE *fp, const char *str, size_t len)
+{
+ u_int32_t i;
+
+ if (len > 0) {
+ for (i = 0; i < len; i++) {
+ if (str[i] != '\0') {
+ if (str[i] == '&')
+ fprintf(fp, "&");
+ else if (str[i] == '<')
+ fprintf(fp, "<");
+ else
+ fprintf(fp, "%c", str[i]);
+ }
+ }
+ }
+}
+
+/*
* Prints the beggining of attribute.
*/
static void
@@ -1855,7 +1877,7 @@
for (i = 0; i < tok->tt.execarg.count; i++) {
if (xml) {
fprintf(fp, "<arg>");
- print_string(fp, tok->tt.execarg.text[i],
+ print_xml_string(fp, tok->tt.execarg.text[i],
strlen(tok->tt.execarg.text[i]));
fprintf(fp, "</arg>");
} else {
@@ -1914,7 +1936,7 @@
for (i = 0; i< tok->tt.execenv.count; i++) {
if (xml) {
fprintf(fp, "<env>");
- print_string(fp, tok->tt.execenv.text[i],
+ print_xml_string(fp, tok->tt.execenv.text[i],
strlen(tok->tt.execenv.text[i]));
fprintf(fp, "</env>");
} else {
>Release-Note:
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110231647.p9NGlcm9029317>
