summaryrefslogtreecommitdiffstats
path: root/grammar
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-07-09 09:43:06 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-07-09 09:43:06 +0200
commit59f8ebdba75d693f7b462f51b7b50136b590dea7 (patch)
tree78f1c393bcfdb7a7bba9d57a9e2ceeba8dbce7b0 /grammar
parentf5e0bbe2d9d1d9594a01fc869392374d1a44afbe (diff)
downloadrsyslog-59f8ebdba75d693f7b462f51b7b50136b590dea7.tar.gz
rsyslog-59f8ebdba75d693f7b462f51b7b50136b590dea7.tar.xz
rsyslog-59f8ebdba75d693f7b462f51b7b50136b590dea7.zip
checking number of parameters provided to function
Diffstat (limited to 'grammar')
-rw-r--r--grammar/rainerscript.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index 41107de5..f8809e13 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -398,6 +398,8 @@ doFuncCall(struct cnffunc *func, struct exprret *ret, void* usrptr)
(unsigned) func->fID, fname);
free(fname);
}
+ ret->datatype = 'N';
+ ret->d.n = 0;
}
}
@@ -972,18 +974,46 @@ cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next)
return lst;
}
+/* Obtain function id from name AND number of params. Issues the
+ * relevant error messages if errors are detected.
+ */
static inline enum cnffuncid
-funcName2ID(es_str_t *fname)
+funcName2ID(es_str_t *fname, unsigned short nParams)
{
if(!es_strbufcmp(fname, (unsigned char*)"strlen", sizeof("strlen") - 1)) {
+ if(nParams != 1) {
+ parser_errmsg("number of parameters for strlen() must be one "
+ "but is %d.", nParams);
+ return CNFFUNC_INVALID;
+ }
return CNFFUNC_STRLEN;
} else if(!es_strbufcmp(fname, (unsigned char*)"getenv", sizeof("getenv") - 1)) {
+ if(nParams != 1) {
+ parser_errmsg("number of parameters for getenv() must be one "
+ "but is %d.", nParams);
+ return CNFFUNC_INVALID;
+ }
return CNFFUNC_GETENV;
} else if(!es_strbufcmp(fname, (unsigned char*)"tolower", sizeof("tolower") - 1)) {
+ if(nParams != 1) {
+ parser_errmsg("number of parameters for tolower() must be one "
+ "but is %d.", nParams);
+ return CNFFUNC_INVALID;
+ }
return CNFFUNC_TOLOWER;
} else if(!es_strbufcmp(fname, (unsigned char*)"cstr", sizeof("cstr") - 1)) {
+ if(nParams != 1) {
+ parser_errmsg("number of parameters for cstr() must be one "
+ "but is %d.", nParams);
+ return CNFFUNC_INVALID;
+ }
return CNFFUNC_CSTR;
} else if(!es_strbufcmp(fname, (unsigned char*)"cnum", sizeof("cnum") - 1)) {
+ if(nParams != 1) {
+ parser_errmsg("number of parameters for cnum() must be one "
+ "but is %d.", nParams);
+ return CNFFUNC_INVALID;
+ }
return CNFFUNC_CNUM;
} else {
return CNFFUNC_INVALID;
@@ -1007,7 +1037,7 @@ cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst)
func->nodetype = 'F';
func->fname = fname;
func->nParams = nParams;
- func->fID = funcName2ID(fname);
+ func->fID = funcName2ID(fname, nParams);
/* shuffle params over to array (access speed!) */
param = paramlst;
for(i = 0 ; i < nParams ; ++i) {