3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-07-21 21:07:24 +02:00

applets/trans.pl: whitelist allowed options

This commit is contained in:
Pragmatic Software 2025-07-19 12:24:31 -07:00
parent 66ce01a0c3
commit 4582e225e5
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
2 changed files with 25 additions and 4 deletions

27
applets/trans.pl vendored
View File

@ -5,6 +5,8 @@
use warnings;
use strict;
use Getopt::Long qw/GetOptionsFromString/;
if (not @ARGV) {
print "Usage: trans [options] [source]:[targets] <word or phrase>\n";
exit;
@ -17,9 +19,28 @@ $args =~ s/^\s+|\s+$//g;
my $opts = '-j -no-ansi -no-autocorrect -no-browser -no-pager -no-play';
$opts .= ' -b' unless $args =~ /^-/;
if ($args =~ m/-(pager|browser|player|download|p|I|interactive|shell|emacs|E|x|4|6|ipv|inet|u|U|upgrade|user)/) {
print "I don't think so.\n";
exit;
{
my $opt_err;
local $SIG{__WARN__} = sub {
$opt_err = shift;
chomp $opt_err;
};
Getopt::Long::Configure('no_auto_abbrev', 'no_ignore_case');
my %h;
my @allowed = qw/V version H help M man T reference R reference-english S list-engines list-languages list-languages-english list-codes list-all L linguist e engine b brief d dictionary identify show-original show-original-phonetics show-translation show-translation-phonetics show-prompt-message show-languages show-original-dictionary show-dictionary show-alternatives hl host s sl source from t tl target to/;
my ($ret, $rest) = GetOptionsFromString($args, \%h, @allowed);
if ($opt_err) {
print "$opt_err\n";
exit;
}
if ($ret != 1) {
print "Error parsing options.\n";
exit;
}
}
my $result = `trans $opts $args`;

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4874,
BUILD_REVISION => 4875,
BUILD_DATE => "2025-07-19",
};