Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

fsockopen()/stream_socket_client() accept TCP ports above 65535, which wrap to another port

未關閉 適合新手
#24,616 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
c, php

研究方向

先閱讀 main/streams/xp_socket.c 中的 parse_ip_address_ex(),尤其是 issue 中提到的 atoi() 呼叫,並檢查其他地方(包括 parse_url())如何驗證 socket 連接埠。為連接埠號大於 65535 的 stream_socket_client() 和 fsockopen() 新增回歸測試。完成標準是兩者都拒絕無效連接埠,而不是連線到回繞後的連接埠。

由索引模型根據 Issue 內容生成。

描述

Description

A TCP port number above 65535 is not rejected by fsockopen() or stream_socket_client(): it wraps modulo 65536 and the connection goes to a different port. parse_ip_address_ex() in main/streams/xp_socket.c reads the port with atoi() and stores it without a range check.

The following code:

<?php
$srv = stream_socket_server("tcp://127.0.0.1:0");
$name = stream_socket_get_name($srv, false);
$port = (int)substr($name, strrpos($name, ':') + 1);

$c = stream_socket_client("tcp://127.0.0.1:" . ($port + 65536));
echo "asked for ", $port + 65536, ", connected to ", stream_socket_get_name($c, true), "\n";

$c2 = fsockopen("127.0.0.1", $port + 65536);
echo "fsockopen connected to ", stream_socket_get_name($c2, true), "\n";

Resulted in this output:

asked for 99735, connected to 127.0.0.1:34199
fsockopen connected to 127.0.0.1:34199

But I expected this output instead: both calls fail with an invalid port error, since 99735 is not a valid TCP port (parse_url() already rejects such ports).

Reproduced on 8.2.34-dev (512c04e39f) and 8.4.28-dev; master has the same atoi() calls (xp_socket.c lines 654 and 664).

This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.

PHP Version
PHP 8.4.28-dev, PHP 8.2.34-dev
Operating System

Linux (Ubuntu 20.04, x86_64)

主要語言
C
星號
40.7k
分支
8.3k
平均合併
2 天 15 小時
30 天內合併 PR
155

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。