php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20023 Page Fault on Socket read
Submitted: 2002-10-22 05:27 UTC Modified: 2002-12-10 05:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sven dot schnitzke at t-online dot de Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.2.2 4.3 OS: Win 98 SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sven dot schnitzke at t-online dot de
New email:
PHP Version: OS:

 

 [2002-10-22 05:27 UTC] sven dot schnitzke at t-online dot de
I use this with PHP 4.2.2 Win executable version:

<?php
// set up listener and wait for clients
$listener = socket_create(AF_INET, SOCK_STREAM, 0);
socket_setopt($listener, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($listener, "0.0.0.0", 1234);
if (socket_listen($listener, 5);
$client = array();

// monitoring loop
while (true)
{
    $read[0] = $listener;
    // keep track of clients
    for ($i = 0; $i < MAX_CLIENTS; i++)
    {
        if ($client[$i] != null)
             $read[$i + 1] = $client[$i];
    }
    
    // watch for any socket activity
    $nready = socket_select($read, $null, $null, null);
    
    if (in_array($listener, $read))
    {
        // here we have a new client
        for ($i = 0; $i < MAX_CLIENTS; $i++)
        {
            if ($client[$i] == null)
            {    
                $client[$i] = socket_accept($listener);
                break;
            }
        }
        if (--$nready <= 0)
            continue;
    }

    // get data from socket(s) marked as active
    for ($i = 0; $i < MAX_CLIENTS; $i++)
    {
        if (in_array($client[$i], $read))
        {
            socket_getpeername($client[$i], $host, $port);
            $n = socket_read($client[$i], 16300);
            if (strlen($n) > 0)
                echo "rcv from $host:$port:$n\r\n";
            // else close and cleanup socket
        }
    }
}

This is, slightly modified, the example from the manual.

Everything works fine as long as I have well-behaved clients.
But if I for example try this against a telnet client and just close 
it without properly disconnecting before my script (by the way 
running in a dos box with php -f ... ) in turn 
dies with a page fault when getting to "socket_read".

I tried to have a look at "socket_last_error" after "socket_select" 
but that does not help since it says: 0. "socket_select" lets 
loose upon the killing of the client, putting the socket into 
the "$read" array. So I have to look at it...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-22 10:19 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip
 [2002-10-23 09:47 UTC] sven dot schnitzke at t-online dot de
I did as you suggested. But now it isn't working at all
anymore: as with 4.2.2 I can do everything up to (but not
including) entering a character into the telnet client.

doing socket_read or even an
echo(socket_strerror(socket_last_error($client[$i])));
upon recieving that character triggers a Page Fault in php4ts.
 [2002-10-24 01:55 UTC] sniper@php.net
you most likely didn't update PHP correctly.
Just make sure you first REMOVE all existing PHP related
binaries (dlls, etc.) and then install the new version.

 [2002-10-25 13:09 UTC] sven dot schnitzke at t-online dot de
I didn't update - I did a new parallel inst of 4.3 
obviously leading to some inst issues. These are covered
in another bug thread because they seem to be due to the
environmental diffences between CGI and module mode.

One thing is certain: 4.3 behaves different from 4.2.2
using the same inst strategy - I will try to sort it out.
Sven
 [2002-10-28 07:55 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-11-01 17:08 UTC] sven dot schnitzke at t-online dot de
I tried again with 4.3 Build Nov 1, 2002 16:12:01
and no luck:

socket_get_status complains over the result from 
socket_select stating that this is "not a valid stream 
resource", socket_last_error says: "0" and 
socket_get_peername knows about the correct ip and port.
Then comes socket_read and dies with a page fault in 
module <unknown> at 0000:00000003. This occurs either
upon entering a character in a telnet client on the
same machine or upon closing the connection from such
a client prior to entering anything from there. Killing
the telnet client results in a page fault in php4ts.

My installation is without any php related stuff in
%WINDIR% or %WINSYSDIR%, just a PATH set to the folder
containing the .EXE. I launch the script from a CLI
set to the folder of the .EXE with the command:
php -f "absolute path to script.php"
"extension_dir" is specified absolutely in php.ini and
the output of phpinfo() looks reasonable (sockets enabled
and path to extensions correctly specified).

A parallel inst of 4.2.2 running the same script can
read the characters from the telnet client and dies only
when the telnet client is killed without a correct shutdown
of the socket.
 [2002-11-07 11:07 UTC] sven dot schnitzke at t-online dot de
Addendum:
I got hold of a Windows Me system and installed PHP 4.2.2
and 4.3 on it with the following results:
My initial complaint regarding the page fault when a local
telnet is ripped off the socket is specific to the OS 
(perhaps the wsock32.dll ver? Win 98:4.10.1998 Me:4.90.3000)

On Win 98 it occurs with telnet 4.90.3000.1 and 5.00.1717.1
and on Me it does not occur at all. This is independent of 
the location of the telnet client, same or foreign machine.

Not so with PHP 4.3 CVS 1 Nov 16:12:01: 
Socket_read dies on Win Me with the same symtoms as on Win 
98. It also does not matter witch machine telnet is running on.
 [2002-12-09 09:23 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-12-10 05:29 UTC] sven dot schnitzke at t-online dot de
Hello "iliaa",
as it seems from first tests you have got this one!
I tried it on W98 SP2 with PHP4.4 2002-12-10 8:29
and  it doesn't crash any more. Thanks a lot! I will
also try on Win Me and stressing it soon. Sorry for
having been such a pain. Thanks again!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 09:01:29 2024 UTC