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

libast strcopy() should be removed #1149

Closed
krader1961 opened this issue Feb 2, 2019 · 3 comments
Closed

libast strcopy() should be removed #1149

krader1961 opened this issue Feb 2, 2019 · 3 comments
Assignees
Labels

Comments

@krader1961
Copy link
Contributor

As part of my ongoing efforts to remove code that isn't needed or problematic I recently noticed strcopy(). It's used in only 24 places and all of those should be using strlcpy() or an other appropriate function. The function is also unsafe for the same reasons that strcpy() is unsafe. There is no good reason to retain strcopy() so nuke it.

@krader1961 krader1961 self-assigned this Feb 2, 2019
@krader1961
Copy link
Contributor Author

Please note that this isn't about removing libast code just because it can be replaced with an alternative. It's about reducing the amount of complexity in the project. It's about reducing the number of patterns or interfaces someone has to be aware of when reading the code. It's about eliminating code that is almost certain to be slower than an equivalent API provided by the platform.

@krader1961
Copy link
Contributor Author

I'm going to resolve this in two steps. First, mechanically replace strcopy() with stpcpy() since they are equivalent. There are a handful of uses of stpcpy() that also need to be replaced by strlcpy(). Then replace stpcpy() with strlcpy().

@krader1961
Copy link
Contributor Author

I'm closing this because issue #956 is already open which notes that uses of stpcpy() should be replaced with strlcpy(). The problem is that the existing code makes that substitution pointless since it would involve pretending that the target buffer is of length SIZE_T_MAX. In other words, the existing data structures make it all but impossible to ensure that problems like buffer overruns can't happen. Fixing this state of affairs is going to be non-trivial.

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

No branches or pull requests

1 participant