]> git.ipfire.org Git - thirdparty/ulogd2.git/commit
output: SQLITE3: improve mapping of DB columns to fields
authorJeremy Sowden <jeremy@azazel.net>
Tue, 30 Nov 2021 10:55:49 +0000 (10:55 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 3 Jan 2022 15:08:54 +0000 (16:08 +0100)
commit12f0909d606684010bc9c4ba97857f89c3d2dd70
tree910f5a48bbb81bb3c7bf8c9b01c66bff375b5b01
parent53d669d95c94aab4366b8fe9544d61369aa384b5
output: SQLITE3: improve mapping of DB columns to fields

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 field's
`name` member.

Apart from the inefficiency, `strncpy` is used to do the copies, which
leads gcc to complain:

  ulogd_output_SQLITE3.c:341: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 field 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>
output/sqlite3/ulogd_output_SQLITE3.c