[PATCH] Bug #30027 segmentation fault in ftp_get/memchr()
| From: | Chris Field | Date: | Thu, 30 Sep 2004 12:47:21 +0000 |
| Subject: | [PATCH] Bug #30027 segmentation fault in ftp_get/memchr() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-13075@lists.php.net to get a copy of this message | ||
Attached is a patch that fixes this problem. The problem seems to occur
when a \r is the last char in the data buffer.
--
Chris Field
cfield@affinitysolutions.com
Affinity Solutions Inc.
350 5th Avenue
22nd Floor
New York, NY 10118
(212) 822-9620
--- php-4.3.8/ext/ftp/ftp.c 2004-03-31 15:44:04.000000000 -0500 +++ php-4.3.8/ext/ftp/ftp.c.1 2004-09-30 08:35:59.000000000 -0400 @@ -727,12 +727,12 @@ ptr = s; } #else - while ((s = memchr(ptr, '\r', (e - ptr)))) { + while ((e>ptr) && (s = memchr(ptr, '\r', (e - ptr)))) { php_stream_write(outstream, ptr, (s - ptr)); if (*(s + 1) == '\n') { s++; + php_stream_putc(outstream, '\n'); } - php_stream_putc(outstream, '\n'); ptr = s + 1; } #endif
--- php-4.3.8/ext/ftp/ftp.c 2004-03-31 15:44:04.000000000 -0500 +++ php-4.3.8/ext/ftp/ftp.c.1 2004-09-30 08:35:59.000000000 -0400 @@ -727,12 +727,12 @@ ptr = s; } #else - while ((s = memchr(ptr, '\r', (e - ptr)))) { + while ((e>ptr) && (s = memchr(ptr, '\r', (e - ptr)))) { php_stream_write(outstream, ptr, (s - ptr)); if (*(s + 1) == '\n') { s++; + php_stream_putc(outstream, '\n'); } - php_stream_putc(outstream, '\n'); ptr = s + 1; } #endif