netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Corubba Smith <corubba@gmx.de>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH ulogd2 1/8] ulogd: fix config file fd leak
Date: Sat, 8 Mar 2025 23:32:29 +0100	[thread overview]
Message-ID: <ca5581f5-5e54-47f5-97c8-bcc788c77781@gmx.de> (raw)

Consistently use the return jump to close the config file descriptor if
opened, to prevent it from leaking.

Signed-off-by: Corubba Smith <corubba@gmx.de>
---
 src/conffile.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/conffile.c b/src/conffile.c
index 66769de..5b7f834 100644
--- a/src/conffile.c
+++ b/src/conffile.c
@@ -143,7 +143,8 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 		/* if line was fetch completely, string ends with '\n' */
 		if (! strchr(line, '\n')) {
 			ulogd_log(ULOGD_ERROR, "line %d too long.\n", linenum);
-			return -ERRTOOLONG;
+			err = -ERRTOOLONG;
+			goto cpf_error;
 		}

 		if (!(wordend = get_word(line, " \t\n\r[]", (char *) wordbuf)))
@@ -156,8 +157,8 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 	}

 	if (!found) {
-		fclose(cfile);
-		return -ERRSECTION;
+		err = -ERRSECTION;
+		goto cpf_error;
 	}

 	/* Parse this section until next section */
@@ -175,7 +176,8 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 		/* if line was fetch completely, string ends with '\n' */
 		if (! strchr(line, '\n')) {
 			ulogd_log(ULOGD_ERROR, "line %d too long.\n", linenum);
-			return -ERRTOOLONG;
+			err = -ERRTOOLONG;
+			goto cpf_error;
 		}

 		if (!(wordend = get_word(line, " =\t\n\r", (char *) &wordbuf)))
--
2.48.1

             reply	other threads:[~2025-03-08 22:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 22:32 Corubba Smith [this message]
2025-03-08 22:33 ` [PATCH ulogd2 2/8] ulogd: add ulogd_parse_configfile public function Corubba Smith
2025-03-12  7:47   ` Florian Westphal
2025-03-08 22:34 ` [PATCH ulogd2 3/8] all: use config_parse_file function in all plugins Corubba Smith
2025-03-08 22:35 ` [PATCH ulogd2 4/8] ulogd: raise error on unknown config key Corubba Smith
2025-03-08 22:36 ` [PATCH ulogd2 5/8] ulogd: ignore malformed config directives Corubba Smith
2025-03-08 22:37 ` [PATCH ulogd2 6/8] ulogd: improve integer option parsing Corubba Smith
2025-03-08 22:38 ` [PATCH ulogd2 7/8] ulogd: default configure implementation Corubba Smith
2025-03-08 22:39 ` [PATCH ulogd2 8/8] all: remove trivial configure hooks Corubba Smith

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=ca5581f5-5e54-47f5-97c8-bcc788c77781@gmx.de \
    --to=corubba@gmx.de \
    --cc=netfilter-devel@vger.kernel.org \
    /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.
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).