15 ms·
If you are really worried about the security of old C code, then the safest, most portable thing to do is re-write in modern C++. This is sane and doable in a s
by w8rbt 9y ago
If you are really worried about the security of old C code, then the safest, most portable thing to do is re-write in modern C++. This is sane and doable in a short period of time. Rust is not.
- strictfp 9y agoWhy not Rust? Given that you aren't very familiar with niether C++ nor Rust, I'm not convinced that C++ is saner or faster.
- sebcat 9y agoOr just rewrite it in modern C. This is sane and doable in a short period of time. You just have to make sure it's modern C. (no true Scotsman)
- camus2 9y ago> Or just rewrite it in modern C. This is sane and doable in a short period of time. What do you call modern C?
- sebcat 9y agoWell, anything that does not support the point I am making is not modern C.
- knicholes 9y agoI think his comment was facetious. I think the clue is "no true scotsman," which is a type of fallacy. I think the point is that it's assumed to be better because of the use of "modern," and that it's only valuable if it's rewritten in something modern. Perhaps it's a joke about how old code is actually fine, and that people who get excited about the cutting-edge technology could chill a little bit. Maybe it's just a mockery of the previous arguments.
- adwhit 9y agoNo true Scotsman: "We found a terrifying vulnerability in your codebase. You should rewrite it in modern C++." "OK, done!" <Time passes> "We found a terrifying vulnerability in your codebase. It must not have been modern C++!"
- hashmal 9y agosame question applies to C++. every new version of C++ is the modern version for a while…
- kreetx 9y agoIsn't Go pretty much the modern C, with additions in concurrency?
- trimbo 9y agoIt's garbage collected. So, no.
- treehau5 9y agoNo, not really. Go left a lot of C behind (pointer arithmetic for example), while also being garbage collected and having modules instead of header files. Coincidentally, while being touted as replacement for C and as the "language of the server", most of its converts come from python, ruby, and node.js evironments.
- w8rbt 9y agoPerhaps he means C11? The most recent standard (ISO/IEC 9899:2011). https://en.wikipedia.org/wiki/C11_(C_standard_revision) https://en.wikipedia.org/wiki/C11_(C_standard_revision)
- akavel 9y agoOh no, no, no! Some people may reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly. (See maybe SQLite. Seen as one of the pinnacles of crazy pedantism in C. Also, see the article about errors found recently in SQLite with fuzzing!) But with C++, it's just impossible for a human. It's too big, too quirky, too big, too wide, too deep, too tricky, too big, too complicated, and also too huge. And purposefully (sic! for performance) sprinkled with UB, which means barbed fences, trip-wire mines (to boost your in-flight performance), and hidden pit traps. Writing C++ code longer than a few lines without UB is humanly impossible. Sorry. And that's just about UB, because it's the most unpredictable thing; but there's still exception safety, for example, which you also should be doing, which can "only" spoil your code's logic (and then, obviously, go on writing over random memory, but that's nothing uncommon for us C++ers). Is every line of your C++ codebase exception safe? Yeah, sure. Good luck. And "modern C++" only means more C++. Because backwards compatibility. Unless at some point some quest for a "safe subset of C++" finally gains traction, which may maybe bring back some sanity. I do really hope for that. A personal opinion from a person who loved C++ for quite some time, before diving deep enough to realize how dark is the abyss.
- lj3 9y ago> Oh no, no, no! Some people may reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly. Why the sarcasm?
- akavel 9y agoI'm afraid I was not being sarcastic. Sorry. This is a totally honest and dead serious opinion from a long time C & C++ user. ("stars aligning" here means "you must also have luck". As I said: see SQLite.)
- FRex 9y agoThen just delete your entire OS or at least your browser, don't force yourself to use C and C++ software. Seriously. I'll let you keep LLVM so you can play with Rust. There's disliking language or the boilerplate it forces on the programmer which I can REALLY understand in case of these two and there's being a jerk and an idiot and saying any C++ program that isn't few lines is broken by the UB, you need stars aligning to write safe C, they are impossible to write anything substantial, safe and useful in, etc. and anyone who tells you otherwise is implicitly a very bad programmer who does their job wrong and endangers people.
- moomin 9y agoFastest to develop, yes. Portable, yes. Safest? Well, only in as much most of the errors will be blamed on the programmer for not doing the correct modern C++. I mean, seriously, understanding the borrow checker is nowhere near as hard as understanding this: https://akrzemi1.wordpress.com/2013/10/10/too-perfect-forwarding/ https://akrzemi1.wordpress.com/2013/10/10/too-perfect-forwar... There's a No True Scotsman aspect to C++ advocacy. Anything that is obviously dumb either is because the programmer did it wrong, because it belongs to the ever-growing list of features you avoid or "doesn't come up that often".
- _ph_ 9y agoAs long as it possible to run the same old C code inside your "modern C++" rewrite, you might have ported the security holes to C++. The problem is, C++ is far to compatible to C here. The idea of all "safe" modern languages is, that unsafe constructs are simply not allowed by the compiler. Why not let the compiler do the checking work vs. hoping that the human programmer didn't miss a check?