From owner-freebsd-bugs@FreeBSD.ORG Sun Oct 23 16:50:04 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 048211065673 for ; Sun, 23 Oct 2011 16:50:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id CF9FC8FC14 for ; Sun, 23 Oct 2011 16:50:03 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p9NGo3SV017130 for ; Sun, 23 Oct 2011 16:50:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p9NGo3lG017129; Sun, 23 Oct 2011 16:50:03 GMT (envelope-from gnats) Resent-Date: Sun, 23 Oct 2011 16:50:03 GMT Resent-Message-Id: <201110231650.p9NGo3lG017129@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ryan Steinmetz Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 037741065673 for ; Sun, 23 Oct 2011 16:47:39 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id CFAFD8FC08 for ; Sun, 23 Oct 2011 16:47:38 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p9NGlcBL029318 for ; Sun, 23 Oct 2011 16:47:38 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p9NGlcm9029317; Sun, 23 Oct 2011 16:47:38 GMT (envelope-from nobody) Message-Id: <201110231647.p9NGlcm9029317@red.freebsd.org> Date: Sun, 23 Oct 2011 16:47:38 GMT From: Ryan Steinmetz To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/161936: [openbsm][patch] praudit can produce invalid XML output X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Oct 2011 16:50:04 -0000 >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, ""); - 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, ""); } else { @@ -1914,7 +1936,7 @@ for (i = 0; i< tok->tt.execenv.count; i++) { if (xml) { fprintf(fp, ""); - 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, ""); } else { >Release-Note: >Audit-Trail: >Unformatted: