From nobody Fri Jan 03 01:53:17 2025 X-Original-To: dev-commits-src-main@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 4YPRRy07Hnz5kFdy; Fri, 03 Jan 2025 01:53:18 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YPRRx4TLRz4QwW; Fri, 3 Jan 2025 01:53:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735869197; 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=J34NjgtxOEYxfM9jenX8zcSddXstmjdYdKsLDkYmMcQ=; b=JeLzusuQGmhHUw+qEMfzpLL0x1pYz17R8wqe8aN4HQQkfbggOmn3ahcdAHamdWjtl89iJ8 QqcJrByYKZumMoSX6bG0ZovsvpblK5dlAODtzTSHw2IEdrt+REk9vnmh7VbCaWbrH2DIX1 Kk6fPuRmeX8D3m/J656jTzeObkiiqplEbRf6lx4Yx7UBzwwPtdV1oypnxgYotofGnTXkgE H3FaWU5FygaTPLV2vuJORFFAp5uSApWPhOrJ5hR1Pth88OX9gn2nQIl0dQc9x/o20v3bQT twDzSLdkzs8lXfLy7QkCwAntSPMNOi3aVdN6uvr5iQQPssyJMb/n9NMjocElow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735869197; 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=J34NjgtxOEYxfM9jenX8zcSddXstmjdYdKsLDkYmMcQ=; b=A8G2lgJBIOu2RWp+Htfdl2gW4H7kvq/xLXCkkRzhnrkeQB6svNGXpVvKHR1YSSI5mx337o sqLBi8B9WamRlOLJgZn49v0bPgUI5HwyrtcDvYhycvQq348P4BZKaRGSfP9KY6NE6J6U0Z ORvkCIwZGaENsl7z15Z63hJwQBfH/ndHyWBAg1/bGuy+5jpGKfzRchbeEi7fzSZGxM0Mpq B8KkklkKZTIx1zSvyeMh4Fx7am4aWeIQNa8+X6uGDpQlR6n6dqXQUK9uMFrinXQg52xLwO w8wkFUuiwI1ZD79RI3JW9gUCLh/zbb2bN0WlkNCAHrbiKOT3mZ9Qi89R/0ICDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735869197; a=rsa-sha256; cv=none; b=Mgf31B3Mm4EN+jbg5LyNfxUGLZzZzZwIqr7ORoAGqh8hvBfkdbAxVRH782jQrItb8IOlqN rv56CxkfwXa6t6alNKRCEtobsvRuNiKLb0XnN8L2G9mz6XB7M59b/ZDBS4p0SLkdidCB6G mJ419guJ9OzN/y6yRYVuNd5eYkrhIfucWayXvIk+Zj9XswAHBtLVLvkb+qEiwu9CEMqYu4 cJgiF2wxsm8MpgA/RE5gKzudDajiuMj1r7ga9aEAK7RWfMnLQ9HjqTGRn9+fgV38dxYJrv 8ZwFCFuvJERMRBbKhfOjB+86/R2RT2lqW8Me84itIwXn2JVpF95hilpUt5MZRg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YPRRx42s8z12XC; Fri, 03 Jan 2025 01:53:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5031rH5e008730; Fri, 3 Jan 2025 01:53:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5031rH2m008727; Fri, 3 Jan 2025 01:53:17 GMT (envelope-from git) Date: Fri, 3 Jan 2025 01:53:17 GMT Message-Id: <202501030153.5031rH2m008727@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 526bd072b33e - main - syslogd: Fix resource leaks List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 526bd072b33e3e255748e547fdc21ab15e77b709 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=526bd072b33e3e255748e547fdc21ab15e77b709 commit 526bd072b33e3e255748e547fdc21ab15e77b709 Author: Mark Johnston AuthorDate: 2025-01-03 01:51:19 +0000 Commit: Mark Johnston CommitDate: 2025-01-03 01:51:19 +0000 syslogd: Fix resource leaks - nvlist_append_nvlist_array() makes a copy of the input nvlist, so the pattern of nvlist_append_nvlist_array(... cfline(...)) would leak memory and descriptors. Pass the entire config nvlist to cfline() instead since this is needed for a future change. - In parse_action(), free the linked list returned by getaddrinfo(). - Remove some checks at the beginning of close_filed(). For some log types we'll always have f->f_file == -1, in which case we wouldn't release other resources, such as forwarding sockets. - After converting a filed to an nvlist, free the filed resources. Fixes: 2567168dc498 ("syslogd: Refresh configuration using libcasper") Reviewed by: jfree Differential Revision: https://reviews.freebsd.org/D48250 --- usr.sbin/syslogd/syslogd.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index be4eaa235d36..e1d3dffe013a 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -334,7 +334,8 @@ struct iovlist; static bool allowaddr(char *); static void addpeer(const char *, const char *, mode_t); static void addsock(const char *, const char *, mode_t); -static nvlist_t *cfline(const char *, const char *, const char *, const char *); +static void cfline(nvlist_t *, const char *, const char *, const char *, + const char *); static const char *cvthname(struct sockaddr *); static struct deadq_entry *deadq_enter(int); static void deadq_remove(struct deadq_entry *); @@ -369,10 +370,6 @@ static void increase_rcvbuf(int); static void close_filed(struct filed *f) { - - if (f == NULL || f->f_file == -1) - return; - switch (f->f_type) { case F_FORW: if (f->f_addr_fds != NULL) { @@ -409,7 +406,8 @@ close_filed(struct filed *f) default: break; } - (void)close(f->f_file); + if (f->f_file != -1) + (void)close(f->f_file); f->f_file = -1; } @@ -2447,8 +2445,7 @@ parseconfigfile(FILE *cf, bool allow_includes, nvlist_t *nvl_conf) } for (i = strlen(cline) - 1; i >= 0 && isspace(cline[i]); i--) cline[i] = '\0'; - nvlist_append_nvlist_array(nvl_conf, "filed_list", - cfline(cline, prog, host, pfilter)); + cfline(nvl_conf, cline, prog, host, pfilter); } return (nvl_conf); @@ -2472,10 +2469,8 @@ readconfigfile(const char *path) (void)fclose(cf); } else { dprintf("cannot open %s\n", path); - nvlist_append_nvlist_array(nvl_conf, "filed_list", - cfline("*.ERR\t/dev/console", "*", "*", "*")); - nvlist_append_nvlist_array(nvl_conf, "filed_list", - cfline("*.PANIC\t*", "*", "*", "*")); + cfline(nvl_conf, "*.ERR\t/dev/console", "*", "*", "*"); + cfline(nvl_conf, "*.PANIC\t*", "*", "*", "*"); } return (nvl_conf); } @@ -3071,7 +3066,7 @@ parse_action(const char *p, struct filed *f) if (shutdown(*sockp, SHUT_RD) < 0) err(1, "shutdown"); } - + freeaddrinfo(res); f->f_type = F_FORW; break; @@ -3125,10 +3120,11 @@ parse_action(const char *p, struct filed *f) } /* - * Crack a configuration file line + * Convert a configuration file line to an nvlist and add to "nvl", which + * contains all of the log configuration processed thus far. */ -static nvlist_t * -cfline(const char *line, const char *prog, const char *host, +static void +cfline(nvlist_t *nvl, const char *line, const char *prog, const char *host, const char *pfilter) { nvlist_t *nvl_filed; @@ -3169,6 +3165,7 @@ cfline(const char *line, const char *prog, const char *host, /* An nvlist is heap allocated heap here. */ nvl_filed = filed_to_nvlist(&f); + close_filed(&f); if (pfilter && *pfilter != '*') { nvlist_t *nvl_pfilter; @@ -3179,7 +3176,8 @@ cfline(const char *line, const char *prog, const char *host, nvlist_add_nvlist(nvl_filed, "f_prop_filter", nvl_pfilter); } - return (nvl_filed); + nvlist_append_nvlist_array(nvl, "filed_list", nvl_filed); + nvlist_destroy(nvl_filed); } /*