-Wstringop-truncation warning in socketmodule.c getsockaddrarg() for AF_ALG salg_name
未關閉
還沒有人認領這個 Issue。
extension-modules
pending
topic-socket
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
Building 3.14.5 with gcc 15.2 produces this warning:
default: ./Modules/socketmodule.c: In function ‘getsockaddrarg’:
default: ./Modules/socketmodule.c:2636:9: warning: ‘strncpy’ specified bound 64 equals destination size [-Wstringop-truncation]
default: 2636 | strncpy((char *)sa->salg_name, name, sizeof(sa->salg_name));
default: | ^
Build environment: Ubuntu 26.04 LTS, gcc 15.2.0, configure with
./configure --enable-optimizations --with-lto --enable-bolt --enable-safety --enable-slower-safety --with-system-expat CXX=/usr/bin/g++ CFLAGS="-flto=auto" LDFLAGS="-flto=auto"
This looks like a false positive. I see this location reported in https://github.com/python/cpython/issues/94536 and there is a fix for a similar warning here:
https://github.com/matthiasgoergens/cpython/commit/c1fdddcf0f7b31a5954163bfd299115b1fa7799b
Would the following be a good fix that mirrors that older one?
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy((char *)sa->salg_name, name, sizeof(sa->salg_name));
#pragma GCC diagnostic pop
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-150022
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Modules/socketmodule.c 中 getsockaddrarg() 對 AF_ALG 的處理開始,檢查回報的 strncpy 警告。檢視相關的 CPython issue 和連結的 PR gh-150022,然後使用回報的 GCC 建置進行驗證,確認警告已解決且未改變 socket 行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c
- 領域
- networking
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100