Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: net/ftp/ftp_network_transaction.cc

Issue 2538773002: Fix yet another silly DCHECK in the FTP code. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/ftp/ftp_network_transaction_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ftp/ftp_network_transaction.cc
diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc
index 2995e90bafa340db9041247a1b257823d92887fb..018a892904ea54274ebd32d499da3c13bc916eaf 100644
--- a/net/ftp/ftp_network_transaction.cc
+++ b/net/ftp/ftp_network_transaction.cc
@@ -36,8 +36,8 @@ const char kCRLF[] = "\r\n";
const int kCtrlBufLen = 1024;
-// Returns true if |input| can be safely used as a part of FTP command.
-bool IsValidFTPCommandString(const std::string& input) {
+// Returns true if |input| can be safely used as a part of an FTP command.
+bool IsValidFTPCommandSubstring(const std::string& input) {
// RFC 959 only allows ASCII strings, but at least Firefox can send non-ASCII
// characters in the command if the request path contains them. To be
// compatible, we do the same and allow non-ASCII characters in a command.
@@ -462,7 +462,7 @@ int FtpNetworkTransaction::SendFtpCommand(const std::string& command,
DCHECK(!write_command_buf_.get());
DCHECK(!write_buf_.get());
- if (!IsValidFTPCommandString(command)) {
+ if (!IsValidFTPCommandSubstring(command)) {
// Callers should validate the command themselves and return a more specific
// error code.
NOTREACHED();
@@ -505,7 +505,7 @@ std::string FtpNetworkTransaction::GetRequestPathForFtpCommand(
UnescapeRule::SPACES |
UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS;
// This may unescape to non-ASCII characters, but we allow that. See the
- // comment for IsValidFTPCommandString.
+ // comment for IsValidFTPCommandSubstring.
path = UnescapeURLComponent(path, unescape_rules);
if (system_type_ == SYSTEM_TYPE_VMS) {
@@ -515,7 +515,7 @@ std::string FtpNetworkTransaction::GetRequestPathForFtpCommand(
path = FtpUtil::UnixFilePathToVMS(path);
}
- DCHECK(IsValidFTPCommandString(path));
+ DCHECK(IsValidFTPCommandSubstring(path));
return path;
}
@@ -756,7 +756,7 @@ int FtpNetworkTransaction::DoCtrlWriteComplete(int result) {
int FtpNetworkTransaction::DoCtrlWriteUSER() {
std::string command = "USER " + base::UTF16ToUTF8(credentials_.username());
- if (!IsValidFTPCommandString(command))
+ if (!IsValidFTPCommandSubstring(command))
return Stop(ERR_MALFORMED_IDENTITY);
next_state_ = STATE_CTRL_READ;
@@ -786,7 +786,7 @@ int FtpNetworkTransaction::ProcessResponseUSER(
int FtpNetworkTransaction::DoCtrlWritePASS() {
std::string command = "PASS " + base::UTF16ToUTF8(credentials_.password());
- if (!IsValidFTPCommandString(command))
+ if (!IsValidFTPCommandSubstring(command))
return Stop(ERR_MALFORMED_IDENTITY);
next_state_ = STATE_CTRL_READ;
@@ -896,6 +896,11 @@ int FtpNetworkTransaction::ProcessResponsePWD(const FtpCtrlResponse& response) {
line = FtpUtil::VMSPathToUnix(line);
if (!line.empty() && line.back() == '/')
line.erase(line.length() - 1);
+ // Fail if the "path" contains characters not allowed in commands.
+ // This does mean that files with CRs or LFs in their names aren't
+ // handled, but that's probably for the best.
+ if (!IsValidFTPCommandSubstring(line))
+ return Stop(ERR_INVALID_RESPONSE);
current_remote_directory_ = line;
next_state_ = STATE_CTRL_WRITE_TYPE;
break;
« no previous file with comments | « no previous file | net/ftp/ftp_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698