From: Florian Forster Date: Fri, 3 Oct 2008 21:11:47 +0000 (+0200) Subject: src/utils_ignorelist.c: Fix an off-by-one errror when adding regular expressions. X-Git-Tag: collectd-4.4.4~16 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e0df7ed3f1a6bc3d9164dde7f25b8ed582388a9b;p=collectd.git src/utils_ignorelist.c: Fix an off-by-one errror when adding regular expressions. Resolves: #20 --- diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c index 1d9467fe..689b4a42 100644 --- a/src/utils_ignorelist.c +++ b/src/utils_ignorelist.c @@ -306,11 +306,13 @@ int ignorelist_add (ignorelist_t *il, const char *entry) if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/') { char *entry_copy; + size_t entry_copy_size; /* We need to copy `entry' since it's const */ - entry_copy = smalloc (entry_len); - memset (entry_copy, '\0', entry_len); - strncpy (entry_copy, entry + 1, entry_len - 2); + entry_copy_size = entry_len - 1; + entry_copy = smalloc (entry_copy_size); + strncpy (entry_copy, entry + 1, entry_copy_size); + entry_copy[entry_copy_size - 1] = 0; DEBUG("I'm about to add regex entry: %s", entry_copy); ret = ignorelist_append_regex(il, entry_copy);