Live data from Hacker News

Let's Destroy C

gist.github.com

91–100 of 192 posts

Re: Let's Destroy C

#91
post #36

Perfect usage of the title to get on HN frontpage.

I really expected this to be another aggressive Rust marketing peice at first

Well, thanks to Rust's more powerful macro system, I'm sure someone could butcher it even more than the C-PreProcessor lets me do to C, here.

Re: Let's Destroy C

#92
post #65
post #64

Earlier quoted context omitted.

By that same logic, puts("Hello, world!"); is also vulnerable to DoS attack and information leak since someone could have removed the NUL terminator at the end of the string and have puts() read uninitialized/unmapped memory. Which is absurd logic.

Format string attacks have occurred in the wild. [0] > Originally thought harmless, format string exploits can be used to crash a program or to execute harmful code. They are not the same as puts. Puts can allow you to potentially read memory. A format string attack can allow you to write to memory. [0] https://en.wikipedia.org/wiki/Uncontrolled_format_string

So an attacker able to write to memory would be able to elevate into the ability to... write to memory. That doesn't sound particularly worrisome.

Re: Let's Destroy C

#93
post #72
post #57

Earlier quoted context omitted.

That's a format string attack [0]. By modifying the start of that string, you can begin reading and writing to various parts of the stack. Whilst implementations may inline that string into a RO memory region - that's not defined behaviour, so you shouldn't depend on it. [0] https://owasp.org/www-community/attacks/Format_string_attack

> By modifying the start of that string In order to modify that string, even in RW pages, the attacker already has to have access, at which point the point is moot. It's like saying "if you can change memory, then you can change memory"....

Agreed, if the attacker can modify string constants is,

    printf("Hello, World!\n");
really any safer than this?

    printf("%s\n", "Hello, World!");

Re: Let's Destroy C

#94
post #65
post #64

Earlier quoted context omitted.

By that same logic, puts("Hello, world!"); is also vulnerable to DoS attack and information leak since someone could have removed the NUL terminator at the end of the string and have puts() read uninitialized/unmapped memory. Which is absurd logic.

Format string attacks have occurred in the wild. [0] > Originally thought harmless, format string exploits can be used to crash a program or to execute harmful code. They are not the same as puts. Puts can allow you to potentially read memory. A format string attack can allow you to write to memory. [0] https://en.wikipedia.org/wiki/Uncontrolled_format_string

Yes if the attacker has control of the string (like if you do printf(getenv("FOO")) or something equally stupid).

Re: Let's Destroy C

#95
post #17

Earlier quoted context omitted.

Can you explain why?

On C language an expression which evaluates to any non-zero value is considered as True. So for example this kind of statement would not likely behave as intended: if (TRUE == expression) { ... }

I have refused to hire people who did this. (FALSE, too, even though it is safer.)

Re: Let's Destroy C

#96
This just in: you can write bad code in any language.

In this case, that language is the C Preprocessor, already well documented and widely accepted as a Bad Language To Start With.

The title of the article is misleading: it's not "destroying C" it's writing Bad Code using the C Preprocessor. It's not destroying C any more than a series of bad puns destroys the English language.

Re: Let's Destroy C

#97
post #57
post #54

Earlier quoted context omitted.

Can you please exemplify how you exploit a printf("Hello, World!\n") ?

That's a format string attack [0]. By modifying the start of that string, you can begin reading and writing to various parts of the stack. Whilst implementations may inline that string into a RO memory region - that's not defined behaviour, so you shouldn't depend on it. [0] https://owasp.org/www-community/attacks/Format_string_attack

It's also not defined whether the executable code is in RO memory or RW memory. By your argument, we should also be concerned that the attacker could modify the code directly.

Re: Let's Destroy C

#98
In some subtle way C was already "destroyed" with the introduction of C89. The K&R C had simplicity and beauty to it. Include files were small as they only contained the essential stuff (mostly definitions of structs). UNIX version 7 - the last "true" edition of UNIX - including its entire userspace - was still written in it. X Window system was written in it. Vi was written in it. Now all people do is complain.

Re: Let's Destroy C

#99

C has its place; every language has its quirks. I think a lot of emphasis needs to be put on testing code. Like SQLite uses Tcl to script tests. C is easy to test because the “software units” are only structures and functions.

> C has its place

No kidding.

Re: Let's Destroy C

#100

Earlier quoted context omitted.

Thanks, awesome paper (which remind me that I should read the ARM at some point). Interesting stuff: "Cfront [the fist c++ compiler] was (and is) a traditional compiler front− end performing a complete check of the syntax and semantics of the language" "[...] the C compiler is used as a code generator only. [...]. I stress this because there has been a long history of confusion about what Cfront was/is. It has been c…

I believe the "modern" term for Cfront would be "transpiler".

I think it could be called a "compiler" if C-- is anything to go by:

https://en.wikipedia.org/wiki/C--

> C-- (pronounced cee minus minus) is a C-like programming language. Its creators, functional programming researchers Simon Peyton Jones and Norman Ramsey, designed it to be generated mainly by compilers for very high-level languages rather than written by human programmers. Unlike many other intermediate languages, its representation is plain ASCII text, not bytecode or another binary format.[1][2]

> There are two main branches of C--. One is the original C-- branch, with the final version 2.0 released in May 2005.[3] The other is the Cmm fork actively used by the Glasgow Haskell Compiler as its intermediate representation.[4]

Post reply on HN