GoslingAllenLee / xmpphp

Automatically exported from code.google.com/p/xmpphp
0 stars 0 forks source link

XMLStream.php possible double closing socket on while loop #142

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Please see moodle tracker https://tracker.moodle.org/browse/MDL-28047

The problem exists on loop while on processUntill method,
It runs from disconnect method and don't check closed sockets, but it depents 
on disconnected variable which is set after loop and after throwed error.
1. I start here
        public function disconnect() {
                $this->log->log("Disconnecting...",  XMPPHP_Log::LEVEL_VERBOSE);
                if(false == (bool) $this->socket) {
                        return;
                }
                $this->reconnect = false;
                $this->send($this->stream_end);
                $this->sent_disconnect = true;
                $this->processUntil('end_stream', 5);
                $this->disconnected = true;
        }
2. It going to processUntil
                while(!$this->disconnected and $this->until_count[$event_key] < 1 and (time() - $start < $timeout or $timeout == -1)) {
                        $this->__process();
                }
3. Code crashes here $this->__process()
There are 2 independent fclose($this->socket); until there're time to 
reconnect, your code is trying to close 2 times same socket on while loop.

Please check on code was socket closed before.

if($this->socket !== NULL) {
   fclose($this->socket);
}

What version of the product are you using? On what operating system?

Affects Version/s: 2.1, 2.7.4, 2.7.5, 2.8.3
link to main moodle repository with your library 
https://github.com/moodle/moodle/tree/master/lib/jabber

Please apply ready patch in your original repository and further update can be 
done on moodle repository.

Thanks,
Michael (Michał) Hieronimczuk.

Original issue reported on code.google.com by michal.h...@zpsb.edu.pl on 24 Feb 2015 at 9:57

Attachments: