File tree Expand file tree Collapse file tree 4 files changed +32
-0
lines changed
src/libraries/System.Net.Requests Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 195195 <data name =" net_ftp_receivefailure" xml : space =" preserve" >
196196 <value >The underlying connection was closed: An unexpected error occurred on a receive</value >
197197 </data >
198+ <data name =" net_ftp_no_newlines" xml : space =" preserve" >
199+ <value >CRLF character pair is not allowed in FtpWebRequest inputs.</value >
200+ </data >
198201 <data name =" net_webstatus_NameResolutionFailure" xml : space =" preserve" >
199202 <value >The remote name could not be resolved</value >
200203 </data >
Original file line number Diff line number Diff line change @@ -1118,6 +1118,11 @@ private string GetPortCommandLine()
11181118 /// </summary>
11191119 private static string FormatFtpCommand ( string command , string ? parameter )
11201120 {
1121+ if ( parameter is not null && parameter . Contains ( "\r \n " , StringComparison . Ordinal ) )
1122+ {
1123+ throw new FormatException ( SR . net_ftp_no_newlines ) ;
1124+ }
1125+
11211126 return string . IsNullOrEmpty ( parameter ) ?
11221127 command + "\r \n " :
11231128 command + " " + parameter + "\r \n " ;
Original file line number Diff line number Diff line change @@ -486,6 +486,9 @@ internal FtpWebRequest(Uri uri)
486486 if ( ( object ) uri . Scheme != ( object ) Uri . UriSchemeFtp )
487487 throw new ArgumentOutOfRangeException ( nameof ( uri ) ) ;
488488
489+ if ( uri . OriginalString . Contains ( "\r \n " , StringComparison . Ordinal ) )
490+ throw new FormatException ( SR . net_ftp_no_newlines ) ;
491+
489492 _timerCallback = new TimerThread . Callback ( TimerCallback ) ;
490493 _syncObject = new object ( ) ;
491494
Original file line number Diff line number Diff line change @@ -203,6 +203,27 @@ public void Ftp_RenameFileSubDir_Success(FtpExecutionMode mode)
203203 Assert . False ( DirExists ( mode , dir ) ) ;
204204 }
205205
206+ [ Fact ]
207+ public void Ftp_Ignore_NewLine_Constructor_Throws_FormatException ( )
208+ {
209+ string uri = absoluteUri + Guid . NewGuid ( ) . ToString ( ) ;
210+
211+ Assert . Throws < FormatException > ( ( ) => WebRequest . Create ( $ "{ uri } \r \n { WebRequestMethods . Ftp . AppendFile } { Guid . NewGuid ( ) . ToString ( ) } ") ) ;
212+ }
213+
214+ [ ConditionalFact ( nameof ( LocalServerAvailable ) ) ]
215+ public void Ftp_Ignore_NewLine_GetRequestStream_And_GetResponse_Throws_FormatException_As_InnerException ( )
216+ {
217+ FtpWebRequest ftpWebRequest = ( FtpWebRequest ) WebRequest . Create ( absoluteUri + Guid . NewGuid ( ) . ToString ( ) ) ;
218+ ftpWebRequest . Method = "APPE" ;
219+ ftpWebRequest . Credentials = new NetworkCredential ( "test\r \n test2" , "test\r \n test2" ) ;
220+ var requestException = Assert . Throws < WebException > ( ( ) => ftpWebRequest . GetRequestStream ( ) ) ;
221+ Assert . True ( requestException . InnerException is FormatException ) ;
222+
223+ var responseException = Assert . Throws < WebException > ( ( ) => ftpWebRequest . GetResponse ( ) ) ;
224+ Assert . True ( responseException . InnerException is FormatException ) ;
225+ }
226+
206227 private static async Task < MemoryStream > DoAsync ( FtpWebRequest request , MemoryStream requestBody )
207228 {
208229 if ( requestBody != null )
You can’t perform that action at this time.
0 commit comments