3 ms·
To be fair, religiously running Valgrind, Helgrind, Asan plus a static analyzer will probably do more than most compilers to ensure you don't have memory issues
by tsimionescu 4y ago
To be fair, religiously running Valgrind, Helgrind, Asan plus a static analyzer will probably do more than most compilers to ensure you don't have memory issues. Probably more than Rust, at least if you find yourself needing some unsafe blocks in your own code or dependencies.
- camel-cdr 4y agoIf you add to that the discipline of fuzzing, then you've actually got a pretty reasonable workflow. Fuzzing wasn't mentioned in the article but the author does at least to some extended in their project, from what I could tell at a glance.
- dopidopHN 4y agoSorry. I’m a JVM slob, what is fuzzing in that context of testing code rubustness?
- aw1621107 4y agoBroadly speaking, it's automated generation of test inputs to try to find bugs. For example, fuzzing a parser might involve feeding it random inputs and watching for crashes, hangs, etc. Fuzzers frequently also use instrumentation to try to figure out inputs that will hit more code paths in a more intelligent manner.
- andai 4y agoHere's a fun one: a fuzzer will generate valid JPEGs by starting with random input and mutating it to maximize code coverage. https://news.ycombinator.com/item?id=8571879 https://news.ycombinator.com/item?id=8571879
- gavinhoward 4y agoAuthor here. I fuzz religiously. I use it to generate lots of my test suite. I love fuzzing. I've added a note about it to the post.
- vlovich123 4y agoNothing is stopping you from running all of that on rust code though. In fact, you probably should just for sanity. Compilers have bugs. Libraries have bugs. At the lowest levels there’s unsafe somewhere anyway. Rust doesn’t remove the need for those things as good engineering practice. It just makes sure that the danger of failing to do so is minimized. Also, when there is a failure, it’ll be limited to very specific code paths (barring compiler bugs which themselves aren’t thaaat common all things considered).
- cyber_kinetist 4y agoDoes Rust stable support the commonly-used sanitizers (ASan, TSan, UBSan, etc.) though? The last time I've checked it was still a work in progress (https://github.com/rust-lang/rust/issues/39699 https://github.com/rust-lang/rust/issues/39699).
- vlovich123 4y agoIt’s not stabilized yet but it runs fine on x86_64. I don’t really see why it not being in stable is a huge blocker. It’s a bit inconvenient, but you can always rebuild your project with nightly, no?
- deleted 4y ago[deleted]
- tsimionescu 4y agoThat's beside the point. The OP was claiming that the article author is showing hubris, and I was just pointing out that, assuming their claims about what tools they use are all true, they are in fact showing more care than any project which relies only on the compiler and runtime system for memory safety.
- sprash 4y agoThis! If you really care about security you should educate people about how to use available tools to analyze C instead of relentless Rust evangelism. People arguing that "you can not ever write safe C" might also come to the conclusion that one "unsafe" somewhere in your Rust code potentially means that the whole code base is immediately at the same level of implicit memory safety as C.
- Lev1a 4y ago> People arguing that "you can not ever write safe C" might also come to the conclusion that one "unsafe" somewhere in your Rust code potentially means that the whole code base is immediately at the same level of implicit memory safety as C. No, the forced use of "unsafe" in Rust for some kinds of safety mechanisms to be disabled makes the code to audit easier to locate and reason about. IF the code in the "unsafe" block does not actually isolate the "unsafe"-ness THEN conclusions can be drawn about the rest of the code. Contrast that to C where the code introducing unsafeness, UB and unsoundness could be basically anywhere instead of a convenient "rg/grep unsafe" away.
- pjmlp 4y agoLint exists since 1979, eventually we have to accept those people don't want to be educated.
- tsimionescu 4y agoI don't agree at all. Developing in Rust (or other memory-safe or mostly-memory-safe languages) is going to be orders of magnitude easier than writing things in C and then running through several dynamic and static code analyzers and quieting the mountain of false positives you'll see with those, plus the massive test suite that you need to make any use of them. I was just pointing out that, in the case of the particularly diligent OP, he is probably getting an equivalent level of safety - for much more effort though.
- sprash 4y agoTo me writing C is orders of magnitude easier because I almost instantly can see in my mind the resulting assembly code generated by the C code. In comparison Rust feels very opaque (e.g. A simple writeln expands into a rather large macro and who knows what the compiler is doing with that). I'm sure with more experience you can get better but why bother. Even with just static analysis and some sane coding conventions you can get C on the same safety level of Rust. I see Rust as a huge waste of everybody's time and resources and far too opinionated in many regards.
- adrianN 4y agoMost of those tools check runtime properties of your code. If your test suite is perfect, that gets you quite far. I don't know of many nontrivial projects with perfect test suites.
- tsimionescu 4y agoWithout a good test suite, there are often security issues that don't depend on memory safety violations. Also, I did mention a static analyzer among the tools, which will likely be able to do analysis quite similar to the Rust borrow-checker (but with an order of magnitude more false positives, which the OP claims they are fixing anyway).
- gavinhoward 4y agoAuthor here. Not a perfect test suite, but the one for my bc [1] is pretty good. [1]: https://git.gavinhoward.com/gavin/bc https://git.gavinhoward.com/gavin/bc
- crabbone 4y agoThis only works if you don't stray too far away from the "typical" C. But a lot of large projects written in C will have tons of extensions and modifications making tools like Valgrind irrelevant. For instance, I worked in a company that rolled its own coroutines in a way very similar to how they work in Go on top of many other things they did to the language runtime. Valgrind couldn't "understand" what was happening in that runtime at all and if you tried to run it would spew millions of warnings (similar problem you'd have if you used Bohem GC with your C program). There was a way to "teach" Valgrind to understand what was going on in that runtime, but and even though we tried, at some point we realized that it would take too much effort to do so. I'd bet that OPs home-made alloca() would have a similar effect on Valgrind too.
- tsimionescu 4y agoAgreed completely. I was only trying to defend the article author from the accusation of hubris. If all of these tools are indeed used until they show no errors at all, not even false positives (as the article claims), and if the test suite used to run them is non-trivial, then they are likely far more secure than a typical program written in Rust or even something like Go or C# or Java (which all allow and internally use raw pointer manipulation for things like interop).