Skip to content

fix(monitor): chặn cận độ dài khi ghi nhật ký socket chuột, bản dựng hết cảnh báo - #493

Open
nguyenphivn wants to merge 1 commit into
LotusInputMethod:devfrom
nguyenphivn:fix/mouse-socket-log-bound
Open

fix(monitor): chặn cận độ dài khi ghi nhật ký socket chuột, bản dựng hết cảnh báo#493
nguyenphivn wants to merge 1 commit into
LotusInputMethod:devfrom
nguyenphivn:fix/mouse-socket-log-bound

Conversation

@nguyenphivn

Copy link
Copy Markdown
Contributor

Dựng dev bằng GCC 16 thì cả bản dựng chỉ còn đúng một cảnh báo, và đây là nó:

char_traits.h:432:56: warning: '__builtin_memcpy' accessing between
9223372036854775760 and 9223372036854775806 bytes ... [-Wrestrict]
inlined from 'void mousePressResetThread()' at src/lotus-monitor.cpp:113

Không phải lỗi đọc tràn thật. n là giá trị recv trả về với đệm 16 byte, và nhánh n <= 0 đã break ở trên, nên tới dòng đó n chắc chắn nằm trong [1, sizeof(buf)]. Chỉ là GCC không chứng minh được cận trên nên nó giả định ssize_t có thể vọt lên cỡ size_t.

Chặn cận làm điều kiện đó thành tường minh, và bản dựng sạch cảnh báo.

Mình nghĩ đáng sửa vì nó là cảnh báo cuối cùng còn lại: một cảnh báo lúc nào cũng hiện sẽ tập cho người ta quen mắt lướt qua, rồi cảnh báo thật sau này cũng bị lướt qua luôn.

ctest 9/9.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TvNe693ge85eB4QPs6hpjV

…ng-free

Building dev with GCC 16 emits one warning, and this is it:

  char_traits.h:432:56: warning: '__builtin_memcpy' accessing between
  9223372036854775760 and 9223372036854775806 bytes ... [-Wrestrict]
  inlined from 'void mousePressResetThread()' at src/lotus-monitor.cpp:113

Not a real out-of-bounds read: n comes from recv() into a 16-byte buffer and the
n <= 0 case has already returned, so n is in [1, sizeof(buf)] at that point. GCC
cannot prove the upper bound, so it assumes the ssize_t could reach size_t range.

Clamping the length makes the bound explicit and the build clean. Worth doing
because it was the only warning left: one that always shows is one that trains
you to skim past the next warning, which may be real.

ctest 9/9.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TvNe693ge85eB4QPs6hpjV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant