Live data from Hacker News

C99 doesn't need function bodies, or 'VLAs are Turing complete'

lemon.rip

131–140 of 257 posts

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#131
post #117
post #107

Earlier quoted context omitted.

Yeah, right. https://msrc-blog.microsoft.com/2019/07/16/a-proactive-appro... https://research.google/pubs/pub46800/ https://support.apple.com/guide/security/memory-safe-iboot-i... Maybe you could give an helping hand to Microsoft, Apple and Google, they are in need of carefull C coders.

I'm not sure if you intentionally missed my point. Everything in C requires careful usage. VLAs aren't special: they're just yet another feature which must be used carefully, if used at all. Personally, I don't use them, but I don't find "they're unsafe" to be a convincing reason for why they shouldn't be included in the already-unsafe language. Saying they're unnecessary might be a better reason.

VLAs are unsafe in the worst kind of way as it is not possible to query when it is safe to use them. alloca() at least in theory can return null stack overflow, but there is no such provision with VLA.

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#132

Earlier quoted context omitted.

ah yes, why didn't I think of it, let me just try: #include #include __attribute__((annotate("realtime"))) void process_floats(std::span vec) { auto filter = (float*) malloc(sizeof(float) * vec.size()); /* fill filter with values */ for(int i = 0; i ) _Z14process_floatsSt4spanIfLm18446744073709551615EE ##The Deduction Chain: ##The Contradiction Reasons: - malloc : NonRealtime (Blacklist) - free : NonRealtime (Blackli…

Here's a nickel, kid. The bullshit about oh my embedded systems doesn't have dynamic memory is bullshit. You either know how big your stack is and how many elements there are, and you make the array that big. Or you don't know and you're fucked. You can't clever your way out of not knowing how big to make the array with magic stack fairy pretend dynamic memory. You can only fuck up. Is there room for 16 elements? The…

> You either know how big your stack is

that's in most systems I target a run-time property, not a compile-time one

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#133
post #82
post #38

Earlier quoted context omitted.

You can corrupt the stack without VLAs just fine. What else?

VLAs make it a lot easier to corrupt the stack by accident. Unless you're quite a careful coder, stuff like: f (size_t n) { char str[n]; leads to a possible exploit where the input is manipulated so n is large, causing a DoS attack (at best) or full exploit at worse. I'm not saying that banning VLAs solves every problem though. However the main reason we forbid VLAs in all our code is because thread stacks (particula…

> stuff like ... leads to a possible exploit where the input is manipulated so n is large

The same is true for most recursive calls, should recursion be also banned in programming languages?

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#134

This is only tangential to the article: C isn't Turing complete without `fseek` (as far as I can tell). Turing completes requires you to be able to read/write from an infinite tape (essentially infinite memory). This isn't possible in C, because `sizeof` is a constant expression, thus limiting the size of any type, and importantly also pointer type, to a finite number, thus making the addressable memory finite. From…

> This isn't possible in C, because `sizeof` is a constant expression, thus limiting the size of any type, and importantly also pointer type, to a finite number, thus making the addressable memory finite. Who said it had to be finite in theory ? `size_t` is defined in terms of the implementation, not in terms of bit-widths. Sure, size_t is finite in practice, but then again, so are all other programming languages. In…

`size_t` is defined as

> the unsigned integer type of the result of the sizeof operator (https://port70.net/~nsz/c/c11/n1570.html#7.19p2)

`sizeof` returns the following:

> If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant. (https://port70.net/~nsz/c/c11/n1570.html#6.5.3.4p2)

So `sizeof(size_t)` must be a concrete integer constant for any given C implementation, it can't change at runtime.

As far as I'm aware, there isn't an instance of an infinitely large integer, even in mathematics, there are finite integers and there is the concept of infinity.

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#135
post #96
post #82

Earlier quoted context omitted.

VLAs make it a lot easier to corrupt the stack by accident. Unless you're quite a careful coder, stuff like: f (size_t n) { char str[n]; leads to a possible exploit where the input is manipulated so n is large, causing a DoS attack (at best) or full exploit at worse. I'm not saying that banning VLAs solves every problem though. However the main reason we forbid VLAs in all our code is because thread stacks (particula…

You shouldn't be writing C if you're not a careful coder.

Too bad we have all that legacy C code that won't just reappear by itself on a safer language.

That means there are a lot of not careful enough developers (AKA, human ones) that will write a lot of C just because they need some change here or there.

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#136
post #101

I haven't thought about C in years - that one where author passes in a printf as a char array element and de-references it to execute it ... gives me chills. Y'all kids have fun - Im going to stick with my VM over here and call it a day. This makes even modern JS look sane by comparison. Excellent write up too.

> I haven't thought about C in years ... Im going to stick with my VM over here and call it a day. What's your VM written in?

Safe Rust.

https://deno.land/

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#137
post #108

Earlier quoted context omitted.

I like your comparison of a C programmer with a samurai.

Including that most of them end up doing Seppuku on their applications.

while we're hugging them from behind

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#138
post #6

Thanks to them being yet another attack vector and funny stuff like on this post, got demoted to optional on C11. Additionally Google spent several years paying to clean up the Linux kernel from all VLA occurrences. https://www.phoronix.com/news/Linux-Kills-The-VLA

>Thanks to them being yet another attack vector and funny stuff like on this post, got demoted to optional on C11. Sadly, the C committee doesn't really understand what was wrong with VLAs and a sizable group of its members wants to make them mandatory again: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2921.pdf ("Does WG14 want to make VLAs fully mandatory in C23")

> wants to make them mandatory again

What does 'mandatory' mean? Like if I write a C compiler without them... what are they going to do about it?

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#139

Earlier quoted context omitted.

>Thanks to them being yet another attack vector and funny stuff like on this post, got demoted to optional on C11. Sadly, the C committee doesn't really understand what was wrong with VLAs and a sizable group of its members wants to make them mandatory again: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2921.pdf ("Does WG14 want to make VLAs fully mandatory in C23")

> wants to make them mandatory again What does 'mandatory' mean? Like if I write a C compiler without them... what are they going to do about it?

Code that complies with the standard will be rejected by your compiler. The effect would probably be that few people would use your compiler.

Re: C99 doesn't need function bodies, or 'VLAs are Turing complete'

#140

Earlier quoted context omitted.

>Thanks to them being yet another attack vector and funny stuff like on this post, got demoted to optional on C11. Sadly, the C committee doesn't really understand what was wrong with VLAs and a sizable group of its members wants to make them mandatory again: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2921.pdf ("Does WG14 want to make VLAs fully mandatory in C23")

> wants to make them mandatory again What does 'mandatory' mean? Like if I write a C compiler without them... what are they going to do about it?

Most mainstream compilers aim to be standards compliant
Post reply on HN