Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <trinity-b95d35ca-723c-4b6a-bd79-1edbb37dea1f-1718279080124@3c-app-gmx-bap17>
Date: Thu, 13 Jun 2024 13:44:40 +0200
From: erny hombre <hombre67@....at>
To: musl@...ts.openwall.com
Subject: possible bug in syslog

Hello,

I think there is a bug in syslog:

This assert fails (in gcc the test is ok):
	#if (LOG_MAKEPRI(LOG_DAEMON, LOG_WARNING) != (LOG_DAEMON|LOG_WARNING))
	#error "LOG_MAKEPRI"
	#endif

This code should produce a log message, but actually it does not:
	setlogmask(LOG_UPTO(LOG_NOTICE));
	syslog(LOG_MAKEPRI(LOG_LOCAL7, LOG_NOTICE), "LOG_MAKEPRI(LOG_LOCAL7, LOG_NOTICE)");
This works:
	syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_NOTICE), "LOG_MAKEPRI(LOG_DAEMON, LOG_NOTICE)");

---

Maybe these macros in syslog.h are wrong:
	#define	LOG_MAKEPRI(f, p) (((f)<<3)|(p))
	#define LOG_FACMASK 0x3f8
	#define LOG_FAC(p) (((p)&LOG_FACMASK)>>3)

correct version:
	#define	LOG_MAKEPRI(f, p) (((f))|(p))
	#define LOG_FACMASK 0xf8
	#define LOG_FAC(p) (((p)&LOG_FACMASK))

Also a line in syslog.c, __vsyslog() should be changed
from:
	if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return;
to:
	if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0xff)) return;

----
This is my testprogram to reproduce the error:

#include <syslog.h>

int main(void)
{
#if 1 // test ok
#if (LOG_FAC(LOG_MAKEPRI(LOG_DAEMON, LOG_WARNING)) != LOG_DAEMON)
#error "LOG_FAC"
#endif

#if 0 // test fails
#if (LOG_MAKEPRI(LOG_DAEMON, LOG_WARNING) != (LOG_DAEMON|LOG_WARNING))
#error "LOG_MAKEPRI"
#endif
#endif

	setlogmask(LOG_UPTO(LOG_NOTICE));

	openlog("exampleprog", LOG_CONS | LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_LOCAL1);

	syslog(LOG_DAEMON | LOG_NOTICE, "LOG_DAEMON | LOG_NOTICE");
	syslog(LOG_LOCAL7 | LOG_NOTICE, "LOG_LOCAL7 | LOG_NOTICE");
	syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_NOTICE), "LOG_MAKEPRI(LOG_DAEMON, LOG_NOTICE)");
	// the following call does not write a log message:
	syslog(LOG_MAKEPRI(LOG_LOCAL7, LOG_NOTICE), "LOG_MAKEPRI(LOG_LOCAL7, LOG_NOTICE)");

	closelog();

	return 0;
}
----

Regards
Erwin

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.