Skip to content

Commit 7b3dc69

Browse files
committed
Adding fsockopen to the list of Safe methods
1 parent 5687cf3 commit 7b3dc69

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

generated/functionsList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@
548548
'mysqlnd_qc_set_storage_handler',
549549
'closelog',
550550
'dns_get_record',
551+
'fsockopen',
551552
'getprotobyname',
552553
'getprotobynumber',
553554
'header_register_callback',

generated/network.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,65 @@ function dns_get_record(string $hostname, int $type = DNS_ANY, array &$authns =
253253
}
254254

255255

256+
/**
257+
* Initiates a socket connection to the resource specified by
258+
* hostname.
259+
*
260+
* PHP supports targets in the Internet and Unix domains as described in
261+
* . A list of supported transports can also be
262+
* retrieved using stream_get_transports.
263+
*
264+
* The socket will by default be opened in blocking mode. You can
265+
* switch it to non-blocking mode by using
266+
* stream_set_blocking.
267+
*
268+
* The function stream_socket_client is similar but
269+
* provides a richer set of options, including non-blocking connection and the
270+
* ability to provide a stream context.
271+
*
272+
* @param string $hostname If OpenSSL support is
273+
* installed, you may prefix the hostname
274+
* with either ssl:// or tls:// to
275+
* use an SSL or TLS client connection over TCP/IP to connect to the
276+
* remote host.
277+
* @param int $port The port number. This can be omitted and skipped with
278+
* -1 for transports that do not use ports, such as
279+
* unix://.
280+
* @param int $errno If provided, holds the system level error number that occurred in the
281+
* system-level connect() call.
282+
*
283+
* If the value returned in errno is
284+
* 0 and the function returned FALSE, it is an
285+
* indication that the error occurred before the
286+
* connect() call. This is most likely due to a
287+
* problem initializing the socket.
288+
* @param string $errstr The error message as a string.
289+
* @param float $timeout The connection timeout, in seconds.
290+
*
291+
* If you need to set a timeout for reading/writing data over the
292+
* socket, use stream_set_timeout, as the
293+
* timeout parameter to
294+
* fsockopen only applies while connecting the
295+
* socket.
296+
* @return resource fsockopen returns a file pointer which may be used
297+
* together with the other file functions (such as
298+
* fgets, fgetss,
299+
* fwrite, fclose, and
300+
* feof). If the call fails, it will return FALSE
301+
* @throws NetworkException
302+
*
303+
*/
304+
function fsockopen(string $hostname, int $port = -1, int &$errno = null, string &$errstr = null, float $timeout = null)
305+
{
306+
error_clear_last();
307+
$result = \fsockopen($hostname, $port, $errno, $errstr, $timeout);
308+
if ($result === false) {
309+
throw NetworkException::createFromPhpError();
310+
}
311+
return $result;
312+
}
313+
314+
256315
/**
257316
* getprotobyname returns the protocol number
258317
* associated with the protocol name as per

generator/src/DocPage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public function detectFalsyFunction(): bool
7777
if (preg_match('/&false;\s+if\s+the\s+number\s+of\s+elements\s+for\s+each\s+array\s+isn\'t\s+equal/m', $file)) {
7878
return true;
7979
}
80+
if (preg_match('/If\s+the\s+call\s+fails,\s+it\s+will\s+return\s+&false;/m', $file)) {
81+
return true;
82+
}
8083

8184
return false;
8285
}

generator/tests/DocPageTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function testDetectFalsyFunction() {
1414
$filesize = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/filesystem/functions/filesize.xml');
1515
$sessionRegister = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/session/functions/session-register.xml');
1616
$mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml');
17+
$fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml');
1718

1819
$this->assertTrue($pregMatch->detectFalsyFunction());
1920
$this->assertFalse($implode->detectFalsyFunction());
@@ -22,5 +23,6 @@ public function testDetectFalsyFunction() {
2223
$this->assertTrue($filesize->detectFalsyFunction());
2324
$this->assertFalse($sessionRegister->detectFalsyFunction());
2425
$this->assertTrue($mcryptDecrypt->detectFalsyFunction());
26+
$this->assertTrue($fsockopen->detectFalsyFunction());
2527
}
2628
}

rector-migrate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ services:
549549
mysqlnd_qc_set_storage_handler: 'Safe\mysqlnd_qc_set_storage_handler'
550550
closelog: 'Safe\closelog'
551551
dns_get_record: 'Safe\dns_get_record'
552+
fsockopen: 'Safe\fsockopen'
552553
getprotobyname: 'Safe\getprotobyname'
553554
getprotobynumber: 'Safe\getprotobynumber'
554555
header_register_callback: 'Safe\header_register_callback'

0 commit comments

Comments
 (0)