python / python/cpython

-Wstringop-truncation warning in socketmodule.c getsockaddrarg() for AF_ALG salg_name

未关闭
#149,706 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。