Direct usage of flb_sds_alloc
as size argument for flb_sds_snprintf
#9803
Labels
flb_sds_alloc
as size argument for flb_sds_snprintf
#9803
Bug Report
Describe the bug
There are numerous spots throughout the codebase where
flb_sds_alloc
is used as the size argument forflb_sds_snprintf
.flb_sds_alloc
gets thealloc
field ofstruct flb_sds
, which does not include the null terminator, howevervsnprintf
expects a size argument that does include the null terminator. This leads to a potential bug where the result offlb_sds_snprintf
could include one less character than expected.To Reproduce
In a random test file that included
flb_sds.h
, I wrote the following test:The result was this:
When I change it to not adjusting the size (i.e. instead of
flb_sds_alloc(s)+1
it's justflb_sds_alloc(s)
):Additional context
First discovered by @jefferbrecht here: #9779 (comment)
Searching in this repo for
flb_sds_snprintf
usage has some examples right on the first page, but here is a quick list of a few spots doing it as an example:fluent-bit/plugins/out_es/es.c
Line 366 in 68f1887
fluent-bit/plugins/out_azure_logs_ingestion/azure_logs_ingestion_conf.c
Line 102 in 68f1887
fluent-bit/plugins/out_azure_kusto/azure_kusto.c
Line 152 in 68f1887
This is unlikely to be an issue of safety/exposure to a vulnerability thanks to
snprintf
safely discarding any characters past<size argument> - 1
.The text was updated successfully, but these errors were encountered: