Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using strncpy in InputText constructor #42

Open
coderabbitai bot opened this issue Jul 29, 2024 · 0 comments
Open

Avoid using strncpy in InputText constructor #42

coderabbitai bot opened this issue Jul 29, 2024 · 0 comments
Assignees

Comments

@coderabbitai
Copy link

coderabbitai bot commented Jul 29, 2024

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 library

InputText(ReactImgui* view, const int 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)

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

No branches or pull requests

1 participant