5 ms·
This is like saying there's nothing dangerous about guns, because it takes a human to make them dangerous. C is not unsafe if you only write safe code. But hum
by rhinoceraptor 7y ago
This is like saying there's nothing dangerous about guns, because it takes a human to make them dangerous.
C is not unsafe if you only write safe code. But humans are fallible, and "just don't write unsafe code" is not a solution.
- rumanator 7y ago> This is like saying there's nothing dangerous about guns, because it takes a human to make them dangerous. If you want to go with that analogy, UB is a kin of you intentionally pointing your gun to your foot, taking your time to aim it precisely on your foot, and in spite of all the possible warnings and error messages that are shouted at you... You still decide that yes, what you want to do is to shoot yourself in the foot because that is exactly what you want to achieve. And then complain about the consequences.
- masklinn 7y ago> If you want to go with that analogy, UB is a kin of you intentionally pointing your gun to your foot, taking your time to aim it precisely on your foot, and in spite of all the possible warnings and error messages that are shouted at you… Yeaaaah not really: #include <stdio.h> #include <stdlib.h> #include <string.h> static char a[128]; static char b[128]; int main(int argc, char *argv[]) { (void)argc; strcpy(a + atoi(argv[1]), "owned."); printf("%s\n", b); return 0; } compiles with no warning using clang (8), even with -Weverything And that’s a super easy case, it’s not a use after a dynamic callback somewhere freed a pointer it did not own, or a function 5 levels deep (or worse in a dll) didn’t check its input pointer which only became occasionally null years later.
- deleted 7y ago[deleted]
- saagarjha 7y agoAnd many (myself included) think that the compiler should not warn about this code, even if it can potentially exhibit undefined behavior, because it would make it impossible to write code at all without warnings. (A good static analyzer or code reviewer should call it out, though.)
- masklinn 7y agoThat's completely fair. I'm not criticising the compiler not complaining about this code, I'm providing a counter-point to rumanator's assertion that: > UB is a kin of you intentionally pointing your gun to your foot, taking your time to aim it precisely on your foot, and in spite of all the possible warnings and error messages that are shouted at you… Because they could hardly be more wrong, the average UB is completely invisible to static analysers because it's a dynamic condition which the type system is not smart enough to move to static. That's why it's an UB and not, say, a compile error.
- rhinoceraptor 7y agoOpenBSD has almost a singular focus on security, and even they have vulnerabilities. If they can't write safe C 100% of the time, what hope does anyone else have?
- yjftsjthsd-h 7y agoSo... Is there an OS with zero vulnerabilities written in Rust/Go/Ada/anything that I should know about? If nobody's written safe Rust/Go/Ada/whatever 100% of the time, what hope do I have? Now, I think that particular argument is poor. The more defensible version would be to look at the proportion of errors that occurred in C that would not occur in your language of choice, versus the number of errors that occur in this other language that would be unlikely to occur in C. And for completeness it would be good to do some sort of evaluation as to whether they were other gotchas like performance of the resulting code and programmer productivity. I expect that in the grand scheme of things, C is not the best option, but 100% perfection is an absurd goal post and makes it a lot easier for people to dismiss your argument.
- myrrlyn 7y agoRedox[0] actively wants to hear your vulnerability reports. [0]: https://www.redox-os.org/ https://www.redox-os.org/
- thesuperbigfrog 7y agoWhat hardware does it run on? I looked through the documentation and cannot find what hardware it runs on and how to set it up. The Getting Started for real hardware returns a 404 page: https://doc.redox-os.org/book/real_hardware.html https://doc.redox-os.org/book/real_hardware.html
- pjmlp 7y agoYes, Unisys ClearPath MCP, written in NEWP, a secure systems language 10 years older than C. It is still in use, because when governments want safety above anything else, they buy such OSes, not UNIX clones. https://www.unisys.com/offerings/clearpath-forward/clearpath-forward-products https://www.unisys.com/offerings/clearpath-forward/clearpath...