From 96cc419924c38874f9e2f2e5ccf3cd0430d90f43 Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Wed, 2 Oct 2013 08:35:02 +0200 Subject: Fix bug #65667: ftp_nb_continue produces segfault the idea behind ftp_nb_get is for it to be followed by multiple calls to ftp_nb_continue in order to download a file piece-by-piece. As such, it's unwise to close the stream used to write the downloaded data to when the file hasn't been completely downloaded within the first call to ftp_nb_get. This regression was added in a93a462dcefd62e07963dd2da506fbb3409c88b5 and this patch restores the behavior that was seen pre-patch. --- ext/ftp/php_ftp.c | 4 +- ext/ftp/tests/ftp_nb_continue.phpt | 182 +++++++++++++++++++++++++++++++++++++ ext/ftp/tests/server.inc | 7 ++ 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 ext/ftp/tests/ftp_nb_continue.phpt (limited to 'ext/ftp') diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index da22e0b63e..21e13ea460 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -968,7 +968,9 @@ PHP_FUNCTION(ftp_nb_get) RETURN_LONG(PHP_FTP_FAILED); } - php_stream_close(outstream); + if (ret == PHP_FTP_FINISHED){ + php_stream_close(outstream); + } RETURN_LONG(ret); } diff --git a/ext/ftp/tests/ftp_nb_continue.phpt b/ext/ftp/tests/ftp_nb_continue.phpt new file mode 100644 index 0000000000..1f70339913 --- /dev/null +++ b/ext/ftp/tests/ftp_nb_continue.phpt @@ -0,0 +1,182 @@ +--TEST-- +Testing whether ftp_nb_continue() fetches more data +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +This is line 0 of the test data. +This is line 1 of the test data. +This is line 2 of the test data. +This is line 3 of the test data. +This is line 4 of the test data. +This is line 5 of the test data. +This is line 6 of the test data. +This is line 7 of the test data. +This is line 8 of the test data. +This is line 9 of the test data. +This is line 10 of the test data. +This is line 11 of the test data. +This is line 12 of the test data. +This is line 13 of the test data. +This is line 14 of the test data. +This is line 15 of the test data. +This is line 16 of the test data. +This is line 17 of the test data. +This is line 18 of the test data. +This is line 19 of the test data. +This is line 20 of the test data. +This is line 21 of the test data. +This is line 22 of the test data. +This is line 23 of the test data. +This is line 24 of the test data. +This is line 25 of the test data. +This is line 26 of the test data. +This is line 27 of the test data. +This is line 28 of the test data. +This is line 29 of the test data. +This is line 30 of the test data. +This is line 31 of the test data. +This is line 32 of the test data. +This is line 33 of the test data. +This is line 34 of the test data. +This is line 35 of the test data. +This is line 36 of the test data. +This is line 37 of the test data. +This is line 38 of the test data. +This is line 39 of the test data. +This is line 40 of the test data. +This is line 41 of the test data. +This is line 42 of the test data. +This is line 43 of the test data. +This is line 44 of the test data. +This is line 45 of the test data. +This is line 46 of the test data. +This is line 47 of the test data. +This is line 48 of the test data. +This is line 49 of the test data. +This is line 50 of the test data. +This is line 51 of the test data. +This is line 52 of the test data. +This is line 53 of the test data. +This is line 54 of the test data. +This is line 55 of the test data. +This is line 56 of the test data. +This is line 57 of the test data. +This is line 58 of the test data. +This is line 59 of the test data. +This is line 60 of the test data. +This is line 61 of the test data. +This is line 62 of the test data. +This is line 63 of the test data. +This is line 64 of the test data. +This is line 65 of the test data. +This is line 66 of the test data. +This is line 67 of the test data. +This is line 68 of the test data. +This is line 69 of the test data. +This is line 70 of the test data. +This is line 71 of the test data. +This is line 72 of the test data. +This is line 73 of the test data. +This is line 74 of the test data. +This is line 75 of the test data. +This is line 76 of the test data. +This is line 77 of the test data. +This is line 78 of the test data. +This is line 79 of the test data. +This is line 80 of the test data. +This is line 81 of the test data. +This is line 82 of the test data. +This is line 83 of the test data. +This is line 84 of the test data. +This is line 85 of the test data. +This is line 86 of the test data. +This is line 87 of the test data. +This is line 88 of the test data. +This is line 89 of the test data. +This is line 90 of the test data. +This is line 91 of the test data. +This is line 92 of the test data. +This is line 93 of the test data. +This is line 94 of the test data. +This is line 95 of the test data. +This is line 96 of the test data. +This is line 97 of the test data. +This is line 98 of the test data. +This is line 99 of the test data. +This is line 100 of the test data. +This is line 101 of the test data. +This is line 102 of the test data. +This is line 103 of the test data. +This is line 104 of the test data. +This is line 105 of the test data. +This is line 106 of the test data. +This is line 107 of the test data. +This is line 108 of the test data. +This is line 109 of the test data. +This is line 110 of the test data. +This is line 111 of the test data. +This is line 112 of the test data. +This is line 113 of the test data. +This is line 114 of the test data. +This is line 115 of the test data. +This is line 116 of the test data. +This is line 117 of the test data. +This is line 118 of the test data. +This is line 119 of the test data. +This is line 120 of the test data. +This is line 121 of the test data. +This is line 122 of the test data. +This is line 123 of the test data. +This is line 124 of the test data. +This is line 125 of the test data. +This is line 126 of the test data. +This is line 127 of the test data. +This is line 128 of the test data. +This is line 129 of the test data. +This is line 130 of the test data. +This is line 131 of the test data. +This is line 132 of the test data. +This is line 133 of the test data. +This is line 134 of the test data. +This is line 135 of the test data. +This is line 136 of the test data. +This is line 137 of the test data. +This is line 138 of the test data. +This is line 139 of the test data. +This is line 140 of the test data. +This is line 141 of the test data. +This is line 142 of the test data. +This is line 143 of the test data. +This is line 144 of the test data. +This is line 145 of the test data. +This is line 146 of the test data. +This is line 147 of the test data. +This is line 148 of the test data. +This is line 149 of the test data. diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index 7dc8fa08d9..bb0c1ff10b 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -368,6 +368,13 @@ if ($pid) { } fputs($s, "226 Closing data Connection.\r\n"); break; + case "mediumfile": + fputs($s, "150 File status okay; about to open data connection.\r\n"); + for($i = 0; $i < 150; $i++){ + fputs($fs, "This is line $i of the test data.\n"); + } + fputs($s, "226 Closing data Connection.\r\n"); + default: fputs($s, "550 {$matches[1]}: No such file or directory \r\n"); break; -- cgit v1.2.1 From fb38fdc7fd97f1e057b8c9d9102ce8a39b430f81 Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Sat, 19 Oct 2013 20:55:02 -0700 Subject: Remove senseless check here --- ext/ftp/ftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/ftp') diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 0d6704f9d2..58d3c2ec4d 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -630,7 +630,7 @@ ftp_alloc(ftpbuf_t *ftp, const long size, char **response) return 0; } - if (response && ftp->inbuf) { + if (response) { *response = estrdup(ftp->inbuf); } -- cgit v1.2.1 From 1494298231072d5991e76db5ef25f20e81018106 Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Sun, 20 Oct 2013 08:55:48 -0700 Subject: Minor Coverity tweaks --- ext/ftp/ftp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/ftp') diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 58d3c2ec4d..4da8d602c9 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1643,7 +1643,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC) if (ftp->resp == 226) { ftp->data = data_close(ftp, data); php_stream_close(tmpstream); - return ecalloc(1, sizeof(char**)); + return ecalloc(1, sizeof(char*)); } /* pull data buffer into tmpfile */ @@ -1671,11 +1671,11 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC) } } - ftp->data = data = data_close(ftp, data); + ftp->data = data_close(ftp, data); php_stream_rewind(tmpstream); - ret = safe_emalloc((lines + 1), sizeof(char**), size * sizeof(char*)); + ret = safe_emalloc((lines + 1), sizeof(char*), size * sizeof(char*)); entry = ret; text = (char*) (ret + lines + 1); -- cgit v1.2.1 From 8f4a6d6e1b6c36259a5dc865d16f0dad76f2f2c9 Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Sun, 20 Oct 2013 09:36:50 -0700 Subject: Clean up this weird safe_emalloc() call --- ext/ftp/ftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/ftp') diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 4da8d602c9..b82017e21f 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1675,7 +1675,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC) php_stream_rewind(tmpstream); - ret = safe_emalloc((lines + 1), sizeof(char*), size * sizeof(char*)); + ret = safe_emalloc((lines + 1), sizeof(char*), size); entry = ret; text = (char*) (ret + lines + 1); -- cgit v1.2.1