author | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Tue, 1 Mar 2016 10:28:16 +0000 (11:28 +0100) | ||
committer | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Tue, 1 Mar 2016 10:28:16 +0000 (11:28 +0100) |
1 | 2 | |||
---|---|---|---|---|
src/daemon/plugin.h | patch | | diff1 | | diff2 | | blob | history |
src/daemon/types_list.c | patch | | diff1 | | diff2 | | blob | history |
src/daemon/utils_subst.c | patch | | diff1 | | diff2 | | blob | history |
src/liboconfig/oconfig.c | patch | | diff1 | | diff2 | | blob | history |
src/processes.c | patch | | diff1 | | diff2 | | blob | history |
src/threshold.c | patch | | diff1 | | diff2 | | blob | history |
src/utils_cmd_flush.c | patch | | diff1 | | diff2 | | blob | history |
src/utils_cmd_getval.c | patch | | diff1 | | diff2 | | blob | history |
src/utils_db_query.c | patch | | diff1 | | diff2 | | blob | history |
diff --cc src/daemon/plugin.h
Simple merge
diff --cc src/daemon/types_list.c
Simple merge
diff --cc src/daemon/utils_subst.c
index 43634df2d6a0a7ef4a8d586b6ea97f6522fb0205,3e554973c7698dc54bd6d32c0d612e11270a1223..cfa1c7642f0d01b5b5bbdfb2be78dbf38bcb6968
+++ b/src/daemon/utils_subst.c
#include "collectd.h"
#include "common.h"
+ #include "utils_subst.h"
-char *subst (char *buf, size_t buflen, const char *string, int off1, int off2,
+char *subst (char *buf, size_t buflen, const char *string, size_t off1, size_t off2,
const char *replacement)
{
- char *buf_ptr = buf;
- size_t len = buflen;
+ char *out = buf;
- if ((NULL == buf) || (0 >= buflen) || (NULL == string)
- || (0 > off1) || (0 > off2) || (off1 > off2)
- || (NULL == replacement))
+ char const *front;
+ char const *back;
+ size_t front_len;
+ size_t replacement_len;
+ size_t back_len;
+
+ if ((NULL == buf) || (0 == buflen) || (NULL == string) || (NULL == replacement))
return NULL;
- sstrncpy (buf_ptr, string,
- ((size_t)off1 + 1 > buflen) ? buflen : (size_t)off1 + 1);
- buf_ptr += off1;
- len -= off1;
+ size_t string_len = strlen (string);
+ if ((off1 > string_len) || (off2 > string_len) || (off1 > off2))
+ return NULL;
- if (0 >= len)
- return buf;
+ front = string;
+ back = string + off2;
+ front_len = off1;
+ replacement_len = strlen (replacement);
+ back_len = strlen (back);
+
+ if (front_len >= buflen) {
+ front_len = buflen - 1;
+ replacement_len = 0;
+ back_len = 0;
+ } else if ((front_len + replacement_len) >= buflen) {
+ replacement_len = buflen - (front_len + 1);
+ back_len = 0;
+ } else if ((front_len + replacement_len + back_len) >= buflen) {
+ back_len = buflen - (front_len + replacement_len + 1);
+ } else {
+ buflen = front_len + replacement_len + back_len + 1;
+ }
+ assert ((front_len + replacement_len + back_len) == (buflen - 1));
- sstrncpy (buf_ptr, replacement, len);
- buf_ptr += strlen (replacement);
- len -= strlen (replacement);
+ if (front_len != 0) {
+ sstrncpy (out, front, front_len + 1);
+ out += front_len;
+ }
- if (0 >= len)
- return buf;
+ if (replacement_len != 0) {
+ sstrncpy (out, replacement, replacement_len + 1);
+ out += replacement_len;
+ }
- sstrncpy (buf_ptr, string + off2, len);
+ if (back_len != 0) {
+ sstrncpy (out, back, back_len + 1);
+ out += back_len;
+ }
+
+ out[0] = 0;
return buf;
} /* subst */
diff --cc src/liboconfig/oconfig.c
Simple merge
diff --cc src/processes.c
Simple merge
diff --cc src/threshold.c
Simple merge
diff --cc src/utils_cmd_flush.c
Simple merge
diff --cc src/utils_cmd_getval.c
Simple merge
diff --cc src/utils_db_query.c
Simple merge