ftpserver.pl: Added argument check to IMAP command handlers
Added BAD argument check to the following IMAP command handlers: APPEND, STORE, LIST, EXAMINE, STATUS and SEARCH
This commit is contained in:
@@ -877,6 +877,10 @@ sub APPEND_imap {
|
|||||||
my ($mailbox, $size) = ($1, $2);
|
my ($mailbox, $size) = ($1, $2);
|
||||||
fix_imap_params($mailbox);
|
fix_imap_params($mailbox);
|
||||||
|
|
||||||
|
if($mailbox eq "") {
|
||||||
|
sendcontrol "$cmdid BAD Command Argument\r\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
sendcontrol "+ Ready for literal data\r\n";
|
sendcontrol "+ Ready for literal data\r\n";
|
||||||
|
|
||||||
my $testno = $mailbox;
|
my $testno = $mailbox;
|
||||||
@@ -936,6 +940,7 @@ sub APPEND_imap {
|
|||||||
logmsg "received $size bytes upload\n";
|
logmsg "received $size bytes upload\n";
|
||||||
|
|
||||||
sendcontrol "$cmdid OK APPEND completed\r\n";
|
sendcontrol "$cmdid OK APPEND completed\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -950,6 +955,9 @@ sub STORE_imap {
|
|||||||
if ($selected eq "") {
|
if ($selected eq "") {
|
||||||
sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
|
sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
|
||||||
}
|
}
|
||||||
|
elsif (($uid eq "") || ($what eq "")) {
|
||||||
|
sendcontrol "$cmdid BAD Command Argument\r\n";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
sendcontrol "* $uid FETCH (FLAGS (\\Seen \\Deleted))\r\n";
|
sendcontrol "* $uid FETCH (FLAGS (\\Seen \\Deleted))\r\n";
|
||||||
sendcontrol "$cmdid OK STORE completed\r\n";
|
sendcontrol "$cmdid OK STORE completed\r\n";
|
||||||
@@ -961,7 +969,6 @@ sub STORE_imap {
|
|||||||
sub LIST_imap {
|
sub LIST_imap {
|
||||||
my ($args) = @_;
|
my ($args) = @_;
|
||||||
my ($reference, $mailbox) = split(/ /, $args, 2);
|
my ($reference, $mailbox) = split(/ /, $args, 2);
|
||||||
my @data;
|
|
||||||
fix_imap_params($reference, $mailbox);
|
fix_imap_params($reference, $mailbox);
|
||||||
|
|
||||||
logmsg "LIST_imap got $args\n";
|
logmsg "LIST_imap got $args\n";
|
||||||
@@ -969,12 +976,18 @@ sub LIST_imap {
|
|||||||
if ($reference eq "verifiedserver") {
|
if ($reference eq "verifiedserver") {
|
||||||
# this is the secret command that verifies that this actually is
|
# this is the secret command that verifies that this actually is
|
||||||
# the curl test server
|
# the curl test server
|
||||||
@data = ("* LIST () \"/\" \"WE ROOLZ: $$\"\r\n");
|
sendcontrol "* LIST () \"/\" \"WE ROOLZ: $$\"\r\n";
|
||||||
|
sendcontrol "$cmdid OK LIST Completed\r\n";
|
||||||
|
|
||||||
if($verbose) {
|
if($verbose) {
|
||||||
print STDERR "FTPD: We returned proof we are the test server\n";
|
print STDERR "FTPD: We returned proof we are the test server\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
logmsg "return proof we are we\n";
|
logmsg "return proof we are we\n";
|
||||||
}
|
}
|
||||||
|
elsif ($reference eq "") {
|
||||||
|
sendcontrol "$cmdid BAD Command Argument\r\n";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
my $testno = $reference;
|
my $testno = $reference;
|
||||||
|
|
||||||
@@ -987,14 +1000,14 @@ sub LIST_imap {
|
|||||||
|
|
||||||
loadtest("$srcdir/data/test$testno");
|
loadtest("$srcdir/data/test$testno");
|
||||||
|
|
||||||
@data = getpart("reply", "data$testpart");
|
my @data = getpart("reply", "data$testpart");
|
||||||
}
|
|
||||||
|
|
||||||
for my $d (@data) {
|
for my $d (@data) {
|
||||||
sendcontrol $d;
|
sendcontrol $d;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendcontrol "$cmdid OK LIST Completed\r\n";
|
sendcontrol "$cmdid OK LIST Completed\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1003,8 +1016,12 @@ sub EXAMINE_imap {
|
|||||||
my ($testno) = @_;
|
my ($testno) = @_;
|
||||||
fix_imap_params($testno);
|
fix_imap_params($testno);
|
||||||
|
|
||||||
logmsg "EXAMINE_imap got test $testno\n";
|
logmsg "EXAMINE_imap got $testno\n";
|
||||||
|
|
||||||
|
if ($testno eq "") {
|
||||||
|
sendcontrol "$cmdid BAD Command Argument\r\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
$testno =~ s/[^0-9]//g;
|
$testno =~ s/[^0-9]//g;
|
||||||
my $testpart = "";
|
my $testpart = "";
|
||||||
if ($testno > 10000) {
|
if ($testno > 10000) {
|
||||||
@@ -1021,6 +1038,7 @@ sub EXAMINE_imap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendcontrol "$cmdid OK [READ-ONLY] EXAMINE completed\r\n";
|
sendcontrol "$cmdid OK [READ-ONLY] EXAMINE completed\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1029,8 +1047,12 @@ sub STATUS_imap {
|
|||||||
my ($testno) = @_;
|
my ($testno) = @_;
|
||||||
fix_imap_params($testno);
|
fix_imap_params($testno);
|
||||||
|
|
||||||
logmsg "STATUS_imap got test $testno\n";
|
logmsg "STATUS_imap got $testno\n";
|
||||||
|
|
||||||
|
if ($testno eq "") {
|
||||||
|
sendcontrol "$cmdid BAD Command Argument\r\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
$testno =~ s/[^0-9]//g;
|
$testno =~ s/[^0-9]//g;
|
||||||
my $testpart = "";
|
my $testpart = "";
|
||||||
if ($testno > 10000) {
|
if ($testno > 10000) {
|
||||||
@@ -1047,6 +1069,7 @@ sub STATUS_imap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendcontrol "$cmdid OK STATUS completed\r\n";
|
sendcontrol "$cmdid OK STATUS completed\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1060,6 +1083,9 @@ sub SEARCH_imap {
|
|||||||
if ($selected eq "") {
|
if ($selected eq "") {
|
||||||
sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
|
sendcontrol "$cmdid BAD Command received in Invalid state\r\n";
|
||||||
}
|
}
|
||||||
|
elsif ($what eq "") {
|
||||||
|
sendcontrol "$cmdid BAD Command Argument\r\n";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
my $testno = $selected;
|
my $testno = $selected;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user