diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2022-05-18 17:15:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-18 17:15:13 +0300 |
commit | 7e29d5a90896c777d823c46a232fb0edf4f4525e (patch) | |
tree | 374e539abdbf855ad53fe7fc30be721416a28b79 /libnetdata | |
parent | 1edfe043708f6fca3b7d9cc578bf876ccf7a1c8e (diff) |
Prevent command_to_be_logged from overflowing (#12947)
* prevent command_to_be_logged from overflowing
* dont access with size
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/libnetdata.c | 9 | ||||
-rw-r--r-- | libnetdata/popen/popen.c | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/libnetdata/libnetdata.c b/libnetdata/libnetdata.c index 69e1d1cf78..5929d976f9 100644 --- a/libnetdata/libnetdata.c +++ b/libnetdata/libnetdata.c @@ -1111,14 +1111,13 @@ char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) { } int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args) { + if(unlikely(!n)) return 0; + int size = vsnprintf(dst, n, fmt, args); + dst[n - 1] = '\0'; - if (unlikely((size_t) size > n)) { - // truncated - size = (int)n; - } + if (unlikely((size_t) size > n)) size = (int)n; - dst[size] = '\0'; return size; } diff --git a/libnetdata/popen/popen.c b/libnetdata/popen/popen.c index fa9dd2b6c0..eaeffd32dd 100644 --- a/libnetdata/popen/popen.c +++ b/libnetdata/popen/popen.c @@ -400,4 +400,4 @@ int mypclose(FILE *fp, pid_t pid) int netdata_spawn_waitpid(pid_t pid) { return custom_pclose(NULL, pid); -}
\ No newline at end of file +} |