3 ms·
Sounds a lot like Theo is making the assumption that most programmers care about security, when in fact, they're probably primarily interested in creating code
by peterwwillis 13y ago
Sounds a lot like Theo is making the assumption that most programmers care about security, when in fact, they're probably primarily interested in creating code that works, and making it secure later.
It doesn't matter what function you use to copy strings. Hell, you can use strcpy in a way that avoids buffer overflows! If your application is poorly designed, it will be insecure. In this case what we're talking is not doing bounds checking on input before copying data, which will always end up fucking you in one way or another, regardless of what function you use.
Going on and on over this function vs that function is a distraction from the bigger problem, which is the overall poor design of many applications.
- clarry 13y ago> Theo is making the assumption that most programmers care about security, when in fact, they're probably primarily interested in creating code that works, and making it secure later. Insecure software is broken software; it doesn't work correctly (unless insecurity is an intended feature, such as in a backdoor). > It doesn't matter what function you use to copy strings. Technically you're right, you can even roll your own loop. However, the purpose of library functions is to make your (and your users' & co-developers') life easier. The strl* functions provide a simple idiom that just works, and it takes less effort than doing arithmetic prior to strcpy/cat calls. It makes it easy for everyone to check that it does indeed work. > In this case what we're talking is not doing bounds checking on input before copying data, which will always end up fucking you in one way or another, regardless of what function you use. The strl* functions are all about doing bounds checking in a simple and compact way while copying data, and they inform you in case the input was too large. They're all about replacing broken (or entirely missing!) hand-rolled bounds checking that you'd write before every strcpy/strcat. Why don't you try audit code that uses strlcat & strlcpy? Grep for these and check that every invocation is correct. Now do the same for code using strcat, strncpy, and strcpy. Check all the arithmetic (which may take up goodness knows how many lines, spread all over the place, in loops, etc.). After a few hundred of these, you should begin to understand why strlcpy and strlcat exist. People have done such massive audits before. And misuse of the standard string functions has indeed caused many many bugs. The secure alternatives weren't invented just for the heck of it; there's actual history behind it.
- peterwwillis 13y agoYes, I understand why these functions exist. That's my whole point: we shouldn't be nit-picking these functions in regards to security, because simply using them does not make your program secure. You have to actually design for security, not just use strlcpy and believe somehow you have produced secure code. At the same time, just because someone has strcpy in their code, does not mean their code is not secure. So this whole discussion is pointless, is what i'm saying :)
- clarry 13y agoYes it's pointless if people continue to miss the point regarding auditability, and the fact that harder-to-use functions that are also harder to audit are more like to end up used wrong. I realize that many out here don't care about auditability, and never spend hours systematically going through hundreds or thousands of invocations in other people's code, checking for correctness of exactly the kind of code that historically has caused lots of easy-to-exploit security problems. I realize that most people here would probably trust themselves to be able to use strcpy, strncpy, and strcat correctly; I would trust myself too. But that is not the point. With the right idioms, I make it easier for other people to verify the correctness of my code, so they don't need to depend on blind trust. And to be honest, it doesn't take a whole lot of "design" to use strlcat correctly; it is simple. Yes you can misuse it, but I would hold it very likely that most people who actually learn about it, check the manual, and decide to use it, are going to use it correctly.
- peterwwillis 13y ago> I would hold it very likely that most people who actually learn about it, check the manual, and decide to use it, are going to use it correctly. You don't think that's dangerous? If your method of auditing code is skipping all the strlcpy's because you assume it's being used correctly, you're going to miss the one or two times it's not, and end up with vulnerabilities. I haven't needed to audit code professionally, but when I do it personally, I don't look for common pitfalls in function use - I look for general scenarios that are dangerous, like working with potentially tainted data. So when I talk about design security, I don't mean what function you use, I mean how it fits into the broader scheme of what the application is trying to do.