Permalink
Browse files

fix problem with SIGHUP causing exec of unqualified script name

  • Loading branch information...
kjetilho authored and steveschnepp committed Oct 17, 2012
1 parent 1fa698d commit 25985da7d3e121c83b00198c65562de4367172b3
Showing with 22 additions and 3 deletions.
  1. +17 −0 node/lib/Munin/Node/Server.pm
  2. +5 −3 node/sbin/munin-node
@@ -209,6 +209,23 @@ sub _process_command_line {
return 1;
}
+# We override this function from Net::Server. It prefers to read
+# /proc/PID/cmdline, which causes $0 to become /usr/bin/perl (after a re-exec
+# to the argv returned by this function), while we want to keep the value
+# which is the path to the script itself.
+sub _get_commandline {
+ my $self = shift;
+
+ my $script = $0;
+ # make relative path absolute
+ $script = $ENV{'PWD'} .'/'. $script if $script =~ m|^[^/]+/| && $ENV{'PWD'};
+ # untaint for later use in hup
+ # TBD: should we prevent script names containing TAB, LF and other unusual
+ # characters?
+ $script =~ /^(.+)$/;
+ return [ $1, @ARGV ]
+}
+
sub _expect_starttls {
my ($session) = @_;
View
@@ -54,9 +54,6 @@ sub main
$ENV{$key} = $1;
}
- $0 =~ /([^\/]*)$/;
- $0 = $1;
-
parse_args();
my $config = Munin::Node::Config->instance();
@@ -88,6 +85,11 @@ sub main
conf_file => $conffile,
);
+ # Untaint $0 after Munin::Node::Server has had a chance of getting
+ # the original value
+ $0 =~ /([^\/]*)$/;
+ $0 = $1;
+
return 0;
}

0 comments on commit 25985da

Please sign in to comment.