Skip to contentSkip to conversation

Disallow newlines in LOG target --log-prefix

PATCH In review Phil Oester 2 participants 2 messages Mar 29, 2005 – Apr 1, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Disallow newlines in LOG target --log-prefix

As reported in bugzilla, iptables currently does not complain about the following:

# iptables -A foo -j LOG --log-prefix 'asdfasdfa
asdf'

Patch below makes it complain, and closes bugzilla #312.

Phil

extensions/libip6t_LOG.c +4 -0
diff -ru iptables-orig/extensions/libip6t_LOG.c iptables-new/extensions/libip6t_LOG.c
@@ -134,6 +134,10 @@
 				   "Maximum prefix length %u for --log-prefix",
 				   (unsigned int)sizeof(loginfo->prefix) - 1);
 
+		if (strlen(optarg) != strlen(strtok(optarg, "\n")))
+			exit_error(PARAMETER_PROBLEM,
+				   "Newlines not allowed in --log-prefix");
+
 		strcpy(loginfo->prefix, optarg);
 		*flags |= IP6T_LOG_OPT_PREFIX;
 		break;
extensions/libipt_LOG.c +4 -0
diff -ru iptables-orig/extensions/libipt_LOG.c iptables-new/extensions/libipt_LOG.c
@@ -143,6 +143,10 @@
 				   "Maximum prefix length %u for --log-prefix",
 				   (unsigned int)sizeof(loginfo->prefix) - 1);
 
+		if (strlen(optarg) != strlen(strtok(optarg, "\n")))
+			exit_error(PARAMETER_PROBLEM,
+				   "Newlines not allowed in --log-prefix");
+
 		strcpy(loginfo->prefix, optarg);
 		*flags |= IPT_LOG_OPT_PREFIX;
 		break;
#1 lore raw

Thanks again, Phil.

Quoted 7 lines · Phil Oester

As reported in bugzilla, iptables currently does not complain about the following:

# iptables -A foo -j LOG --log-prefix 'asdfasdfa
asdf'

Patch below makes it complain, and closes bugzilla #312.

Sending extensions/libip6t_LOG.c
Sending extensions/libipt_LOG.c
Transmitting file data ..
Committed revision 3819.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie