diff --git a/plugins/omclickhouse/omclickhouse.c b/plugins/omclickhouse/omclickhouse.c index a46adfc58..f520e4865 100644 --- a/plugins/omclickhouse/omclickhouse.c +++ b/plugins/omclickhouse/omclickhouse.c @@ -859,7 +859,7 @@ BEGINnewActInst CODE_STD_STRING_REQUESTnewActInst(1); CHKiRet(OMSRsetEntry(*ppOMSR, 0, (uchar *)strdup((pData->tplName == NULL) ? " StdClickHouseFmt" : (char *)pData->tplName), - OMSR_RQD_TPL_OPT_SQL)); + OMSR_RQD_TPL_OPT_SQL_BACKSLASH)); if (server != NULL) { CHKiRet(computeBaseUrl((const char *)server, pData->port, pData->useHttps, pData)); diff --git a/runtime/action.c b/runtime/action.c index 83970c996..4cb3ac8d3 100644 --- a/runtime/action.c +++ b/runtime/action.c @@ -2712,6 +2712,20 @@ rsRetVal addAction(action_t **ppAction, "the SQL or stdSQL option in your template!\n"); ABORT_FINALIZE(RS_RET_RQD_TPLOPT_MISSING); } + if ((iTplOpts & OMSR_RQD_TPL_OPT_SQL_BACKSLASH) && (pAction->ppTpl[i]->optFormatEscape != SQL_ESCAPE)) { + errno = 0; + LogError(0, RS_RET_RQD_TPLOPT_MISSING, + "Action disabled. To use this action, you have to specify " + "the SQL option (option.sql=\"on\") in your template!\n"); + ABORT_FINALIZE(RS_RET_RQD_TPLOPT_MISSING); + } + if ((iTplOpts & OMSR_RQD_TPL_OPT_SQL_BACKSLASH) && + (pAction->ppTpl[i]->pStrgen != NULL || pAction->ppTpl[i]->bHaveSubtree)) { + errno = 0; + LogError(0, RS_RET_RQD_TPLOPT_MISSING, + "Action disabled. Backslash-aware SQL escaping requires a string or list template!\n"); + ABORT_FINALIZE(RS_RET_RQD_TPLOPT_MISSING); + } tplNoteUse(pAction->ppTpl[i], iTplOpts & OMSR_TPL_AS_DYNAFILE); } diff --git a/runtime/objomsr.c b/runtime/objomsr.c index 4e8ba0207..5df798806 100644 --- a/runtime/objomsr.c +++ b/runtime/objomsr.c @@ -142,7 +142,8 @@ int OMSRgetEntry(omodStringRequest_t *pThis, int iEntry, uchar **ppTplName, int rsRetVal OMSRgetSupportedTplOpts(unsigned long *pOpts) { DEFiRet; assert(pOpts != NULL); - *pOpts = OMSR_RQD_TPL_OPT_SQL | OMSR_TPL_AS_ARRAY | OMSR_TPL_AS_MSG | OMSR_TPL_AS_JSON | OMSR_TPL_AS_DYNAFILE; + *pOpts = OMSR_RQD_TPL_OPT_SQL | OMSR_TPL_AS_ARRAY | OMSR_TPL_AS_MSG | OMSR_TPL_AS_JSON | OMSR_TPL_AS_DYNAFILE | + OMSR_RQD_TPL_OPT_SQL_BACKSLASH; RETiRet; } diff --git a/runtime/objomsr.h b/runtime/objomsr.h index bc4f565c3..0047bd335 100644 --- a/runtime/objomsr.h +++ b/runtime/objomsr.h @@ -35,7 +35,9 @@ #define OMSR_TPL_AS_JSON 8 /* introduced in 6.5.1, 2012-09-02 */ /** Template is used to render a dynamic file name. */ #define OMSR_TPL_AS_DYNAFILE 16 -/* next option is 32, 64, ... */ +/** Template must use SQL_ESCAPE, which also escapes backslashes. */ +#define OMSR_RQD_TPL_OPT_SQL_BACKSLASH 32 +/* next option is 64, 128, ... */ struct omodStringRequest_s { /* strings requested by output module for doAction() */ int iNumEntries; /* number of array entries for data elements below */ diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 5853837d8..30a225b63 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -253,7 +253,7 @@ static uchar template_FullJSONFmt[] = static uchar template_StdClickHouseFmt[] = "\"INSERT INTO rsyslog.SystemEvents (severity, facility, " "timestamp, hostname, tag, message) VALUES (%syslogseverity%, %syslogfacility%, " - "'%timereported:::date-unixtimestamp%', '%hostname%', '%syslogtag%', '%msg%')\",STDSQL"; + "'%timereported:::date-unixtimestamp%', '%hostname%', '%syslogtag%', '%msg%')\",SQL"; static uchar template_StdOmSenderTrack_senderid[] = "\"%fromhost-ip%\""; /* default template for omsendertrack "senderid" parameter*/ static uchar template_PerSourceKey[] = "\"%hostname%\""; /* default template for per-source ratelimiting */