com php-src: Fix bug #68095 - invalid read in php_getopt( ): NEWS main/getopt.c
| From: | Stanislav Malyshev | Date: | Tue, 28 Oct 2014 02:06:44 +0000 |
| Subject: | com php-src: Fix bug #68095 - invalid read in php_getopt( ): NEWS main/getopt.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82724@lists.php.net to get a copy of this message | ||
Commit: deadeeae1d08877021eb2796aa6790baa74361ed
Author: Stanislav Malyshev <stas@php.net> Mon, 27 Oct 2014 19:04:46 -0700
Parents: 88527e456951d13a681fbef65984bc3c4907fded
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=deadeeae1d08877021eb2796aa6790baa74361ed
Log:
Fix bug #68095 - invalid read in php_getopt()
It's a hacky solution and incomplete, but I don't see other way
without refactoring the whole getopt protocol.
Bugs:
https://bugs.php.net/68095
Changed paths:
M NEWS
M main/getopt.c
Diff:
diff --git a/NEWS b/NEWS
index c7fd7af..15a2951 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PHP NEWS
?? ??? 2014, PHP 5.5.19
- Core:
+ . Fixed bug #68095 (AddressSanitizer reports a heap buffer overflow in
+ php_getopt()). (Stas)
. Fixed bug #68118 ($a->foo .= 'test'; can leave $a->foo undefined). (Nikita)
. Fixed bug #68129 (parse_url() - incomplete support for empty usernames
and passwords) (Tjerk)
diff --git a/main/getopt.c b/main/getopt.c
index a31a6c7..258173f 100644
--- a/main/getopt.c
+++ b/main/getopt.c
@@ -59,9 +59,17 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
{
static int optchr = 0;
static int dash = 0; /* have already seen the - */
+ static char **prev_optarg = NULL;
php_optidx = -1;
+ if(prev_optarg && prev_optarg != optarg) {
+ /* reset the state */
+ optchr = 0;
+ dash = 0;
+ }
+ prev_optarg = optarg;
+
if (*optind >= argc) {
return(EOF);
}