Heap buffer overflow: createClient() indexes clients[fd] with no bound on fd
まだ誰も着手していません。
評価
調査の方向性
smallchat-server.c の createClient(int fd) から始め、特に 84-86 行付近の clients[c->fd] へのアクセスを確認し、その後 j <= maxclient のループを調べます。報告されている AddressSanitizer コマンドでビルドし、同時接続で再現します。MAX_CLIENTS 以上のディスクリプタが範囲外アクセスなしで処理され、ループが clients 配列内に収まれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
clients[MAX_CLIENTS] (smallchat-server.c) is indexed directly by the socket file descriptor with no bound check before the write. When the kernel hands accept() a descriptor fd >= 1000 (MAX_CLIENTS), createClient() writes past the end of the heap-allocated chatState struct.
// smallchat-server.c:84 createClient(int fd)
assert(Chat->clients[c->fd] == NULL); // OOB READ when fd >= 1000 (assert, compiled out via -DNDEBUG)
Chat->clients[c->fd] = c; // OOB WRITE when fd >= 1000 -- heap overflow
clients[MAX_CLIENTS] is the last member of chatState (offset 8016 bytes), so clients[1000] writes exactly 8 bytes past the object.
Reachability
The kernel allocates the lowest free descriptor to accept(). A client holding ~997 concurrent connections (routine for a chat server, well under typical ulimit -n) makes the next accept() return fd = 1000 -> createClient(1000) -> the OOB write. No special payload, no race -- just connection count.
Verification (AddressSanitizer)
Built with gcc -fsanitize=address -fno-omit-frame-pointer -g smallchat-server.c chatlib.c -o sc-asan, then opened 1050 concurrent connections.
Release build (-DNDEBUG, assert compiled out) -- OOB WRITE:
ERROR: AddressSanitizer: heap-buffer-overflow on address 0xffff7cc02050
WRITE of size 8 ...
#0 in createClient smallchat-server.c:86
#1 in main smallchat-server.c:189
0xffff7cc02050 is located 0 bytes to the right of 8016-byte region
SUMMARY: AddressSanitizer: heap-buffer-overflow smallchat-server.c:86 in createClient
Suggested fix
if (fd >= MAX_CLIENTS) {
close(fd);
return NULL;
}
and guard the j <= maxclient loops with j < MAX_CLIENTS.
This report was produced with AI assistance (Claude, Anthropic) performing source analysis and building/running the ASan proof-of-concept described above.
- 主要言語
- C
- スター
- 7.5k
- フォーク
- 845
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
antirez/smallchat のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
antirez/smallchat の issue をすべて見る
似ている issue
-
Policy query leaks host primary block (BSL_PrimaryBlock_deinit skipped) on two early-exit pathsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NASA-AMMOS/BSL#355 ·
メンテナーはふだん 1 日以内に返信
-
#242 leftovers: dated narrative and shas in the social-features test plan対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
EchoTools/nevr-runtime#264 ·
メンテナーはふだん 1 日以内に返信
-
area/docdb kind/bug priority/medium status/awaiting-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
yugabyte/yugabyte-db#34873 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
category:port-update
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信