php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42982 FGETS Crash using FSOCKOPEN
Submitted: 2007-10-15 20:49 UTC Modified: 2009-04-21 14:43 UTC
From: mkz at terra dot com dot br Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.4 OS: Windows XP Professional
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: mkz at terra dot com dot br
New email:
PHP Version: OS:

 

 [2007-10-15 20:49 UTC] mkz at terra dot com dot br
Description:
------------
Fgets function cause a fatal error in script.

Reproduce code:
---------------
<?
class Smtp{
	//Creditos: Red neck adaptada por Micael Vianna (http://aiatola.net)
	
	var $conn;
	var $user;
	var $pass;
	var $html;
	var $debug = true;
	var $logado = false;
	var $erro;
	function Smtp($host,$porta){
	  $this->conn = fsockopen($host, $porta, $errno, $errstr, 30);
	  $this->Put("EHLO $host");
	}
	function Auth(){
	  $this->Put("AUTH LOGIN");
	  $this->Put(base64_encode($this->user));
	  $this->Put(base64_encode($this->pass));
	}
	function Send($toName, $to, $fromName, $from, $replyTo, $subject, $msg)
	{
	  if(isset($this->conn))
	  {
	  	// se nao estiver logado, loga
		if (!$this->logado)
		{
			$this->Auth();
			$this->logado = true;
		}
		$this->Put("MAIL FROM: <" . $from.">");
		$this->Put("RCPT TO: <" . $to.">");
		$this->Put("DATA");
		$this->Put($this->toHeader($toName."<".$to.">", $fromName."<".$from.">", $fromName."<".$replyTo.">", $subject));
		$this->Put("\r\n");
		$this->Put($msg);
		$this->Put(".");
		$i = 0;
		$dados = $this->conn; 	
	 }
	 else
	 	return false;
		while (!feof ($dados) || $this->conn) 
		{
			flush();
		    $buffer = fgets($this->conn, 4096);
		    
		}
	}
	
	function Put($value){
	  return fputs($this->conn, $value . "\r\n");
	  echo $this->conn;
	}
	function getRetorno($valor)
	{
    	return $valor{0}.$valor{1}.$valor{2};
	}
	function toHeader($to, $from, $replyTo, $subject){
	  $header  = "Message-Id: <". date('YmdHis').".". md5(microtime()).".". strtoupper($from) ."> \r\n";
	  $header .= "From: ". $from . " \r\n";
	  $header .= "To: ".$to." \r\n";
	  $header .= "Reply-To: ".$replyTo."\r\n";
	  $header .= "Subject: ".$subject." \r\n";
	  $header .= "Date: ". date('D, d M Y H:i:s O') ." \r\n";
	  $header .= "Content-Type: text/html; charset=iso-8859-1 \r\n";
	  $header .= "X-MSMail-Priority: High \r\n";
	  return $header;
	}
	function Close(){
	  $this->Put("QUIT");
	  return fclose($this->conn);
	}
	function getErro()
	{
		return $this->erro;
	}
}



	set_time_limit(10);
	require_once('../modulos/addons/smtp/class.smtp.php');
	$smtp = new Smtp("YOUR SMTP SERVER",25);
	$smtp->debug = false;
	$smtp->user = "YOUR SMTP USERNAME";
	$smtp->pass = "YOUR SMTP PASSWORD";
	if ($smtp->Send('micael','YOUR EMAIL','fulano','YOUR EMAIL','REPLY','Super promo&#65533;&#65533;o',"<html><body><table><tr><td>oi</td><td>tudo</td></tr></table></body></html>"))
		{ echo "ok"; }
	else
	{
		echo "ERRO".$smtp->getErro();
	}
	$smtp->Close();



?>

Expected result:
----------------
List all status from SMTP connect :)

Actual result:
--------------
Fatal error:  Maximum execution time of 10 seconds exceeded line 46

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-16 20:37 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 00:01:31 2024 UTC