Skip to content

Fix unsafe string operations (sprintf, memcpy, strcpy)#1712

Closed
hobostay wants to merge 1 commit intosolvespace:masterfrom
hobostay:fix/unsafe-string-operations
Closed

Fix unsafe string operations (sprintf, memcpy, strcpy)#1712
hobostay wants to merge 1 commit intosolvespace:masterfrom
hobostay:fix/unsafe-string-operations

Conversation

@hobostay
Copy link
Copy Markdown

@hobostay hobostay commented Apr 2, 2026

Summary

This PR fixes potential buffer overflow vulnerabilities by replacing unsafe C string functions with safer alternatives:

Changes

  • src/textwin.cpp:

    • Replace 6 instances of sprintf with snprintf to prevent buffer overflows
    • Replace unsafe memcpy with properly bounds-checked strncpy for string copying
    • Fix 1 additional sprintf in character handling
  • src/textscreens.cpp:

    • Replace sprintf with snprintf with explicit buffer size
  • src/export.cpp:

    • Remove unnecessary strcpy by using direct initialization

Security Impact

These changes address potential buffer overflow vulnerabilities that could be triggered by specially crafted input or very large numerical values. Using snprintf and strncpy with explicit buffer sizes ensures that writes are bounded by the buffer size.

Testing

The changes are minimal and preserve the original functionality while adding safety bounds. The modified code handles:

  • Integer formatting with various precisions
  • String copying with proper null-termination
  • Character formatting

🤖 Generated with Claude Code

Replace unsafe sprintf with snprintf in textwin.cpp to prevent
potential buffer overflows. Replace unsafe memcpy with properly
bounds-checked strncpy. Replace sprintf with snprintf in
textscreens.cpp. Remove unnecessary strcpy in export.cpp.

These changes improve code security by using modern, safer alternatives
to traditional C string functions that are prone to buffer overflow
vulnerabilities.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@ruevs ruevs marked this pull request as draft April 2, 2026 11:34
@ruevs
Copy link
Copy Markdown
Member

ruevs commented Apr 2, 2026

Thank you. But no. For details why not see here #1361 - this has been submitted in the past.

@ruevs ruevs closed this Apr 2, 2026
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