]> git.ipfire.org Git - thirdparty/ulogd2.git/commit
output: DBI: improve mapping of DB columns to input-keys
authorJeremy Sowden <jeremy@azazel.net>
Tue, 30 Nov 2021 10:55:40 +0000 (10:55 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 30 Nov 2021 22:08:26 +0000 (23:08 +0100)
commit0a9fa5603a435afed955f5458a17331b7f2f18ca
tree2195e3c97b456e3ad151388a75f5a6f3557f1af3
parent97fd6fa529330024264e5fa1ee5481a494c47137
output: DBI: 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, iterate over it a second time to
lower-case all letters, and finally copy the buffer to the input-key's
`name` member.

In addition to being inefficient, `strncpy` is used to do the copies,
which leads gcc to complain:

  ulogd_output_DBI.c:160: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 then iterate over it once to replace underscores and
lower-case letters.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
output/dbi/ulogd_output_DBI.c