summaryrefslogtreecommitdiffstats
path: root/output/mysql/ulogd_output_MYSQL.c
diff options
context:
space:
mode:
authorJeremy Sowden <jeremy@azazel.net>2021-11-30 10:55:43 +0000
committerPablo Neira Ayuso <pablo@netfilter.org>2021-12-06 22:28:42 +0100
commit33e2c5b2f63844a3e08fc287d0d8921cbc3b8f86 (patch)
tree4481e8ee0687626ae3bf46b77e2ebe873ead2aa2 /output/mysql/ulogd_output_MYSQL.c
parent23dcfc558ecfcf7cc7ef8a002dea8a3ac31f0335 (diff)
output: MYSQL: improve mapping of DB columns to input-keys
Currently, we copy the column-name to a buffer, iterate over it to replace the underscores with full-stops, using `strchr` from the start of the buffer on each iteration, then copy the buffer to the input-key's `name` member. Apart from the inefficiency, `strncpy` is used to do the copies, which leads gcc to complain: ulogd_output_MYSQL.c:149:17: warning: `strncpy` output may be truncated copying 31 bytes from a string of length 31 Furthermore, the buffer is not initialized, which means that there is also a possible buffer overrun if the column-name is too long, since `strncpy` will not append a NUL. Instead, copy the column-name directly to the input-key using `snprintf`, and run `strchr` from the last underscore on each iteration. Signed-off-by: Jeremy Sowden <jeremy@azazel.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'output/mysql/ulogd_output_MYSQL.c')
-rw-r--r--output/mysql/ulogd_output_MYSQL.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/output/mysql/ulogd_output_MYSQL.c b/output/mysql/ulogd_output_MYSQL.c
index 66151fe..9727e30 100644
--- a/output/mysql/ulogd_output_MYSQL.c
+++ b/output/mysql/ulogd_output_MYSQL.c
@@ -135,18 +135,18 @@ static int get_columns_mysql(struct ulogd_pluginstance *upi)
}
for (i = 0; (field = mysql_fetch_field(result)); i++) {
- char buf[ULOGD_MAX_KEYLEN+1];
char *underscore;
+ snprintf(upi->input.keys[i].name,
+ sizeof(upi->input.keys[i].name),
+ "%s", field->name);
+
/* replace all underscores with dots */
- strncpy(buf, field->name, ULOGD_MAX_KEYLEN);
- while ((underscore = strchr(buf, '_')))
+ for (underscore = upi->input.keys[i].name;
+ (underscore = strchr(underscore, '_')); )
*underscore = '.';
- DEBUGP("field '%s' found\n", buf);
-
- /* add it to list of input keys */
- strncpy(upi->input.keys[i].name, buf, ULOGD_MAX_KEYLEN);
+ DEBUGP("field '%s' found\n", upi->input.keys[i].name);
}
/* MySQL Auto increment ... ID :) */
upi->input.keys[0].flags |= ULOGD_KEYF_INACTIVE;