This fixes a taint mode problem affecting Perl 5.10.1. It definitely
occurs when fetching data by SNMP, using rateup rather than rrdtool,
when dropping privileges inside MRTG (e.g. --user _mrtg on the
command line rather than using su -m -c '/usr/local/bin/mrtg [...]').
It might affect other uses too. This might not be the best way to
fix it but it seems to be effective.

Also reported at http://oss.oetiker.ch/mrtg-trac/ticket/87

While there, switch to using SYSCONFDIR (though you use something
else anyway because you don't want to run this as a user with write
access to /etc, right? :-)

Works for me monitoring OpenBSD snmpd, various routers and switches
via SNMP, and some nasty hand-crufted scripts for non-SNMP-capable kit.

ok?

Index: Makefile
===================================================================
RCS file: /cvs/ports/net/mrtg/Makefile,v
retrieving revision 1.62
diff -u -p -r1.62 Makefile
--- Makefile    5 Jan 2010 16:36:33 -0000       1.62
+++ Makefile    13 Jan 2010 11:25:26 -0000
@@ -3,7 +3,7 @@
 COMMENT=       multi-router traffic grapher
 
 DISTNAME=      mrtg-2.16.2
-PKGNAME=       ${DISTNAME}p0
+PKGNAME=       ${DISTNAME}p1
 CATEGORIES=    net
 
 HOMEPAGE=      http://oss.oetiker.ch/mrtg/
@@ -37,6 +37,10 @@ CONFIGURE_ENV=       CPPFLAGS="-I${X11BASE}/in
                LDFLAGS="-L${X11BASE}/lib -L${LOCALBASE}/lib"
 
 NO_REGRESS=    Yes
+
+# SUBST_CMD mangles the file
+pre-configure:
+       @perl -pi -e 's,%%SYSCONFDIR%%,${SYSCONFDIR},g' ${WRKSRC}/bin/mrtg
 
 do-install:
        ${INSTALL_DATA_DIR} ${PREFIX}/share/examples/mrtg
Index: patches/patch-bin_mrtg
===================================================================
RCS file: patches/patch-bin_mrtg
diff -N patches/patch-bin_mrtg
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-bin_mrtg      13 Jan 2010 11:25:26 -0000
@@ -0,0 +1,27 @@
+$OpenBSD$
+--- bin/mrtg.orig      Wed Jan 13 00:17:19 2010
++++ bin/mrtg   Wed Jan 13 00:17:49 2010
+@@ -212,7 +212,7 @@ sub main {
+ 
+     my $cfgfile = shift @ARGV;
+ 
+-    if ( !defined $cfgfile and -r "/etc/mrtg.cfg" ) { $cfgfile = 
"/etc/mrtg.cfg"; }
++    if ( !defined $cfgfile and -r "%%SYSCONFDIR%%/mrtg.cfg" ) { $cfgfile = 
"%%SYSCONFDIR%%/mrtg.cfg"; }
+ 
+     printusage() unless defined $cfgfile;
+ 
+@@ -910,6 +910,14 @@ sub writegraphics {
+     # set values to -1 to tell rateup about unknown values
+     $inlast = -1 unless defined $inlast;
+     $outlast = -1 unless defined $outlast;
++
++    # untaint
++    if ($inlast =~ /^([-0-9.]+)$/) {
++        $inlast = $1;
++    }
++    if ($outlast =~ /^([-0-9.]+)$/) {
++        $outlast = $1;
++    }
+     
+     if ($$rcfg{'options'}{'dorelpercent'}{$router}) {
+         @exec = ("${FindBin::Bin}${MRTG_lib::SL}rateup", 

Reply via email to