mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
ftp: Harden reply handing a bit and don't raise bad replies to script-land
This improves runtime of the oss-fuzz generated traffic in #125. Specifically, that reproducers included a 064- reply code that was interpreted as needing to be continued. Also, return after AnalyzerViolations() for server replies rather than propagating bad replies them to script-land. This trusts server's to generally behave according to specification.
This commit is contained in:
parent
8f96ac3b77
commit
cf375cf362
1 changed files with 21 additions and 7 deletions
|
@ -166,25 +166,39 @@ void FTP_Analyzer::DeliverStream(int length, const u_char* data, bool orig)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // a new reply
|
{ // a new reply
|
||||||
if ( reply_code > 0 && length > 3 && line[3] == '-' )
|
cont_resp = 0;
|
||||||
|
|
||||||
|
if ( reply_code == 0 )
|
||||||
|
{
|
||||||
|
AnalyzerViolation("non-numeric reply code", (const char*)data, length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if ( reply_code < 100 )
|
||||||
|
{
|
||||||
|
AnalyzerViolation("invalid reply code", (const char*)data, length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if ( length > 3 && line[3] == '-' )
|
||||||
{ // a continued reply
|
{ // a continued reply
|
||||||
pending_reply = reply_code;
|
pending_reply = reply_code;
|
||||||
line = util::skip_whitespace(line + 4, end_of_line);
|
line = util::skip_whitespace(line + 4, end_of_line);
|
||||||
cont_resp = 1;
|
cont_resp = 1;
|
||||||
}
|
}
|
||||||
|
else if ( length > 3 && line[3] != ' ' )
|
||||||
|
{
|
||||||
|
// This is a proper reply code, but there's no space after
|
||||||
|
// the reply code even though the line is long enough.
|
||||||
|
AnalyzerViolation("invalid reply line", (const char*)data, length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{ // a self-contained reply
|
{ // a self-contained reply
|
||||||
if ( reply_code > 0 )
|
line += 3;
|
||||||
line += 3;
|
|
||||||
else
|
|
||||||
AnalyzerViolation("non-numeric reply code", (const char*)data, length);
|
|
||||||
|
|
||||||
if ( line < end_of_line )
|
if ( line < end_of_line )
|
||||||
line = util::skip_whitespace(line, end_of_line);
|
line = util::skip_whitespace(line, end_of_line);
|
||||||
else
|
else
|
||||||
line = end_of_line;
|
line = end_of_line;
|
||||||
|
|
||||||
cont_resp = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue