Skip to content

Avoid using strncpy in InputText constructor #42

Description

@coderabbitai

The constructor in the InputText class uses strncpy, which can lead to buffer overflows. Consider using std::copy from the <algorithm> library to safely copy the string and ensure null termination.

Relevant code snippet:

#include<algorithm>// Include the algorithm libraryInputText(ReactImgui* view, constint id, const std::string& defaultValue, const std::string& label, std::optional<BaseStyle>& style) : StyledWidget(view, id, style) {
m_type = "InputText";
m_bufferPointer = std::make_unique<char[]>(100);
m_defaultValue = defaultValue;
m_label = label;
if (!defaultValue.empty()) {
std::copy(defaultValue.c_str(), defaultValue.c_str() + std::min(defaultValue.size(), size_t(99)), m_bufferPointer.get());
m_bufferPointer[std::min(defaultValue.size(), size_t(99))] = '\0'; // Ensure null termination
}
}

References:

PR URL: #41
Comment URL: #41 (comment)

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions