From 794d8a51a0ab9dcad230f154698b7e798da1ca9d Mon Sep 17 00:00:00 2001 From: jcm Date: Thu, 14 Jul 2022 15:48:32 +0200 Subject: [PATCH 1/3] QA - ftp_rawlist - check list return value --- ext/ftp/tests/ftp_rawlist_basic1.phpt | 16 +++++++++++++--- ext/ftp/tests/server.inc | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ext/ftp/tests/ftp_rawlist_basic1.phpt b/ext/ftp/tests/ftp_rawlist_basic1.phpt index 2dc59bc40a662..9ef2d40fb92c6 100644 --- a/ext/ftp/tests/ftp_rawlist_basic1.phpt +++ b/ext/ftp/tests/ftp_rawlist_basic1.phpt @@ -1,7 +1,5 @@ --TEST-- Testing ftp_rawlist basic functionality ---CREDITS-- -Gabriel Caruso (carusogabriel34@gmail.com) --EXTENSIONS-- ftp pcntl @@ -13,7 +11,19 @@ $ftp = ftp_connect('127.0.0.1', $port); ftp_login($ftp, 'user', 'pass'); $ftp or die("Couldn't connect to the server"); -var_dump(is_array(ftp_rawlist($ftp, 'www/'))); +$result = ftp_rawlist($ftp, 'www/'); +var_dump(is_array($result)); +var_dump($result); +ftp_close($ftp); ?> --EXPECT-- bool(true) +array(3) { + [0]=> + string(5) "file1" + [1]=> + string(5) "file1" + [2]=> + string(9) "file +b0rk" +} diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index afbfd88f73579..3299356f92233 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -446,8 +446,27 @@ if ($pid) { fputs($s, "200 " . $matches[1] . " bytes allocated\r\n"); }elseif (preg_match('/^LIST www\//', $buf, $matches)) { - fputs($s, "226 Transfer complete\r\n"); + if (empty($pasv)) { + fputs($s, "150 File status okay; about to open data connection\r\n"); + if (!$fs = stream_socket_client("tcp://$host:$port")) { + fputs($s, "425 Can't open data connection\r\n"); + continue; + } + } else { + fputs($s, "125 Data connection already open; transfer starting.\r\n"); + $fs=$pasvs; + } + + if ((!empty($ssl)) && (!stream_socket_enable_crypto($pasvs, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER))) { + die("SSLv23 handshake failed.\n"); + } + + fputs($fs, "file1\r\nfile1\r\nfile\nb0rk\r\n"); + fputs($s, "226 Closing data Connection.\r\n"); + fclose($fs); + + fputs($s, "226 Transfer complete\r\n"); }elseif (preg_match('/^LIST no_exists\//', $buf, $matches)) { fputs($s, "425 Error establishing connection\r\n"); From c2ec35f4657854cd7430948aa3a42b48eb20b3c8 Mon Sep 17 00:00:00 2001 From: Juan Morales Date: Fri, 15 Jul 2022 16:35:01 +0200 Subject: [PATCH 2/3] add spaces around variable assignment Co-authored-by: Christoph M. Becker --- ext/ftp/tests/server.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index 3299356f92233..56c78ed3907c5 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -454,7 +454,7 @@ if ($pid) { } } else { fputs($s, "125 Data connection already open; transfer starting.\r\n"); - $fs=$pasvs; + $fs = $pasvs; } From 0e0e8b0467c42443e76d9c66e69d66057d556ed2 Mon Sep 17 00:00:00 2001 From: Juan Morales Date: Fri, 15 Jul 2022 16:36:59 +0200 Subject: [PATCH 3/3] Put back old credit in the test :) --- ext/ftp/tests/ftp_rawlist_basic1.phpt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/ftp/tests/ftp_rawlist_basic1.phpt b/ext/ftp/tests/ftp_rawlist_basic1.phpt index 9ef2d40fb92c6..71e5c7db88137 100644 --- a/ext/ftp/tests/ftp_rawlist_basic1.phpt +++ b/ext/ftp/tests/ftp_rawlist_basic1.phpt @@ -1,5 +1,7 @@ --TEST-- Testing ftp_rawlist basic functionality +--CREDITS-- +Gabriel Caruso (carusogabriel34@gmail.com) --EXTENSIONS-- ftp pcntl