News for hackers. Stuff that matters.
Re:CWE Top Most Dangerous Software Weaknesses by tumdum_ on Thursday July 13, 2023 @07:43AM (#36707701)
"But modern c++ is safe, preventing all those errors is as easy as not making them!..."
Re:CWE Top Most Dangerous Software Weaknesses by citrin_ru on Thursday July 13, 2023 @08:00AM (#36707851)
Is there some authoritative source for what is considered modern C++ and what is old? Most projects I've seen use a wide mix of C++ features of varying age. If you use some C++23 futures it would not make it modern if you still use C++98 features you not supposed to use.
Re:CWE Top Most Dangerous Software Weaknesses by tumdum_ on Thursday July 13, 2023 @08:23AM (#36708075)
No, there no such authoritative source - depending on context C++ fans will mix and match what is 'modern'.

It's somewhat similar to the C/C++ split. When it is convenient it's "C/C++" because "you can easily migrate your old C codebase to C++". But in other situations it's "C++", because C is old and more error prone and "we no longer manipulate raw pointers".

Re:CWE Top Most Dangerous Software Weaknesses by SubjectToChange on Thursday July 13, 2023 @08:13AM (#36707968)
“Modern C++” is not necessarily tied to any specific standard, it is more a collection of ideas and philosophies. Although if I had to pick I’d say it really started with C++11.
Re:CWE Top Most Dangerous Software Weaknesses by zabzonk on Thursday July 13, 2023 @08:06AM (#36707900)
not authoritative, but the really big c++ change was with c++11 - changes after that have been important, but perhaps more or less transparent to the average c++ user. and compiler support for c++11 is very good.
Re:CWE Top Most Dangerous Software Weaknesses by pjmlp on Thursday July 13, 2023 @09:18AM (#36708659)
Originally it refers to what was already possible in C++98, when one leaves behind the legacy ways of coding C with a C++ compiler.

Started with the publishing of "Modern C++ Design" from Andrei Alexandrescu in 2001.

https://en.wikipedia.org/wiki/Modern_C%2B%2B_Design

When ISO C++11 came to be, many re-used the term to mean C++11 or higher.

Given that many keep updating this to mean more modern versions, a well known developer in the community (Tony Van Eerd) has made the joke of that by C++17 time we were in Postmodern C++.

https://www.youtube.com/watch?v=QTLn3goa3A8

No idea what kind of modernism to call C++23, when C++17 was already postmodern, maybe Revivalist C++.

However it basically comes back to Andrei Alexandrescu's original ideas of programming in C++ as its own language, leave the C ways and pitfalls of resource management behind, learn to embrace a modern language for systems programming.

I should also note that there are developers against this philosophy, they advocate that the C++ as understood by CFront is what one should care about, thus Orthodox C++ movement was born.

https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b

Re:CWE Top Most Dangerous Software Weaknesses by tialaramex on Thursday July 13, 2023 @01:04PM (#36712474)
> programming in C++ as its own language, leave the C ways

I'm with Kate Gregory on the "Stop teaching C" (actually Kate specifically means in order to then teach C++ but I also think it's probably fine to stop teaching C outright)

But whilst Kate is right in terms of pedagogy, as a larger philosophy this is inadequate. As a language C++ is obviously defective and the explanation is almost invariably "Because C" which only makes sense once you appreciate C++ in terms of C.

The built-in array type in C++ is garbage. Why is it garbage? This is a language with all these powerful features, why doesn't its array type leverage any of them? It's because this is actually the array type from C.

OK, maybe just the array type is trash, that's obviously not good, but it's one defect. How about string literals. Oops. C++ does sort of technically have the string literals you actually wanted, but the syntax for them is weird and you need the standard library not the core language... the ones you get for "Some text" are C's constant strings, an array of bytes with an extra zero byte, and well, the array type sucks.

This carries on, the language doesn't provide real tuples, it doesn't provide a real sum type, its built-in types don't believe in methods but user types do, everywhere there are weird choices which are non-sensical except for the reality that it's what C does.

And then at the end of that, the language isn't actually compatible with C. It's close, a lot of stuff works, and more stuff kinda-sorta works enough that you may be surprised when it fails, but there isn't the sort of robust compatibility you might expect given the enormous sacrifices made for this goal.

Re:CWE Top Most Dangerous Software Weaknesses by pjmlp on Thursday July 13, 2023 @01:19PM (#36712717)
I mostly agree with you.

The issue is how "worse is better" culture tends to win, and if the option is between C and C++ for a given scenario, then I definitely take C++.

However if the option pool is widened to more alternatives, then yeah, there should be a sound reason for still pick them for greenfield development, e.g. CUDA, a language toolchain based on LLVM,...

Re:CWE Top Most Dangerous Software Weaknesses by littlestymaar on Thursday July 13, 2023 @07:51AM (#36707772)
In fairness, only 2 of those 4 are actually memory-related.
Re:CWE Top Most Dangerous Software Weaknesses by tialaramex on Thursday July 13, 2023 @08:16AM (#36707998)
I agree that in principle the neutralization bugs aren't something C++ is necessarily making worse than, say, Python. But it'd be fascinating to see a study to figure out whether C++ programmers make these mistakes more often, or less often, or roughly the same.

An argument for more often: C++ is so complicated, maybe you're too busy with other problems to address the neutralization issue

An argument for less often: C++ teaches you to be careful and check everything to avoid nasty outcomes so that carries over to neutralization

Re:CWE Top Most Dangerous Software Weaknesses by tumdum_ on Thursday July 13, 2023 @08:18AM (#36708021)
In fairness, only C/C++ of all the currently commonly used languages can have half of the 4 top dangerous software weaknesses.
Re:CWE Top Most Dangerous Software Weaknesses by littlestymaar on Thursday July 13, 2023 @11:29AM (#36710764)
JavaScript routinely has the other half of the top4.
Re:CWE Top Most Dangerous Software Weaknesses by tatersolid on Saturday July 15, 2023 @09:23AM (#36736501)
So do C and C++ when used in web or database applications. So they get 4/4
Re:CWE Top Most Dangerous Software Weaknesses by deadletters on Thursday July 13, 2023 @09:16AM (#36708648)
And both have existing tools to find those bugs that people often just don't use.
Re:CWE Top Most Dangerous Software Weaknesses by pjmlp on Thursday July 13, 2023 @09:21AM (#36708705)
Since 1979 with the invention of lint by Stephen Johnson at Bell Labs.

https://en.wikipedia.org/wiki/Lint_(software)

Re:CWE Top Most Dangerous Software Weaknesses by UncleMeat on Thursday July 13, 2023 @09:48AM (#36709076)
Static analysis as a bugfinding tool has proven to be insufficient, especially for large C++ binaries and JS programs. Both languages are nightmares for precise and scalable analysis.

Coverity exists. They've got a great product. But it doesn't solve the problem.

Re:CWE Top Most Dangerous Software Weaknesses by pjmlp on Thursday July 13, 2023 @09:50AM (#36709113)
It doesn't solve everything, it solves even less when it isn't used.
Re:CWE Top Most Dangerous Software Weaknesses by UncleMeat on Thursday July 13, 2023 @10:09AM (#36709407)
Of course. But these issues will remain near the top of the list indefinitely if people just leverage traditional analysis tools.

I love static analysis. I did my PhD in it. But we'll still be talking about use after free in 2073 if we just try to chase higher K in our analysis implementations.

Re:CWE Top Most Dangerous Software Weaknesses by pjmlp on Thursday July 13, 2023 @11:54AM (#36711265)
Naturally static analysis alone doesn't fix use after free in all possible cases, however it already does fix several of them when the analyser can see everything on the existing source code.

The main issue is the community sub-culture of not adopting tooling as it isn't perfect 100% of the time.

Many of the C++ security conscious folks end up being polyglot, as this subculture eventually wears one out.

Re:CWE Top Most Dangerous Software Weaknesses by UncleMeat on Thursday July 13, 2023 @10:16PM (#36718665)
Having spent well over a decade in this space, I assure you that the root cause of limitations for static analyzers doing lifetime analysis in C++ is not separate compilation or partial program analysis caused by shared libraries.
Re:CWE Top Most Dangerous Software Weaknesses by pjmlp on Friday July 14, 2023 @02:26AM (#36720157)
Naturally it isn't.

Again, even if not perfect, and doesn't cover all use cases, what about people would actually use something at all?

During that decade, how much time did you spent looking at the human side of the problem instead of what the tools can achive?

Re:CWE Top Most Dangerous Software Weaknesses by UncleMeat on Friday July 14, 2023 @08:48AM (#36723186)
Nowhere did I suggest that we shouldn’t use these tools or spend time improving them. UX for tools more powerful than local AST matching indeed tends to be quite bad because explaining the chain of reasoning for an alarm is difficult.

My only point is that without a different approach we will continue to have the same problems in 2073.