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

Potential buffer overflow/truncation / null-terminated strings #284

Open
kamahen opened this issue Jul 11, 2024 · 2 comments
Open

Potential buffer overflow/truncation / null-terminated strings #284

kamahen opened this issue Jul 11, 2024 · 2 comments

Comments

@kamahen
Copy link

kamahen commented Jul 11, 2024

The compiler flagged a number of potential errors with the use of strncpy(), which have been fixed with #283.

However, there might be other such errors.
Also, null-terminated strings could introduce obscure bugs if any strings have embedded nulls (unlikely, but possible).
And the current code does its own buffer handling, re-allocating the buffers if needed when appending.

A better solution is to use std::string -- it handles buffer reallocation and also can handle nulls within strings.
Making this change would reduce the amount of code somewhat, which would reduce the probability of errors.

It would also probably help to change functions that pass char* parameters or return char* values (or update char** parameters). For public APIs, the existing char* ones could be preserved by adding equivalent std::string or const std::string& APIs.

If you wish some help with making these changes, please ask.

@kamahen
Copy link
Author

kamahen commented Jul 12, 2024

Here is one example of a potential bug that is fixed by using std::string: e77521a

@kamahen
Copy link
Author

kamahen commented Jul 12, 2024

Another potential bug that should have been fixed with std::vector: ba7742a (this was discovered by a compiler warning).

In general, most raw pointers in the code should be replaced by std::string, std::vector, std::unique_ptr, or local stack, as appropriate, which would simplify the code in many places (especially where the pointer is reallocated because a larger buffer is needed).

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

No branches or pull requests

1 participant