From c21c3b0befeb46a51b6bf3758ffa30813bea0ff0 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 9 Mar 2024 14:19:22 +0100 Subject: Adding upstream version 1.44.3. Signed-off-by: Daniel Baumann --- libnetdata/inlined.h | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'libnetdata/inlined.h') diff --git a/libnetdata/inlined.h b/libnetdata/inlined.h index 9c07d97b6..535b791e3 100644 --- a/libnetdata/inlined.h +++ b/libnetdata/inlined.h @@ -426,13 +426,24 @@ static inline void sanitize_json_string(char *dst, const char *src, size_t dst_s } static inline bool sanitize_command_argument_string(char *dst, const char *src, size_t dst_size) { + if(dst_size) + *dst = '\0'; + // skip leading dashes - while (src[0] == '-') + while (*src == '-') src++; - // escape single quotes - while (src[0] != '\0') { - if (src[0] == '\'') { + while (*src != '\0') { + if (dst_size < 1) + return false; + + if (iscntrl(*src) || *src == '$') { + // remove control characters and characters that are expanded by bash + *dst++ = '_'; + dst_size--; + } + else if (*src == '\'' || *src == '`') { + // escape single quotes if (dst_size < 4) return false; @@ -440,14 +451,10 @@ static inline bool sanitize_command_argument_string(char *dst, const char *src, dst += 4; dst_size -= 4; - } else { - if (dst_size < 1) - return false; - - dst[0] = src[0]; - - dst += 1; - dst_size -= 1; + } + else { + *dst++ = *src; + dst_size--; } src++; @@ -456,6 +463,7 @@ static inline bool sanitize_command_argument_string(char *dst, const char *src, // make sure we have space to terminate the string if (dst_size == 0) return false; + *dst = '\0'; return true; @@ -531,10 +539,6 @@ static inline int read_single_base64_or_hex_number_file(const char *filename, un } } -static inline int uuid_memcmp(const uuid_t *uu1, const uuid_t *uu2) { - return memcmp(uu1, uu2, sizeof(uuid_t)); -} - static inline char *strsep_skip_consecutive_separators(char **ptr, char *s) { char *p = (char *)""; while (p && !p[0] && *ptr) p = strsep(ptr, s); -- cgit v1.2.3