Meditation, The Art of Exploitation

Thinking? At last I have discovered it--thought; this alone is inseparable from me. I am, I exist--that is certain. But for how long? For as long as I am thinking. For it could be, that were I totally to cease from thinking, I should totally cease to exist....I am, then, in the strict sense only a thing that thinks.

Friday, December 01, 2006

Be careful with openlog/syslog library calls


void foo(){
syslog(LOG_INFO, "logging from foo");

int main(void){
syslog(LOG_INFO, "logging from MAIN");

Ever wonder why sometimes syslog secretly sends logging message to the wrong facility behind your back? It appears openlog call has a process wide effect,


void openlog(const char *ident, int option, int facility);
void syslog(int priority, const char *format, ...);
void closelog(void);

Facility number can be changed at any place in the source code by a call to openlog. Any subsequent call to syslog will use the new facility number specified. In my opinion, it's a bad form of programming to use syslog directly in library code. Watch out for this bug when you use syslog.