php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15772 PHP is developed and maintained by morons
Submitted: 2002-02-27 21:40 UTC Modified: 2002-03-05 09:29 UTC
From: jon+php at unequivocal dot co dot uk Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.6 OS: all
Private report: No CVE-ID: None
 [2002-02-27 21:40 UTC] jon+php at unequivocal dot co dot uk
Dear morons,

Please observe the following two lines from the 'fix' you have posted for your file-upload incompetence:

  loc = (char *) memchr(ptr, '\n', rem)+1;
  if (!loc) {

There's a bug in this code. Can you see what it is? Hint: the 'if' expression will never evaluate true. Well, that's assuming the first line doesn't crash since it invokes undefined behaviour.

Hint #2: the whole routine (not just those 2 lines) is still completely and utterly broken as of revision 1.71.2.2. It is riddled with code that reads beyond the end of the buffer.

Hint #3: yet again, you need to follow-up to your Bugtraq posting with a message saying 'Not only were we too stupid to write the code right in the first place, we were too stupid to fix it right too. Please ignore our previous patch. Please use this new one, which will probably be wrong also.'

HTH, HAND.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-27 22:55 UTC] rasmus@php.net
True, that bit of code made no sense and has been fixed.  The entire thing has been reworked for the 4.2 tree, but if you could expand on the muriad of buffer overflows aside from the memchr()+1 mixup, and submit a useful bug report it would be appreciated.
 [2002-02-27 23:20 UTC] jon+php at unequivocal dot co dot uk
It what way is it "fixed"? Every PHP user in the entire world is going to have to download the patches from www.php.net to fix the security hole, and those patches contain this bug. I know that it is fixed in CVS in that the entire file has been replaced, but as I understand it there is no fixed release version.

As to the other bugs, just look at the main while() loop in php_mime_split(). Pretty much every call to str* functions (including the very first one) are reading beyond the end of the buffer. If this happens, 'rem' may become negative and even more excitement ensues.
 [2002-02-27 23:34 UTC] rasmus@php.net
The specific memchr()+1 issue is fixed in CVS which was the only useful part of this bug report.  We close bugs when they are fixed in CVS, not when we ship releases.  
 [2002-02-27 23:42 UTC] jon+php at unequivocal dot co dot uk
Fine by me, but the problems are not fixed in CVS. You asked me for more specifics, I gave them to you.
 [2002-02-28 03:02 UTC] sesser@php.net
Your claims are simply wrong.

Not a single str* function is able to read beyond the
buffer, cause the buffer is '\0' terminated and
strcmp/strcasecmp whatever will stop there.

 [2002-02-28 03:21 UTC] yohgaki@php.net
We can search and fix what's wrong if there is a bug description, but it would nice if you could post patch to php-dev directly.  We know PHP has many bugs and appreciate patches fixes bugs.

You have skills, right :)

 [2002-02-28 04:59 UTC] jon+php at unequivocal dot co dot uk
I'll admit that I did not examine the rest of the program to see if the buffer was '\0'-terminated, however if it is, it's not just me that thought it wasn't - whoever wrote the routine thought it wasn't either. Otherwise there wouldn't even be any point in passing the buffer length to the function, or the main loop's "while (ptr - buf < cnt)" or indeed half the function.

As to providing patches, I know from experience that what you tend to do with them is ignore them, insult them, re-write them badly and apply them six months later, and then fail to credit. Plus I see no point in providing band-aids in a futile attempt to cover the gaping wounds in PHP. I *can* give you the fix I recommend to people for PHP, however, which is 'rm -rf php-*' ;-)
 [2002-02-28 05:06 UTC] sesser@php.net
You are again wrong, cnt must be supplied.
I advise you to think before you speak.

A POST fileupload block can have lots of '\0's in it.
Without the number of bytes it would be impossibe to
handle such a block.

 [2002-02-28 17:50 UTC] adrianc at e-smith dot com
How about this patch:

