python / python/cpython

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

Open
#149,706 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules pending topic-socket type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Modules/socketmodule.c at the getsockaddrarg() handling for AF_ALG and inspect the reported strncpy warning. Review the related CPython issue and linked PR gh-150022, then verify with the reported GCC build that the warning is resolved without changing socket behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.