]> git.ipfire.org Git - thirdparty/collectd.git/commit
Write MongoDB plugin: fix format trunction errors. 4158/head
authorFlorian Forster <octo@collectd.org>
Fri, 24 Nov 2023 08:15:04 +0000 (09:15 +0100)
committerFlorian Forster <octo@collectd.org>
Fri, 24 Nov 2023 08:19:34 +0000 (09:19 +0100)
commit9db1fd47ee607e9bcee762e3b659a9af2b2c0e87
tree25b312cb751e33b26ec5ee48b2429596ca521e64
parente45a7c03dcf89d836906c7bf207f01cf66c8756d
Write MongoDB plugin: fix format trunction errors.

When a `size_t` is a 64bit integer, the 16 byte buffer could potentially
overflow. Fix this by using a larger buffer and also collectd's own
`ssnprintf()` function which guarantees to result in a null terminated
string.

```
In function 'wm_create_bson',
    inlined from 'wm_write' at src/write_mongodb.c:229:17:
src/write_mongodb.c:99:32: error: '%zu' directive output may be truncated writing between 1 and 20 bytes into a region of size 16 [-Werror=format-truncation=]
   99 |     snprintf(key, sizeof(key), "%" PRIsz, i);
      |                                ^~~
src/write_mongodb.c: In function 'wm_write':
src/write_mongodb.c:99:33: note: format string is defined here
   99 |     snprintf(key, sizeof(key), "%" PRIsz, i);
```
src/write_mongodb.c