Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

library/3057: syslog(x, "%%m") does the wrong thing

From: <krh(at)lemniscate.net>
Date: Tue Dec 31 2002 - 20:42:21 EST


>Number: 3057
>Category: library
>Synopsis: syslog(x, "%%m") does the wrong thing
>Confidential: no
net
>Environment:
        

	System      : OpenBSD 3.2
	Architecture: OpenBSD.i386
	Machine     : i386

>Description:

syslog(3) lets the programmer use %m to indicate the current error, as determined by errno. However, it does not check that this percent is not part of some other format conversion (namely %%). So "%%m" does the wrong thing, e.g.:

Dec 31 17:00:27 gauss test3: 3485457128ndefined error: 0

>How-To-Repeat:

#include <stdio.h>
#include <sys/syslog.h>

int
main(void)
{

        syslog(LOG_DEBUG, "%%m");
}
>Fix:

This is against /usr/src/lib/libc/gen/syslog.c in 3.2. It should also work against -current. It is furthermore ugly, but it has been tested, and works. The program shown above now gives:

Dec 31 17:37:35 gauss test3: %m

as it should.

226,230c226,239

< 		if (ch == '%' && fmt[1] == 'm') {
< 			++fmt;
< 			if (data == &sdata) {
< 				prlen = snprintf(t, fmt_left, "%s",
< 				    strerror(saved_errno)); 
---

> if (ch == '%') {
> if (fmt[1] == 'm') {
> ++fmt;
> if (data == &sdata) {
> prlen = snprintf(t, fmt_left, "%s",
> strerror(saved_errno));
> } else {
> prlen = snprintf(t, fmt_left, "Error %d",
> saved_errno);
> }
> if (prlen >= fmt_left)
> prlen = fmt_left - 1;
> t += prlen;
> fmt_left -= prlen;
232,233c241,246 < prlen = snprintf(t, fmt_left, "Error %d", < saved_errno); ---
> if (fmt_left > 2) {
> *t++ = ch;
> *t++ = fmt[1];
> fmt_left -= 2;
> ++fmt;
> }
235,238d247 < if (prlen >= fmt_left) < prlen = fmt_left - 1; < t += prlen; < fmt_left -= prlen;
Do you need help?X

>Release-Note:
>Audit-Trail:
>Unformatted:

Received on Wed Jan 1 14:19:04 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:43 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library