5 ms·
OpenBSD replaced strcat by strlcat, strcpy by strlcpy 20 years ago, in OpenBSD 2.4. They are implemented in the C libraries for OpenBSD, FreeBSD, NetBSD, Solar
by auslander 8y ago
OpenBSD replaced strcat by strlcat, strcpy by strlcpy 20 years ago, in OpenBSD 2.4.
They are implemented in the C libraries for OpenBSD, FreeBSD, NetBSD, Solaris, OS X, and QNX.
They have not been included in the GNU C library used by Linux.
- medecau 8y agoA few years ago I remember seeing strl* mentioned in a slide presentation for something that must have come from the oBSD camp. Since then I thought, not knowing any amount of C, that strl* was part of the language and available to all. Imagine if you will my confusion everytime I read people complaining about C being insecure. Your comment corrected my perception of this. Thank you.
- auslander 8y agoI admire the no-nonsense approach by OpenBSD: "The process we follow to increase security is simply a comprehensive file-by-file analysis of every critical software component. We are not so much looking for security holes, as we are looking for basic software bugs, and if years later someone discovers the problem used to be a security issue, and we fixed it because it was just a bug, well, all the better." https://www.openbsd.org/security.html https://www.openbsd.org/security.html I'm in DevOps field, and this 'make it right from the start' resonates strongly with me. Richard Feynman: Disregard others :)
- WalterBright 8y agoThose functions have a separate length parameter. There is no way to mechanically check that the length argument accurately reflects the length of the string. It's not an effective solution.
- pjmlp 8y agoWhich is the reason why I consider the C11 security annex, anything but safe.
- auslander 8y agoNot an expert, but shouldn't they have a length parameter, it makes sense?
- acehreli 8y agoI current C, yes, they should. The whole point is, the length parameter should not be separate from the array. It's even worse than that: the parameter is not an "array", it's a pointer to a single element. This whole thing relies on a convention and human attention; can't work in practice.
- grrrrrrrrrrrrr 8y agoAnd yet, it clearly does (work). When it doesn't (work), it is NOT because of a failure in the language; It is because C has (and always will have) the "basic philosophy that programmers know what they are doing;". Criticising C, is like criticising assembly. What's the point? If people want to criticise a programming language, then they should always start with C++, not C. C++ was designed to allow us to develop bigger and more complex programs, and yet, C++ inherited from C? How stupid was that! But people are happy to give out various awards and medals to the person who made one of the dumbest decisions ever made, in the whole history of computing! Leave C alone. It's fine. It's C++ that is the problem.
- auslander 8y agoWere OpenBSD people wrong, making strlcat and strlcpy ? Honest question.
- grrrrrrrrrrrrr 8y agoThat is a library issue. Trying to make C 'foolproof' however, is an excercise in futility, and in any case, can only come about by morphing it into a fundamentally different language. An argument in this thread, is that you shouldn't be able to pass an array without the argument being passed having some implicit 'size' element associated with it. That is NOT C. Conflating pointers with arrays, that is C. Again I feel the need to quote this: "C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly." If you don't know what you're doing, don't use C. C should be considered a 'specialist' language - much like doing brain surgery - if you're doing it, you better know what you're doing, else go be a GP or something. And, if you're project doesn't absolutely require that you use C, don't use it. Instead, use something that is more 'foolproof'. (and I don't mean C++!!!) D should focus less on being a better C, and more on being a replacement for C++. Then, I might take D more seriously. No attempt to morph C (i.e. the language, not the library) into something else will ever succeed. Leave C alone!
- auslander 8y agoWiki on subj: https://en.wikipedia.org/wiki/C_string_handling#Replacements https://en.wikipedia.org/wiki/C_string_handling#Replacements