3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-05 19:49:32 +01:00

pbot-vm: restore stdin for default languages

This commit is contained in:
Pragmatic Software 2022-03-16 12:18:11 -07:00
parent 01cefe462f
commit fcb39511c3

View File

@ -25,7 +25,7 @@ sub new {
$self->{execfile} = $conf{execfile}; $self->{execfile} = $conf{execfile};
$self->{code} = $conf{code}; $self->{code} = $conf{code};
$self->{cmdline} = $conf{cmdline}; $self->{cmdline} = $conf{cmdline};
$self->{input} = $conf{input}; $self->{input} = $conf{input} // '';
$self->{date} = $conf{date}; $self->{date} = $conf{date};
$self->{arguments} = $conf{arguments}; $self->{arguments} = $conf{arguments};
$self->{factoid} = $conf{factoid}; $self->{factoid} = $conf{factoid};
@ -46,20 +46,23 @@ sub preprocess {
print $fh $self->{code} . "\n"; print $fh $self->{code} . "\n";
close $fh; close $fh;
my $quoted_args = ''; my $quoted_args = $self->quote_args($self->{arguments});
if (length $self->{arguments}) { my $stdin = 'ulimit -f 2000; ulimit -t 8; ulimit -u 200; ';
my @args = $self->split_line($self->{arguments}, strip_quotes => 1, preserve_escapes => 0);
foreach my $arg (@args) { if (length $self->{input}) {
$arg =~ s/'/'"'"'/g; my $quoted_cmd = "$self->{cmdline} $quoted_args";
$quoted_args .= "'$arg' "; $quoted_cmd =~ s/'/'"'"'/g;
}
my $quoted_input = $self->{input};
$quoted_input =~ s/'/'"'"'/g;
$stdin .= "/bin/bash -c '$quoted_cmd' <<< '$quoted_input'";
} else {
$stdin .= "$self->{cmdline} $quoted_args";
} }
$self->{input} = "ulimit -f 2000; ulimit -t 8; ulimit -u 200; $self->{cmdline} $quoted_args"; my ($retval, $stdout, $stderr) = $self->execute(60, $stdin, '/bin/sh');
my ($retval, $stdout, $stderr) = $self->execute(60, $self->{input}, '/bin/sh');
$self->{output} = $stderr; $self->{output} = $stderr;
$self->{output} .= ' ' if length $self->{output}; $self->{output} .= ' ' if length $self->{output};
@ -208,4 +211,19 @@ sub split_line {
return @args; return @args;
} }
sub quote_args {
my ($self, $text) = @_;
my @args = $self->split_line($text, strip_quotes => 1, preserve_escapes => 0);
my $quoted = '';
foreach my $arg (@args) {
$arg =~ s/'/'"'"'/g;
$quoted .= "'$arg' ";
}
return $quoted;
}
1; 1;