C considered dangerous
lwn.net
C considered dangerous
1–10 of 66 posts
Re: C considered dangerous
#2Re: C considered dangerous
#3The title is completely misleading.
Re: C considered dangerous
#4The title is completely misleading.
Re: C considered dangerous
#5The title is completely misleading.
Kernel drivers and embedded system bare metal firmware.
The problem with C is that in any bigger project something always slips through even the best programmers, reviewers, static analysis and unit tests. And that something can lead to disastrous crashes and security vulnerabilities.
Re: C considered dangerous
#6I'm confused by this. The third argument provides the destination length, so what good would a "maximum destination length" do? I guess he must mean that because the length is often computed, you'd need a fourth argument to ensure the length isn't greater than some sane upper bound. But you can easily fix that using an if statement around the memcpy.
Re: C considered dangerous
#7The title is completely misleading.
I agree, it's very click-baity. C is actually great and is only really dangerous because it gives the programmer so much control.
Re: C considered dangerous
#8> He asked: why is there no argument to memcpy() to specify the maximum destination length? I'm confused by this. The third argument provides the destination length, so what good would a "maximum destination length" do? I guess he must mean that because the length is often computed, you'd need a fourth argument to ensure the length isn't greater than some sane upper bound. But you can easily fix that using an if stat…
Maybe memcpy_oobp (out of bounds protection) signature could be:
memcpy_oobp(void* dst, size_t dst_size, void* src, size_t src_size);
Then again, I guess you could just as well do: memcpy(dst, src, min(dst_size, src_size));
But having to explicitly specify both destination and source sizes might have prevented a lot of buffer overwrite bugs.Re: C considered dangerous
#9Re: C considered dangerous
#10The title is completely misleading.
I write a ton of C and I completely agree with the title. With 20+ years of experience. Kernel drivers and embedded system bare metal firmware. The problem with C is that in any bigger project something always slips through even the best programmers, reviewers, static analysis and unit tests. And that something can lead to disastrous crashes and security vulnerabilities.