Fix buffer overflow in plot.cc: replace sprintf with snprintf#14
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix code scanning alert #370
Fix buffer overflow in plot.cc: replace sprintf with snprintf
Jul 18, 2026
Owner
|
Prefer to increase the buffer size to be large enough. |
highperformancecoder
requested changes
Jul 18, 2026
highperformancecoder
left a comment
Owner
There was a problem hiding this comment.
Please just increase the buffer size to be sufficiently large
Contributor
Author
Done — increased |
highperformancecoder
approved these changes
Jul 18, 2026
There was a problem hiding this comment.
Pull request overview
This PR aims to address a critical CodeQL buffer-overrun finding in src/plot.cc related to formatting log-axis labels into a fixed-size stack buffer.
Changes:
- Increased the stack buffer used by
logAxisLabel()from 30 bytes to 64 bytes insrc/plot.cc.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| string logAxisLabel(double x) | ||
| { | ||
| char label[30]; | ||
| char label[64]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CodeQL alert #370 (
cpp/overrunning-write, critical): twosprintfcalls insrc/plot.ccwrite into a 30-byte stack buffer with no size bound, risking overflow.Change
src/plot.cc— replace unboundedsprintfwithsnprintf(label, sizeof(label), ...)for both the Pango and fallback label formatting paths.The format string
"%d×10<sup>%d</sup>"can produce up to ~38 bytes (multi-byte UTF-8×, HTML tags, large integers) against a 30-byte buffer —snprintfcaps the write atsizeof(label).This change is