b74969
Adapted for 5.4.16 from
b74969
b74969
b74969
From 1494298231072d5991e76db5ef25f20e81018106 Mon Sep 17 00:00:00 2001
b74969
From: Rasmus Lerdorf <rasmus@lerdorf.com>
b74969
Date: Sun, 20 Oct 2013 08:55:48 -0700
b74969
Subject: [PATCH] Minor Coverity tweaks
b74969
b74969
---
b74969
 ext/ftp/ftp.c | 6 +++---
b74969
 1 file changed, 3 insertions(+), 3 deletions(-)
b74969
b74969
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
b74969
index 58d3c2e..4da8d60 100644
b74969
--- a/ext/ftp/ftp.c
b74969
+++ b/ext/ftp/ftp.c
b74969
@@ -1635,7 +1635,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
b74969
 	if (ftp->resp == 226) {
b74969
 		ftp->data = data_close(ftp, data);
b74969
 		php_stream_close(tmpstream);
b74969
-		return ecalloc(1, sizeof(char**));
b74969
+		return ecalloc(1, sizeof(char*));
b74969
 	}
b74969
 
b74969
 	/* pull data buffer into tmpfile */
b74969
@@ -1663,11 +1663,11 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
b74969
 		}
b74969
 	}
b74969
 
b74969
-	ftp->data = data = data_close(ftp, data);
b74969
+	ftp->data = data_close(ftp, data);
b74969
 
b74969
 	php_stream_rewind(tmpstream);
b74969
 
b74969
-	ret = safe_emalloc((lines + 1), sizeof(char**), size * sizeof(char*));
b74969
+	ret = safe_emalloc((lines + 1), sizeof(char*), size * sizeof(char*));
b74969
 
b74969
 	entry = ret;
b74969
 	text = (char*) (ret + lines + 1);
b74969
-- 
b74969
2.1.4
b74969
b74969
From 8f4a6d6e1b6c36259a5dc865d16f0dad76f2f2c9 Mon Sep 17 00:00:00 2001
b74969
From: Rasmus Lerdorf <rasmus@lerdorf.com>
b74969
Date: Sun, 20 Oct 2013 09:36:50 -0700
b74969
Subject: [PATCH] Clean up this weird safe_emalloc() call
b74969
b74969
---
b74969
 ext/ftp/ftp.c | 2 +-
b74969
 1 file changed, 1 insertion(+), 1 deletion(-)
b74969
b74969
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
b74969
index 4da8d60..b82017e 100644
b74969
--- a/ext/ftp/ftp.c
b74969
+++ b/ext/ftp/ftp.c
b74969
@@ -1667,7 +1667,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
b74969
 
b74969
 	php_stream_rewind(tmpstream);
b74969
 
b74969
-	ret = safe_emalloc((lines + 1), sizeof(char*), size * sizeof(char*));
b74969
+	ret = safe_emalloc((lines + 1), sizeof(char*), size);
b74969
 
b74969
 	entry = ret;
b74969
 	text = (char*) (ret + lines + 1);
b74969
-- 
b74969
2.1.4
b74969
b74969
From ac2832935435556dc593784cd0087b5e576bbe4d Mon Sep 17 00:00:00 2001
b74969
From: Stanislav Malyshev <stas@php.net>
b74969
Date: Wed, 29 Apr 2015 21:57:33 -0700
b74969
Subject: [PATCH] Fix bug #69545 - avoid overflow when reading list
b74969
b74969
---
b74969
 ext/ftp/ftp.c | 82 +++++++++++++++++++++++++++++------------------------------
b74969
 1 file changed, 41 insertions(+), 41 deletions(-)
b74969
b74969
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
b74969
index 3ff54ff..53560eb 100644
b74969
--- a/ext/ftp/ftp.c
b74969
+++ b/ext/ftp/ftp.c
b74969
@@ -1603,8 +1603,8 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
b74969
 	databuf_t	*data = NULL;
b74969
 	char		*ptr;
b74969
 	int		ch, lastch;
b74969
-	int		size, rcvd;
b74969
-	int		lines;
b74969
+	size_t		size, rcvd;
b74969
+	size_t		lines;
b74969
 	char		**ret = NULL;
b74969
 	char		**entry;
b74969
 	char		*text;
b74969
@@ -1646,7 +1646,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
b74969
 	lines = 0;
b74969
 	lastch = 0;
b74969
 	while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) {
b74969
-		if (rcvd == -1) {
b74969
+		if (rcvd == -1 || rcvd > ((size_t)(-1))-size) {
b74969
 			goto bail;
b74969
 		}
b74969
 
b74969
-- 
b74969
2.1.4
b74969
b74969
From 0765623d6991b62ffcd93ddb6be8a5203a2fa7e2 Mon Sep 17 00:00:00 2001
b74969
From: Stanislav Malyshev <stas@php.net>
b74969
Date: Sun, 31 May 2015 17:23:06 -0700
b74969
Subject: [PATCH] improve fix for Bug #69545
b74969
b74969
---
b74969
 NEWS          | 4 ++++
b74969
 ext/ftp/ftp.c | 2 --
b74969
 2 files changed, 4 insertions(+), 2 deletions(-)
b74969
b74969
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
b74969
index 53560eb..50d8def 100644
b74969
--- a/ext/ftp/ftp.c
b74969
+++ b/ext/ftp/ftp.c
b74969
@@ -1656,8 +1656,6 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
b74969
 		for (ptr = data->buf; rcvd; rcvd--, ptr++) {
b74969
 			if (*ptr == '\n' && lastch == '\r') {
b74969
 				lines++;
b74969
-			} else {
b74969
-				size++;
b74969
 			}
b74969
 			lastch = *ptr;
b74969
 		}
b74969
-- 
b74969
2.1.4
b74969