C++ Software Security Sins: Basic Issues
cppstories.com
C++ Software Security Sins: Basic Issues
1–10 of 23 posts
Re: C++ Software Security Sins: Basic Issues
#2Re: C++ Software Security Sins: Basic Issues
#3No even vaguely competent C++ programmer uses arrays of char such as char a[26] - this is completely bogus.
Re: C++ Software Security Sins: Basic Issues
#4No even vaguely competent C++ programmer uses arrays of char such as char a[26] - this is completely bogus.
Re: C++ Software Security Sins: Basic Issues
#5No even vaguely competent C++ programmer uses arrays of char such as char a[26] - this is completely bogus.
Re: C++ Software Security Sins: Basic Issues
#6> Array new and delete
> When you write new in your applications, you are creating unmanaged objects, and you are then required to call delete later on if you don’t want to risk leaks. So don’t use new and delete at all, as this is considered a C++ bad practice. Better yet, working in modern C++ allows you to use smart pointers and Standard library container classes that make it easier to match every new with exactly one delete.
The text is reasonable, but why is the heading "array new and delete"? There is a difference between new/delete and new[]/delete[], and calling delete[] on something created by new or vice versa is indeed going to cause problems. But that problem (and hence the section title) is more or less orthogonal to what the section body talks about.
Edit: The corresponding slide in the presentation does talk specifically about this kind of mismatch. It also comes to the same conclusion as the text ("just use the STL"). The connection between title and body was apparently lost in translation.
Maybe as more general feedback, I'm getting a strange vibe from this blog. Lots of "top 5 " posts, links to Patreon-gated articles, ads for blog-owner-written books... Which would all be fine, but that plus an inconsistent summary of someone else's talk raises a lot of warning signs for me.
Re: C++ Software Security Sins: Basic Issues
#7No even vaguely competent C++ programmer uses arrays of char such as char a[26] - this is completely bogus.
Obviously it's bogus for the language to let you say you want an array of 26 chars and then treat that as a reasonable place to write an unknown number of characters, but that's a language fault.
Re: C++ Software Security Sins: Basic Issues
#8No even vaguely competent C++ programmer uses arrays of char such as char a[26] - this is completely bogus.
But why though? I mean, if I would like exactly 26 chars, this seems a nice way to get that. Even understanding that in C++ "char" is just a weirdly archaic way to say "byte" I might actually want that. Obviously it's bogus for the language to let you say you want an array of 26 chars and then treat that as a reasonable place to write an unknown number of characters, but that's a language fault.
Re: C++ Software Security Sins: Basic Issues
#9Earlier quoted context omitted.
But why though? I mean, if I would like exactly 26 chars, this seems a nice way to get that. Even understanding that in C++ "char" is just a weirdly archaic way to say "byte" I might actually want that. Obviously it's bogus for the language to let you say you want an array of 26 chars and then treat that as a reasonable place to write an unknown number of characters, but that's a language fault.
I'm guessing the reason is because `std::array ` gives you everything you'd want from `char[26]` but with more bells and whistles.
I mean, given what is intended in the examples is a string, obviously you should use an actual string. But if you want an array, you should be able to use an array for that, and it's silly that instead you're asked to use a substitute.
Re: C++ Software Security Sins: Basic Issues
#10Earlier quoted context omitted.
I'm guessing the reason is because `std::array ` gives you everything you'd want from `char[26]` but with more bells and whistles.
Sure, but that's a bug right? The language isn't able to give you those bells and whistles for its actual array type, so as a work around here's something else instead. Naming it "array" won't fool anybody when your language does have arrays already. I mean, given what is intended in the examples is a string, obviously you should use an actual string. But if you want an array, you should be able to use an array for t…
(1) https://github.com/microsoft/STL/blob/62137922ab168f8e23ec1a...