Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Heap buffer overflow: createClient() indexes clients[fd] with no bound on fd

オープン 初心者向け
#59 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
security

調査の方向性

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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

antirez/smallchat のほかの issue

antirez/smallchat の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。