netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Leblond <eric@regit.org>
To: netfilter-devel@vger.kernel.org
Cc: eric@regit.org
Subject: [PATCH 7/7] conf: error handling for too long line
Date: Mon, 18 Feb 2013 09:37:48 +0100	[thread overview]
Message-ID: <1361176668-22661-8-git-send-email-eric@regit.org> (raw)
In-Reply-To: <1361176668-22661-1-git-send-email-eric@regit.org>

Line length in configuration file is limited to 255 due to the use
of a static buffer for line reading. Accepting too long line
without warning as it is currently done could result in some
unexplainable failure.

This patch adds error handling and reject configuration file if a
non comment line is longer than the maximum value.

Signed-off-by: Eric Leblond <eric@regit.org>
---
 src/conffile.c |   15 +++++++++++++++
 src/ulogd.c    |   10 +++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/conffile.c b/src/conffile.c
index 9a73406..b8e82a8 100644
--- a/src/conffile.c
+++ b/src/conffile.c
@@ -123,6 +123,7 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 	unsigned int i;
 	char linebuf[LINE_LEN+1];
 	char *line = linebuf;
+	int linenum = 0;
 
 	pr_debug("%s: section='%s' file='%s'\n", __func__, section, fname);
 
@@ -135,9 +136,16 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 		char wordbuf[LINE_LEN];
 		char *wordend;
 
+		linenum++;
 		if (*line == '#')
 			continue;
 
+		/* 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;
+		}
+
 		if (!(wordend = get_word(line, " \t\n[]", (char *) wordbuf)))
 			continue;
 		pr_debug("word: \"%s\"\n", wordbuf);
@@ -159,10 +167,17 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 		char wordbuf[LINE_LEN];
 		char *wordend;
 		
+		linenum++;
 		pr_debug("line read: %s\n", line);
 		if (*line == '#')
 			continue;
 
+		/* 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;
+		}
+
 		if (!(wordend = get_word(line, " =\t\n", (char *) &wordbuf)))
 			continue;
 
diff --git a/src/ulogd.c b/src/ulogd.c
index 6c0df8a..4af4e9a 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -990,9 +990,13 @@ static int parse_conffile(const char *section, struct config_keyset *ce)
 				"section \"%s\" not found\n", section);
 			break;
 		case -ERRTOOLONG:
-			ulogd_log(ULOGD_ERROR,
-				"too long string value for key \"%s\"\n",
-				config_errce->key);
+			if (config_errce->key)
+				ulogd_log(ULOGD_ERROR,
+					  "too long string value for key \"%s\"\n",
+					  config_errce->key);
+			else
+				ulogd_log(ULOGD_ERROR,
+					  "too long string value\n");
 			break;
 	}
 	return 1;
-- 
1.7.10.4


  parent reply	other threads:[~2013-02-18  8:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-18  8:37 [ulogd patch] small code cleaning Eric Leblond
2013-02-18  8:37 ` [PATCH 1/7] Update TODO Eric Leblond
2013-02-18  8:37 ` [PATCH 2/7] Suppress dead FIXME Eric Leblond
2013-02-18  8:37 ` [PATCH 3/7] Use access to ensure readability of config gile Eric Leblond
2013-02-18  8:37 ` [PATCH 4/7] Fix typo in comments Eric Leblond
2013-02-18  8:37 ` [PATCH 5/7] Add handling of too long arguments Eric Leblond
2013-02-18  9:41   ` Mr Dash Four
2013-02-18 15:04     ` Eric Leblond
2013-02-18  8:37 ` [PATCH 6/7] logemu: return error if configuration is invalid Eric Leblond
2013-02-18  8:37 ` Eric Leblond [this message]
2013-02-18  9:41   ` [PATCH 7/7] conf: error handling for too long line Mr Dash Four
2013-02-22 10:18 ` [ulogd patch] small code cleaning Eric Leblond

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=1361176668-22661-8-git-send-email-eric@regit.org \
    --to=eric@regit.org \
    --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).