summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorLuis Fernando Muñoz Mejías <Luis.Fernando.Munoz.Mejias@cern.ch>2010-11-30 13:04:58 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2010-11-30 16:05:23 +0100
commit0b18c17b2850152203ce9db648ce06212ab67157 (patch)
treeac914ba20e142fcd870164c967a4f96a17e42bda /plugins
parentb9151f6a1708b2fb7e9518e73fcf42d86b0364a9 (diff)
downloadrsyslog-0b18c17b2850152203ce9db648ce06212ab67157.tar.gz
rsyslog-0b18c17b2850152203ce9db648ce06212ab67157.tar.xz
rsyslog-0b18c17b2850152203ce9db648ce06212ab67157.zip
Fix a potential missing '\0' on too long strings.
By implementing a trivial strlcpy it's much easier to detect string truncations and react to them. This also gives a noticeable speedup in buffer handling (can be HUGE), since strlcpy() doesn't clear all the buffer entry before writing data. Converted all uses of strncpy() into strlcpy(). Also, we don't need to check for some null pointers, as there are no malloc-like operations in the doAction loop.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/omoracle/omoracle.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/plugins/omoracle/omoracle.c b/plugins/omoracle/omoracle.c
index 48ee1fa4..30b5834b 100644
--- a/plugins/omoracle/omoracle.c
+++ b/plugins/omoracle/omoracle.c
@@ -127,6 +127,13 @@ typedef struct _instanceData {
struct oracle_batch batch;
} instanceData;
+/* To be honest, strlcpy is faster than strncpy and makes very easy to
+ * detect if a message has been truncated. */
+#ifndef strlcpy
+#define strlcpy(dst,src,sz) snprintf((dst), (sz), "%s", (src))
+#endif
+
+
/** Database name, to be filled by the $OmoracleDB directive */
static char* db_name;
/** Database user name, to be filled by the $OmoracleDBUser
@@ -529,7 +536,7 @@ CODE_STD_FINALIZERparseSelectorAct
ENDparseSelectorAct
BEGINdoAction
- int i;
+ int i, sz;
char **params = (char**) ppString[0];
CODESTARTdoAction
@@ -540,9 +547,13 @@ CODESTARTdoAction
for (i = 0; i < pData->batch.arguments && params[i]; i++) {
dbgprintf("batch[%d][%d]=%s\n", i, pData->batch.n, params[i]);
- strncpy(pData->batch.parameters[i][pData->batch.n], params[i],
- pData->batch.param_size);
- CHKmalloc(pData->batch.parameters[i][pData->batch.n]);
+ sz = strlcpy(pData->batch.parameters[i][pData->batch.n],
+ params[i], pData->batch.param_size);
+ if (sz >= pData->batch.param_size)
+ errmsg.LogError(0, NO_ERRCODE,
+ "Possibly truncated %d column of '%s' "
+ "statement: %s", i,
+ pData->txt_statement, params[i]);
}
pData->batch.n++;