From nobody Thu Aug 18 15:21:31 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M7pWc18s0z4Zl5x; Thu, 18 Aug 2022 15:21:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M7pWc0hRCz446R; Thu, 18 Aug 2022 15:21:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660836092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ta65AsjA9SZf3i7RNWUqAKEc1S2yyOmNF+w2fR5sDRo=; b=b3Iq+tpD1s1JxUpk5zycYopoYeNmZqQB7voGmu8MDutm62UaVjBXsgrTozfVqWnCGWK1OO 5mbr9baLGJsicUVEyN3SsVswluaeLcTgkkPoxkrceOjrGSWa2JBCSI2+5qiqiES1c0aJxZ /Zvf1N445LgvUf8SVo2avpxWJ+wjovqf7nRuGMY+BD2uwEDr9s0Dc7oEtbkEDUwiB96Hyk UZlCThl16qe5UOh9ECXScfaYytms2gh4kmB0q713Rt/33NWSd9pADTg8xSxFSaKBKGJihf kzjYiZHFG46sjFTxfA5hazbgMKf0bG8nbpBgA0HIvW77S3B/JPZLmK6okKuFWA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M7pWb6YP5zJ1c; Thu, 18 Aug 2022 15:21:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27IFLV4f048707; Thu, 18 Aug 2022 15:21:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27IFLVAx048706; Thu, 18 Aug 2022 15:21:31 GMT (envelope-from git) Date: Thu, 18 Aug 2022 15:21:31 GMT Message-Id: <202208181521.27IFLVAx048706@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Subject: git: 4f8b31efcf95 - stable/12 - syslog(3): Send proper NILVALUE if gethostname(3) fails. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 4f8b31efcf95b43ed64bf6f9c895a27e8dffe158 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660836092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ta65AsjA9SZf3i7RNWUqAKEc1S2yyOmNF+w2fR5sDRo=; b=T17E/CyFngZj+KvR3zgVzJCZCtWL/sOz9tpumA+UyI34a8aGIBps+tYelTIWTEe8UJu/Wb rG4yZAHnm0abwhTXJfBqRI6yspClIf2M4+1qQHVzU+2gg5hMLz5Z6GcLa274275YhFbh6b 3hguMvWIhk2JVUcEYSQf5nwkhP8zT0EkI+1Tg8BdT07jEn8UkcGhrw0bVkvoGBEyWBw4vz 7PX/AWreVo2ccD4BMLZAh9VidY20X7TfmwKry9CviGlkid5lGS+QMzAkh/Syhf6UF+twUX CAVSMMdAgJUhOVwcEuRVKTW/F+O6zDOEkhhMGTVuyaP+EaAhkDAg4msoreL0Uw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660836092; a=rsa-sha256; cv=none; b=M5Qq64vCNb1Sw4YzhS4Mjgvi4tcXoMjdoiInPkfsdLLs/7HsJTcTIIhr2+i68USTnJvPM0 yoHNyEojQ5FE+ixv+oFoKTEGTbVrp4Bx49JbOi1Da8uDOB+XA3OSsn03mrwsU1t19U1ZeF t+0DSuFgwyYLO/CCfhisHDC2SoCR7IvkP5HVGKYPCiMyEyje+86E0W3tBXBg0wnUZ+GsXk Im0HDlAOR2HPcUUMmB41kQ0fPOhOxVfZAbBkeyM3pIEYmTWP5eePqamjDy/R+jLXWRkZvE VpVyS8ulkdyShSypg3AIQ/Ui0zPtV2V2eomeCkvjUCPyCRuQ2xhjkK4HVd/ceA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=4f8b31efcf95b43ed64bf6f9c895a27e8dffe158 commit 4f8b31efcf95b43ed64bf6f9c895a27e8dffe158 Author: Bryan Drewery AuthorDate: 2020-08-14 00:18:18 +0000 Commit: Eugene Grosbein CommitDate: 2022-08-18 15:13:04 +0000 syslog(3): Send proper NILVALUE if gethostname(3) fails. RFC5424 defines NILVALUE as '-'. Replace its usage with a macro and separate out the fields to be more clear. fputs(3) is used in some places to avoid hiding possible format string problems in a macro. Reviewed by: cem, vangyzen (earlier version) Sponsored by: Dell EMC (cherry picked from commit 2933cd31845432dbaac67917e6babc516d2a57d1) --- lib/libc/gen/syslog.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index a0f1ddc97535..19d44db0075a 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -75,6 +75,9 @@ static pthread_mutex_t syslog_mutex = PTHREAD_MUTEX_INITIALIZER; if (__isthreaded) _pthread_mutex_unlock(&syslog_mutex); \ } while(0) +/* RFC5424 defined value. */ +#define NILVALUE "-" + static void disconnectlog(void); /* disconnect from syslogd */ static void connectlog(void); /* (re)connect to syslogd */ static void openlog_unlocked(const char *, int, int); @@ -190,25 +193,30 @@ vsyslog1(int pri, const char *fmt, va_list ap) tm.tm_hour, tm.tm_min, tm.tm_sec, now.tv_usec, tz_sign, tz_offset / 3600, (tz_offset % 3600) / 60); } else - (void)fprintf(fp, "- "); + (void)fputs(NILVALUE " ", fp); /* Hostname. */ (void)gethostname(hostname, sizeof(hostname)); - (void)fprintf(fp, "%s ", hostname); + (void)fprintf(fp, "%s ", + hostname[0] == '\0' ? NILVALUE : hostname); if (LogStat & LOG_PERROR) { /* Transfer to string buffer */ (void)fflush(fp); stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left); } + /* Application name. */ + if (LogTag == NULL) + LogTag = _getprogname(); + (void)fprintf(fp, "%s ", LogTag == NULL ? NILVALUE : LogTag); /* - * Application name, process ID, message ID and structured data. * Provide the process ID regardless of whether LOG_PID has been * specified, as it provides valuable information. Many * applications tend not to use this, even though they should. */ - if (LogTag == NULL) - LogTag = _getprogname(); - (void)fprintf(fp, "%s %d - - ", - LogTag == NULL ? "-" : LogTag, getpid()); + (void)fprintf(fp, "%d ", getpid()); + /* Message ID. */ + (void)fputs(NILVALUE " ", fp); + /* Structured data. */ + (void)fputs(NILVALUE " ", fp); /* Check to see if we can skip expanding the %m */ if (strstr(fmt, "%m")) { @@ -251,6 +259,7 @@ vsyslog1(int pri, const char *fmt, va_list ap) fmt = fmt_cpy; } + /* Message. */ (void)vfprintf(fp, fmt, ap); (void)fclose(fp);