Self-printing program (was Re: The Scope and Ownership of fedora-list)

Chris Tyler chris at tylers.info
Wed Aug 27 22:46:25 UTC 2008


On Wed, 2008-08-27 at 16:54 -0430, Patrick O'Callaghan wrote:
> On Wed, 2008-08-27 at 13:18 -0500, Mike Chambers wrote:
> > > p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
> > 
> > Not being a programmer or anything, WHAT in the heck IS that? LOL
> 
> It's C. There's a whole class of things like this. Google for
> "Obfuscated C Contest".
> 
> BTW it won't compile without a load of warnings. I can't be bothered
> working out how to turn them off.
> 
> poc

This is a short program of the type that Thompson described in
"Reflections on Trusting Trust"[0]. This version can be compiled with
gcc (with one warning):

        char* p="char* p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}

When run, it prints its own source code.

-Chris


[0] This is an amazing paper. It describes why you can't trust software
for which you have audited the source code and compiled your own binary.
Original PDF from the ACM site:
http://portal.acm.org/citation.cfm?id=358210 
or html format from Ken Thompson's site at Bell Labs:
http://cm.bell-labs.com/who/ken/trust.html




More information about the fedora-list mailing list