From: erny hombre <hombre67@gmx.at>
To: musl@lists.openwall.com
Subject: [musl] possible bug in syslog
Date: Thu, 13 Jun 2024 13:44:40 +0200 [thread overview]
Message-ID: <trinity-b95d35ca-723c-4b6a-bd79-1edbb37dea1f-1718279080124@3c-app-gmx-bap17> (raw)
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
next reply other threads:[~2024-06-13 12:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-13 11:44 erny hombre [this message]
2024-06-13 13:46 ` Rich Felker
2024-06-13 15:20 ` Thorsten Glaser
2024-06-13 15:37 ` Rich Felker
2024-06-13 15:44 ` Thorsten Glaser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-b95d35ca-723c-4b6a-bd79-1edbb37dea1f-1718279080124@3c-app-gmx-bap17 \
--to=hombre67@gmx.at \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).