Skip to content

fix(ext/http): avoid misaligned sockaddr_in access in SocketAddr constructor - #4629

Open
Shubhammehta2008 wants to merge 3 commits into
open-telemetry:mainfrom
Shubhammehta2008:fix-socketaddr-misaligned-cast
Open

Shubhammehta2008 wants to merge 3 commits into
open-telemetry:mainfrom
Shubhammehta2008:fix-socketaddr-misaligned-cast

Conversation

@Shubhammehta2008

Copy link
Copy Markdown

Fixes #4307

Changes

Avoids undefined behavior caused by binding a sockaddr_in & to m_data through reinterpret_cast in the SocketAddr(u_long, uint16_t) constructor.

Following the existing pattern in SocketAddr(char const *) and port(), this initializes a clean stack-allocated struct sockaddr_in and copies it into m_data using memcpy.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@Shubhammehta2008
Shubhammehta2008 requested a review from a team as a code owner September 22, 2026 17:14
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Shubhammehta2008 / name: shubham mehta (0f208c6)

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch.

Please see comments, the proper fix is to use sockaddr_storage to represent a socket in an arbitrary protocol.

Other places using m_data may need some cleanup.

Comment thread ext/include/opentelemetry/ext/http/server/socket_tools.h Outdated
@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.53%. Comparing base (f77c1a5) to head (0f208c6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4629      +/-   ##
==========================================
+ Coverage   86.53%   86.53%   +0.01%     
==========================================
  Files         525      525              
  Lines       20475    20476       +1     
==========================================
+ Hits        17715    17716       +1     
  Misses       2760     2760              
Files with missing lines Coverage Δ
...clude/opentelemetry/ext/http/server/socket_tools.h 95.70% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SocketAddr(u_long, int) performs misaligned sockaddr_in access and truncates out-of-range ports

2 participants