[comp.bugs.4bsd] Bug in syslog

bob@acornrc.UUCP (Bob Weissman) (01/08/88)

This one's been bothering me for some time.  syslog(3) does not
correctly do printf-style expansion of %-escapes, due to an
extraneous zeroing of a byte.

I'd been wanting to include 
	syslog(priority, "SU: %s %s\n", user, tty);
in su.c for a while, but it never seemed to work.  I finally got
around to looking at syslog today.

Of course, installing this fix means rebuilding the C library.  Sigh.

----------------------------------------
Repeat by:

#include <syslog.h>
main(argc,argv)
int argc;
char *argv[];
{
  syslog(atoi(argv[1]), argv[2], argv[3], argv[4]);
}

Compile and run with arguments 7, 'TEST: %s %s', X, Y.
The entire message does not make it into the syslog file.

----------------------------------------
Fix:

*** /usr/src/lib/libc/gen/syslog.c	Mon Jun 27 15:06:44 1983
--- ./syslog.c	Thu Jan  7 10:19:28 1988
***************
*** 70,76
  			}
  			c = *f++;
  			if (c != 'm') {
! 				*b++ = '%', *b++ = c, *b++ = '\0';
  				continue;
  			}
  			if ((unsigned)errno > sys_nerr)

--- 70,76 -----
  			}
  			c = *f++;
  			if (c != 'm') {
! 				*b++ = '%', *b++ = c;
  				continue;
  			}
  			if ((unsigned)errno > sys_nerr)

----------------------------------------

-- 
Bob Weissman
Internet:	bob@acornrc.UUCP
UUCP:		...!{ ames | decwrl | oliveb | apple }!acornrc!bob
Arpanet:	bob%acornrc.UUCP@AMES.ARPA