--- main/rfc1867.c.orig Thu Feb 28 14:08:25 2002
+++ main/rfc1867.c      Thu Feb 28 14:33:03 2002
@@ -163,20 +163,28 @@
                                                SAFE_RETURN;
                                        }
                                        /* some other headerfield found, skip it */
-                                       loc = (char *) memchr(ptr, '\n', rem)+1;
+                                       loc = (char *) memchr(ptr, '\n', rem);
                                        if (!loc) {
                                                /* broken */
                                                php_error(E_WARNING, "File Upload Mime headers garbled ptr: [%c%c%c%c%c]", *ptr, *(ptr + 1), *(ptr + 2), *(ptr
+ 3), *(ptr + 4));
                                                SAFE_RETURN;
                                        }
+                                       else
+                                       {
+                                           loc++;
+                                       }
                                        while (*loc == ' ' || *loc == '\t') {
                                                /* other field is folded, skip it */
-                                               loc = (char *) memchr(loc, '\n', rem-(loc-ptr))+1;
+                                               loc = (char *) memchr(loc, '\n', rem-(loc-ptr));
                                                if (!loc) {
                                                        /* broken */
                                                        php_error(E_WARNING, "File Upload Mime headers garbled ptr: [%c%c%c%c%c]", *ptr, *(ptr + 1), *(ptr +
2), *(ptr + 3), *(ptr + 4));
                                                        SAFE_RETURN;
                                                }
+                                               else
+                                               {
+                                                   loc++;
+                                               }
                                        }
                                        rem -= (loc - ptr);
                                        ptr = loc;
@@ -232,6 +240,10 @@
                                         * pre 4.0.6 code here
                                         */
                                        loc2 = memchr(loc + 1, '\n', rem);
+                                       if (!loc2) {
+                                               php_error(E_WARNING, "File Upload Mime headers - no newline");
+                                               SAFE_RETURN;
+                                       }
                                        rem -= (loc2 - ptr) + 1;
                                        ptr = loc2 + 1;
                                        /* is_arr_upload is true when name of file upload field
 [2002-03-01 07:03 UTC] jes at nl dot demon dot net
I have had a long look at rfc1867.c v 1.71.2.2 2002/02/21
from a download of php4.1.2 today (1 Mar 10:00 CET). There are a large number of dubious cases of handling of the buffer being processed. The following diffs address most of these (I believe). I am posting the patches to the php-dev list, since it's difficult if not impossible to create a properfly formatted diff in this edit window.
 [2002-03-02 15:56 UTC] heik at netcraft dot com
Fuck you ...php
 [2002-03-03 02:34 UTC] sesser@php.net
> Fuck you ...php

This posting is most probably a fake, cause there is
noone at heik@netcraft.com

And for the rest of the trolls:

The patch from jes@nl.demon.net will not be applied.
All his claims were as bogus as his patch.
He just added lots of redundant code. And the best:
In his patch every single variable is double freed.
You know how dangerous that is...

 [2002-03-04 12:22 UTC] unixach at ig dot com dot br
Folks, please, we need a working fix, stop bitching at each other.

Is the official response from the PHP team that "the fix is in CVS, so it is fixed"?
 [2002-03-05 07:12 UTC] assgoat at hotmail dot com
Would it be possible to post the IP addresses of the users of php.net?  Some would very much appreciate that.
 [2002-03-05 08:01 UTC] sesser@php.net
This would be a violation of (at least german) userdata protection laws.
 [2002-03-05 08:05 UTC] derick@php.net
Make that european...

Derick
 [2002-03-05 09:23 UTC] dan_york at mitel dot com
I note that 'adrianc@e-smith.com' submitted another patch that seems to fix the issue.  What about that patch?
 [2002-03-05 09:29 UTC] rasmus@php.net
The current patch fixes the exploit.  Yes, there is a memchr() crash bug left in it which is fixed in CVS, and the 4.2 code has been completely rewritten.  Basically the issue has been addressed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 21:01:31 2024 UTC