php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32324 socket_recvfrom stops reading at null char
Submitted: 2005-03-15 20:19 UTC Modified: 2005-03-24 01:00 UTC
From: admin at freeworldonline dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 4.3.10 OS: Linux stripples.devel.redhat.com
Private report: No CVE-ID: None
 [2005-03-15 20:19 UTC] admin at freeworldonline dot com
Description:
------------
I am trying to recieve data via a UDP socket using the socket_recvfrom function. It works fine unless there is a null char anywhere in the packet.

If there is the buffer returned only contains data up to that point, although the value returned by the function shows there is actually more data.

Reproduce code:
---------------
if (!$sock=socket_create(AF_INET,SOCK_DGRAM,SOL_UDP)) {
	echo "<b>Error:</b> Failed to create socket, ".socket_strerror(socket_last_error($sock))."<br>\n";
	} elseif (!socket_bind($sock,"0.0.0.0",41330)) {
	echo "<b>Error:</b> Failed to bind socket, ".socket_strerror(socket_last_error($sock))."<br>\n";
	socket_close($sock);
	} else {
	echo "<b>Ready, please send a message to port 41330 using UDP</b><br><br>\n";
	
	$size=socket_recvfrom($sock,$buf,65535,0,$clientIP,$clientPort);
	if ($buf===FALSE) {
		echo "<b>Error:</b> Returned false, ".socket_strerror(socket_last_error($sock))."<br>\n";
		} else {
		echo "Message from ".$clientIP.":".$clientPort." (".strlen($buf)."/".$size." bytes)...<br>\n";
		}
	
	socket_close($sock);
	}

Expected result:
----------------
All data to be placed into the buffer regardless of any null characters in the packet.

Actual result:
--------------
If you send a datagram to port 41330 while this is running with a null character mid way into the packet, any data from there onwards will not be placed into $buf.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-16 00:19 UTC] sniper@php.net
Please try using this CVS snapshot:

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

I can not reproduce this. I get only "Message from 127.0.0.1:52345 (363/363 bytes)..." 

 [2005-03-24 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC