python / python/cpython

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

オープン
#149,706 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Modules/socketmodule.c の AF_ALG に対する getsockaddrarg() の処理から始め、報告された strncpy 警告を調査してください。関連する CPython issue とリンクされている PR gh-150022 を確認し、そのうえで報告された GCC ビルドにより、ソケットの動作を変更せずに警告が解消されていることを検証してください。

索引モデルが issue の本文から書いたものです。

評価

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

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

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