News for hackers. Stuff that matters.
Re:Top secure C++ coding practices by musicale on Wednesday March 16, 2022 @07:10PM (#30705334)
1. Don't use C++.
Re:Top secure C++ coding practices by olliej on Thursday March 17, 2022 @12:44AM (#30707749)
Not a useful comment, a better one /might/ be "don't write new software in c++."

But that said, C++ is safer than C.

This is a result of large and complex software developing features that require a large amount of manual and error prone code, whereas C++ can do the work for the developer, and will do it correctly everytime. Are there bad things in C++? of course. But you can avoid the known "bad" features - we can acknowledge things we originally thought would be good were in fact bad, and also recognize they need to remain due to old code - without throwing out all the good features.

Hence you get the "modern C++" subset that all serious large c++ projects use, which is not some horrific wasteland of bad code. Most security bugs that have been in C++ have been as a result of errors inherited from C and, unlike C, can be engineered out.

My suspicion is that the over-representation of C++ in vulnerability statistics is a product of the size of the major C++ codebases, the value of those targets, and the complexity of the products.

Re:Top secure C++ coding practices by api on Wednesday March 16, 2022 @08:27PM (#30706001)
This is correct.

What people often don't think about in the safe languages debate is that it's not about the skill of specific programmers. Yes, good programmers can write secure C or C++ code. That's not the problem.

The problem is what happens as code ages. What happens when bugs are fixed, refactors are done, code is ported to other platforms and OSes, multiple people work on it, and pull requests are merged. Bugs creep in when modifications are made without the full context, hastily, and by people who did not write the original code or when it was written so long ago that they've forgotten the deep details of it.

Safe languages will prevent, catch, or at least "nerf" the most dangerous sorts of bugs such as memory errors. Rust is very good at catching most of them at compile time. Unsafe languages won't and it's easy for bugs to creep in later and then result in catastrophic security failures long after they're released. Look at OpenSSL, a hoary old code base that continues to produce ugly security bugs.

Re:Top secure C++ coding practices by ridiculous_fish on Wednesday March 16, 2022 @09:10PM (#30706307)
Old codebases have a lot of baked-in institutional knowledge and bug fixes. A RiiR effort will introduce new bugs and reintroduce old ones, especially if done "without the full context, hastily, and by people who did not write the original code." Rewrites often fail.

MSFT, Google, Apple, Facebook all have a gazillion lines of C++ and it's not going away any time soon. "Don't use C++" is not practical advice for them and many other companies.

Re:Top secure C++ coding practices by pjmlp on Thursday March 17, 2022 @05:03AM (#30709053)
Microsoft Security Response Center official guidelines are:

1 - Use a managed language like C#, Java, Go if automatic memory management is ok

2 - Use a systems language like Rust if automatic memory management is not an option

3- Use C++ alongside Core Guidelines tooling.

Granted, not all Microsoft projects care about those guidelines.

Re:Top secure C++ coding practices by passivate on Wednesday March 16, 2022 @09:13PM (#30706325)
>Safe languages will prevent, catch, or at least "nerf" the most dangerous sorts of bugs such as memory errors

As a former C++ developer, errors leading to crashes (be it due to memory or otherwise) were always more preferable to me than logic errors or race conditions (which can still happen in Rust) that go unnoticed for months/years. I guess 'danger' here is subjective, but thats my view.

Re:Top secure C++ coding practices by api on Wednesday March 16, 2022 @09:57PM (#30706691)
How does catching crash bugs lead to more logic bugs? In practice I've never seen this.

In any case we're talking about security here where many crash bugs can in fact be catastrophic security vulnerabilities. If it crashes there's a distinct possibility that the bug is exploitable.

Re:Top secure C++ coding practices by passivate on Thursday March 17, 2022 @12:42AM (#30707736)
That is not quite what I said. I said I would take a crashing bug over a logic bug. Logic bugs are hard to find because you can't easily test for them. IME, Security vulnerabilities are primarily about functions assuming the input is safe (logic bugs), or file format parsing bugs (logic bugs) or the function being buggy to the point where the caller can poison the stack and/or control EIP. (logic bugs)

For each of these types there are some mitigations available at both the OS and hardware level, but I was making a general point about logic vs crashing bugs.

> If it crashes there's a distinct possibility that the bug is exploitable.

What I mean by crashing is that the program stops executing. Are you saying that crashing bugs make it easier to plant resident code? I'm nota security expert, so I don't quite know what you're referring to.

Re:Top secure C++ coding practices by pjmlp on Thursday March 17, 2022 @05:05AM (#30709067)
When C and C++ segfault we can be considered lucky that it happened, instead of corrupting data, that might even be stored somewhere else and go months unnoticed.
Re:Top secure C++ coding practices by 0xcde4c3db on Wednesday March 16, 2022 @08:49PM (#30706150)
In my experience, language selection is typically based on the overall ecosystem, not on any quality of the language itself. It takes an uncommonly opinionated team to pick anything other than the language whose ecosystem seems like it will let them ship with the least amount of hassle.
Re:Top secure C++ coding practices by anonymousDan on Wednesday March 16, 2022 @07:36PM (#30705565)
No idea why this is being downvoted.
Re:Top secure C++ coding practices by charcircuit on Wednesday March 16, 2022 @08:47PM (#30706142)
It's a useless dismissal of the article. It's equivalent to saying if you don't want to write any bugs, just don't write software. The advice is useless to someone who wants to make software even though it technically is true.
Re:Top secure C++ coding practices by ModernMech on Wednesday March 16, 2022 @09:24PM (#30706417)
I dunno, the first bullet point of the article is:

  Understand that there are no safety nets provided by the compiler or runtime while coding in C++.
I took the poster's comment to mean this bullet point is essentially saying "Don't use C++ if you really want to write secure software." If we've learned anything in the 35 or so years since C++ was introduced, it's that compilers and runtimes can do a great deal of good to help developers write secure software.

I mean, another reading of this article is that it's a list of the sharpest edges to watch out for in the C++ language, not a list of secure coding practices. The advice presented here boils down to "avoid these common bear traps and foot guns that are unhelpfully provided for you as part of you C++ starterpack." I think many reasonable people could easily conclude the same as the OP after reading this piece.

Re:Top secure C++ coding practices by gefhfffh on Wednesday March 16, 2022 @08:04PM (#30705826)
Jep. Secure C++ is no C++ - given you don't fall back to C or ASM, and consider safer alternatives