Skip to content

Coding - Dangerous use of 'cin'#681

Merged
dpasukhi merged 2 commits into
Open-Cascade-SAS:IRfrom
dpasukhi:cpp/dangerous-cin
Aug 17, 2025
Merged

Coding - Dangerous use of 'cin'#681
dpasukhi merged 2 commits into
Open-Cascade-SAS:IRfrom
dpasukhi:cpp/dangerous-cin

Conversation

@dpasukhi
Copy link
Copy Markdown
Member

Refactor input buffer allocation to use constexpr for improved readability and safety

Refactor input buffer allocation to use constexpr for improved readability and safety
@dpasukhi dpasukhi added this to the Release 8.0 milestone Aug 17, 2025
@dpasukhi dpasukhi requested a review from Copilot August 17, 2025 18:56
@dpasukhi dpasukhi self-assigned this Aug 17, 2025
@dpasukhi dpasukhi added 2. Enhancement New feature or request 1. Coding Coding rules, trivial changes and misprints labels Aug 17, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses security concerns with dangerous use of std::cin by refactoring input buffer allocation to use constexpr variables and setting stream width limits. The changes improve code safety by preventing potential buffer overflows when reading user input.

Key Changes

  • Replaced hardcoded buffer sizes with constexpr size_t aBufferSize constants
  • Added width() calls to input streams before reading to prevent buffer overflows
  • Applied consistent buffer size management across multiple input operations

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Draw/TKXSDRAWIGES/XSDRAWIGES/XSDRAWIGES.cxx Updated 4 instances of std::cin usage with constexpr buffer sizes and width limits
src/Draw/TKTopTest/GeometryTest/GeometryTest_ConstraintCommands.cxx Updated file input stream usage with constexpr buffer size and width limit
src/DataExchange/TKXSBase/IFSelect/IFSelect_Functions.cxx Updated std::cin usage with constexpr buffer size and width limit

Comment thread src/Draw/TKXSDRAWIGES/XSDRAWIGES/XSDRAWIGES.cxx
Comment thread src/Draw/TKXSDRAWIGES/XSDRAWIGES/XSDRAWIGES.cxx
Comment thread src/Draw/TKXSDRAWIGES/XSDRAWIGES/XSDRAWIGES.cxx
Comment thread src/Draw/TKTopTest/GeometryTest/GeometryTest_ConstraintCommands.cxx
@dpasukhi dpasukhi merged commit 5c814b0 into Open-Cascade-SAS:IR Aug 17, 2025
21 checks passed
@dpasukhi dpasukhi deleted the cpp/dangerous-cin branch August 17, 2025 20:03
@github-project-automation github-project-automation Bot moved this from Todo to Done in Maintenance Aug 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1. Coding Coding rules, trivial changes and misprints 2. Enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants