Skip to contentSkip to conversation

Trivial space char fix for --log-prefix

PATCH In review Michael Rash 3 participants 3 messages Dec 8, 2003 – Dec 11, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Trivial space char fix for --log-prefix

Hello -

This patch adds a space character to the --log-prefix string if the user did not have it already. This prevents the "IN=" field in iptables log messages from being obscured by a --log-prefix that doesn't have a space.

(Resending this since my original post did not seem to make it through).

--Mike

Michael Rash
http://www.cipherdyne.org
Key fingerprint = 53EA 13EA 472E 3771 894F AC69 95D8 5D6B A742 839F

libipt_LOG.c +11 -1
diff -u -r1.14 libipt_LOG.c
@@ -107,6 +107,7 @@
       struct ipt_entry_target **target)
 {
 	struct ipt_log_info *loginfo = (struct ipt_log_info *)(*target)->data;
+	unsigned short int addspc_f = 0, prefix_len = 0;
 
 	switch (c) {
 	case '!':
@@ -131,12 +132,21 @@
 			exit_error(PARAMETER_PROBLEM,
 				   "Unexpected `!' after --log-prefix");
 
-		if (strlen(optarg) > sizeof(loginfo->prefix) - 1)
+		prefix_len = strlen(optarg);
+		if (optarg[strlen(optarg)-1] != ' ') {
+			/* we need to add a space */
+			addspc_f = 1;
+			prefix_len++;
+		}
+
+		if (prefix_len > sizeof(loginfo->prefix) - 1)
 			exit_error(PARAMETER_PROBLEM,
 				   "Maximum prefix length %u for --log-prefix",
 				   sizeof(loginfo->prefix) - 1);
 
 		strcpy(loginfo->prefix, optarg);
+		if (addspc_f)
+			loginfo->prefix[prefix_len-1] = ' ';
 		*flags |= IPT_LOG_OPT_PREFIX;
 		break;
#1 lore raw
Quoted 10 lines · Michael Rash

Hello -

This patch adds a space character to the --log-prefix string if the user did not have it already. This prevents the "IN=" field in iptables log messages from being obscured by a --log-prefix that doesn't have a space.

(Resending this since my original post did not seem to make it through).

We have received such a patch numerous times. However, we felt that changing the behaviour now is bad - everybody knows about the old behaviour by now, and all the scripts that have been written in the last couple of years assume it to _not_ automatically add the space.

Yes, I regard it a bug. But we'd rather stick with it for compatibility reasons :(

Quoted 1 line

--Mike

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.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
#2 lore raw
Quoted 4 lines · Harald Welte

We have received such a patch numerous times. However, we felt that changing the behaviour now is bad - everybody knows about the old behaviour by now, and all the scripts that have been written in the last couple of years assume it to _not_ automatically add the space.

Please note that the proposed patch only adds a space if there was none. I do not think anyone with a working mind is intentionally using the fact that the --log-prefix can be used without a space to separate it from the rest of the log result today.

Regards
Henrik