Re: [patch] cat's main never return

2015-08-30 Thread Tobias Stoeckmann
On Sat, Aug 29, 2015 at 05:02:33PM -0600, Theo de Raadt wrote:
 It really does not matter.  Coder's choice.  The result is the same.
 You could hunt them all down, change them all, save a few code bytes,
 but don't you dare introduce any bugs...

The main function is called by crt0 like
exit(main(argc, argv, envp));

Which means that return 0; and exit(0); in main lead to the same
result.

But there is a subtle difference.

If main calls exit, its own stack protector will never be validated,
which means that a previous overflow of main's stack is not spotted.
return on the other hand would trigger the machine code to check.

I would prefer a proper return. Who knows if we spot an issue?  But on
the other hand, take Theo's statement into consideration:

 but don't you dare introduce any bugs...


Tobias



Re: [patch] cat's main never return

2015-08-29 Thread Joerg Sonnenberger
On Sun, Aug 30, 2015 at 12:10:03AM +0200, Fritjof Bornebusch wrote:
 If exit(3) is always called, than why not changing the return value to *void*?

Because ISO C says that in non-freestanding environment, main should
retutrn int.

Joerg



Re: [patch] cat's main never return

2015-08-29 Thread Theo de Raadt
 just saw that cat's *main* function does never return even though there is a 
 return value,
 exit(3) is called instead.
 Is there any reason why or is it just historically, cause it's a bit 
 confusing?
 If exit(3) is always called, than why not changing the return value to *void*?
 
 Other calls in *src/bin/* share the same behavior.

It really does not matter.  Coder's choice.  The result is the same.
You could hunt them all down, change them all, save a few code bytes,
but don't you dare introduce any bugs...