From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 9FA9B22636 for ; Thu, 21 Mar 2024 23:34:29 +0100 (CET) Received: (qmail 18400 invoked by uid 550); 21 Mar 2024 22:29:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 18365 invoked from network); 21 Mar 2024 22:29:52 -0000 Date: Thu, 21 Mar 2024 18:34:34 -0400 From: Rich Felker To: Maks Mishin Cc: musl@lists.openwall.com Message-ID: <20240321223433.GK15722@brightrain.aerifal.cx> References: <20240321213109.10701-1-maks.mishinFZ@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240321213109.10701-1-maks.mishinFZ@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [musl] Re: [PATCH] syslog: Check result of connect function On Fri, Mar 22, 2024 at 12:31:09AM +0300, Maks Mishin wrote: > Return value of of function 'connect', called at syslog.c:55, > is not checked. The return value possibly contains > an error code and ignoring it may lead to missing important errors. > > Found by RASU JSC. > > Signed-off-by: Maks Mishin > --- > src/misc/syslog.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/src/misc/syslog.c b/src/misc/syslog.c > index 710202f9..72ad6d2c 100644 > --- a/src/misc/syslog.c > +++ b/src/misc/syslog.c > @@ -52,7 +52,12 @@ void closelog(void) > static void __openlog() > { > log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); > - if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr); > + if (log_fd >= 0) { > + int ret = connect(log_fd, (void *)&log_addr, sizeof log_addr); > + if (ret > 0) { > + errno = ret; > + } > + } > } > > void openlog(const char *ident, int opt, int facility) > -- > 2.30.2 This patch is wrong but does nothing; connect is not permitted to return positive values. It returns either 0 on success or -1 on error. Since openlog cannot report failure to the caller (it returns void), it's a best-effort operation. In the case where it fails to connect, it's still desirable and intentional to leave a socket reserved so that the program can't run out of file descriptors rendering it unable to produce log output later. The lack of connection will be noticed later when send() fails and the is_lost_conn predicate on errno returns true. Rich