Skip to content

Fix CWE-134 format string vulnerability in netcomplexity.cc#16

Merged
highperformancecoder merged 2 commits into
masterfrom
copilot/fix-code-scanning-alerts-again
Jul 18, 2026
Merged

Fix CWE-134 format string vulnerability in netcomplexity.cc#16
highperformancecoder merged 2 commits into
masterfrom
copilot/fix-code-scanning-alerts-again

Conversation

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

strerror(errno) was being passed directly as the format argument to the error constructor (which calls vsnprintf), making it a non-constant format string. If strerror() ever returns a string containing % characters, this triggers undefined behavior and is potentially exploitable (CWE-134).

Changes

  • src/netcomplexity.cc — Replaced 8 occurrences of throw error(strerror(errno)) with an explicit format string:
// Before
throw error(strerror(errno));

// After
throw error("%s", strerror(errno));

This ensures the format argument is always a compile-time literal, with strerror()'s output treated purely as data.


This change is Reviewable

Copilot AI changed the title [WIP] Fix code scanning alert #405 Fix CWE-134 format string vulnerability in netcomplexity.cc Jul 18, 2026
@highperformancecoder
highperformancecoder marked this pull request as ready for review July 18, 2026 07:47
Copilot AI review requested due to automatic review settings July 18, 2026 07:47
@highperformancecoder
highperformancecoder merged commit e8d2007 into master Jul 18, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Addresses a potential CWE-134 format-string vulnerability by ensuring strerror(errno) is never used as a printf-style format string when constructing ecolab::error (which internally calls vsnprintf).

Changes:

  • Replaced throw error(strerror(errno)) with throw error("%s", strerror(errno)) in the affected error paths in src/netcomplexity.cc.
  • Ensured strerror() output is treated as data (string argument) rather than a format string.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/netcomplexity.cc
int pipes[2];
if (pipe(pipes)!=0)
throw error(strerror(errno));
throw error("%s", strerror(errno));
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.

3 participants