From: Sebastian Harl Date: Thu, 2 Oct 2008 12:53:06 +0000 (+0200) Subject: iptables plugin, utils_ignorelist: Fixed an off-by-one error each. X-Git-Tag: collectd-4.5.1~9 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ee9507500f738d21858f76128501772d212c069c;p=collectd.git iptables plugin, utils_ignorelist: Fixed an off-by-one error each. Those were introduced when unifying the string handling in commit 5f9ec13b in cases where the exact length of the string to be copied is passed to sstrncpy instead of the size of the destination buffer. In case of the iptables plugin this prevented the table or chain name to match correctly as the user configuration was truncated. In case of the ignorelist a given regex was truncated. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/src/iptables.c b/src/iptables.c index 4d15c6e0..e1694af3 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -107,8 +107,8 @@ static int iptables_config (const char *key, const char *value) table = fields[0]; chain = fields[1]; - table_len = strlen (table); - if ((unsigned int)table_len >= sizeof(temp.table)) + table_len = strlen (table) + 1; + if ((unsigned int)table_len > sizeof(temp.table)) { ERROR ("Table `%s' too long.", table); free (value_copy); @@ -116,8 +116,8 @@ static int iptables_config (const char *key, const char *value) } sstrncpy (temp.table, table, table_len); - chain_len = strlen (chain); - if ((unsigned int)chain_len >= sizeof(temp.chain)) + chain_len = strlen (chain) + 1; + if ((unsigned int)chain_len > sizeof(temp.chain)) { ERROR ("Chain `%s' too long.", chain); free (value_copy); diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c index 518715b1..db679dad 100644 --- a/src/utils_ignorelist.c +++ b/src/utils_ignorelist.c @@ -310,7 +310,8 @@ int ignorelist_add (ignorelist_t *il, const char *entry) /* We need to copy `entry' since it's const */ entry_copy = smalloc (entry_len); memset (entry_copy, '\0', entry_len); - sstrncpy (entry_copy, entry + 1, entry_len - 2); + /* sstrncpy() overwrites the trailing '/' */ + sstrncpy (entry_copy, entry + 1, entry_len - 1); DEBUG("I'm about to add regex entry: %s", entry_copy); ret = ignorelist_append_regex(il, entry_copy);