Heap buffer overflow: createClient() indexes clients[fd] with no bound on fd
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
Hướng nghiên cứu
Bắt đầu trong smallchat-server.c tại createClient(int fd), đặc biệt là các lần truy cập clients[c->fd] quanh dòng 84-86, sau đó kiểm tra các vòng lặp j <= maxclient. Biên dịch bằng lệnh AddressSanitizer được nêu và tái hiện lỗi với các kết nối đồng thời; được xem là hoàn thành khi các descriptor lớn hơn hoặc bằng MAX_CLIENTS được xử lý mà không có truy cập ngoài giới hạn và các vòng lặp vẫn nằm trong mảng clients.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C
- Star
- 7.5k
- Fork
- 843
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của antirez/smallchat
-
About Performance and TestingĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
-
How to compile on Windows.Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
How to use it? Read here.Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
Tất cả issue của antirez/smallchat
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
ly05010419/MacNativeGames#1340 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:stdlib bug found-by:cold-read kind:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
InauguralSystems/EigenScript#2197 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Hide the cursorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
seedds/nxnative#675 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 2 ngày