Re:Glibc getaddrinfo stack-based buffer overflow
by dbaupp on Tuesday February 16, 2016 @01:39PM
(#11112077)
> No I think he meant that if you adhere to certain language constructs the language is just as memory safe as Rust/others.
It's not; as soon as code uses (for instance) references, you're running the memory-unsafety gantlet. E.g. even something super-modern like
for (auto& thing: vector)
is risky: what if the loop body happens to somehow call `vector.push_back(x)`?
Re:Glibc getaddrinfo stack-based buffer overflow
by tomjakubowski on Tuesday February 16, 2016 @02:35PM
(#11112513)
> is risky: what if the loop body happens to somehow call `vector.push_back(x)`?
Some people like to say that these bugs are trivial to avoid ("who would write code like that?!"), but they miss the insidious (and common) case: when code several layers down the call stack (in some arbitrary callback assigned at runtime, say) grows the vector/map from under you.
Re:Glibc getaddrinfo stack-based buffer overflow
by kccqzy on Wednesday February 17, 2016 @02:44AM
(#11116063)
It's still easy to avoid though. Just take a const reference to the vector and use that in the loop and pass that to the callback. It just requires discipline, and in fact less discipline than writing C.
Eg. Don't use C++ as C with vectors, use C++ with the more modern language features:
It's the difference between:
Eg. Don't use C++ as C with vectors, use C++ with the more modern language features:It's the difference between:
Or alternatvily: In the first one you're 'protected' by the stl code, which is arguably the same level of protection as afforded by any memory safe language’s library code. Or alternatvily: In the first one you're 'protected' by the stl code, which is arguably the same level of protection as afforded by any memory safe language’s library code.