~ubuntu-branches/ubuntu/utopic/rsyslog/utopic

« back to all changes in this revision

Viewing changes to .pc/CVE-2014-3634.patch/grammar/rainerscript.h

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-10-09 13:01:54 UTC
  • Revision ID: package-import@ubuntu.com-20141009130154-r61ujzd0ufz92td7
Tags: 7.4.4-1ubuntu11
* SECURITY UPDATE: denial of service and possible code execution via
  invalid PRI value
  - debian/patches/CVE-2014-3634.patch: limit PRI values in
    grammar/rainerscript.h, plugins/imfile/imfile.c,
    plugins/imklog/imklog.c, plugins/imkmsg/imkmsg.c,
    plugins/imsolaris/imsolaris.c, plugins/imuxsock/imuxsock.c,
    runtime/msg.c, runtime/parser.c, runtime/rsyslog.h,
    runtime/srutils.c, runtime/syslogd-types.h, runtime/typedefs.h,
    tools/syslogd.c.
  - CVE-2014-3634
  - CVE-2014-3683

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef INC_UTILS_H
 
2
#define INC_UTILS_H
 
3
#include <stdio.h>
 
4
#include <libestr.h>
 
5
#include <typedefs.h>
 
6
#include <sys/types.h>
 
7
#include <regex.h>
 
8
 
 
9
 
 
10
#define LOG_NFACILITIES 24      /* current number of syslog facilities */
 
11
#define CNFFUNC_MAX_ARGS 32
 
12
        /**< maximum number of arguments that any function can have (among
 
13
         *   others, this is used to size data structures).
 
14
         */
 
15
 
 
16
extern int Debug; /* 1 if in debug mode, 0 otherwise -- to be enhanced */
 
17
 
 
18
enum cnfobjType {
 
19
        CNFOBJ_ACTION,
 
20
        CNFOBJ_RULESET,
 
21
        CNFOBJ_GLOBAL,
 
22
        CNFOBJ_INPUT,
 
23
        CNFOBJ_MODULE,
 
24
        CNFOBJ_TPL,
 
25
        CNFOBJ_PROPERTY,
 
26
        CNFOBJ_CONSTANT,
 
27
        CNFOBJ_INVALID = 0
 
28
};
 
29
 
 
30
static inline char*
 
31
cnfobjType2str(enum cnfobjType ot)
 
32
{
 
33
        switch(ot) {
 
34
        case CNFOBJ_ACTION:
 
35
                return "action";
 
36
                break;
 
37
        case CNFOBJ_RULESET:
 
38
                return "ruleset";
 
39
                break;
 
40
        case CNFOBJ_GLOBAL:
 
41
                return "global";
 
42
                break;
 
43
        case CNFOBJ_INPUT:
 
44
                return "input";
 
45
                break;
 
46
        case CNFOBJ_MODULE:
 
47
                return "module";
 
48
                break;
 
49
        case CNFOBJ_TPL:
 
50
                return "template";
 
51
                break;
 
52
        case CNFOBJ_PROPERTY:
 
53
                return "property";
 
54
                break;
 
55
        case CNFOBJ_CONSTANT:
 
56
                return "constant";
 
57
                break;
 
58
        default:return "error: invalid cnfobjType";
 
59
        }
 
60
}
 
61
 
 
62
enum cnfactType { CNFACT_V2, CNFACT_LEGACY };
 
63
 
 
64
/* a variant type, for example used for expression evaluation
 
65
 * 2011-07-15/rger: note that there exists a "legacy" object var_t,
 
66
 * which implements the same idea, but in a suboptimal manner. I have
 
67
 * stipped this down as much as possible, but will keep it for a while
 
68
 * to avoid unnecessary complexity during development. TODO: in the long
 
69
 * term, var_t shall be replaced by struct var.
 
70
 */
 
71
struct var {
 
72
        union {
 
73
                es_str_t *estr;
 
74
                struct cnfarray *ar;
 
75
                long long n;
 
76
                struct json_object *json;
 
77
        } d;
 
78
        char datatype; /* 'N' number, 'S' string, 'J' JSON, 'A' array
 
79
                        * Note: 'A' is only supported during config phase
 
80
                        */
 
81
};
 
82
 
 
83
struct cnfobj {
 
84
        enum cnfobjType objType;
 
85
        struct nvlst *nvlst;
 
86
        struct objlst *subobjs;
 
87
        struct cnfstmt *script;
 
88
};
 
89
 
 
90
struct objlst {
 
91
        struct objlst *next;
 
92
        struct cnfobj *obj;
 
93
};
 
94
 
 
95
struct nvlst {
 
96
  struct nvlst *next;
 
97
  es_str_t *name;
 
98
  struct var val;
 
99
  unsigned char bUsed;
 
100
        /**< was this node used during config processing? If not, this
 
101
         *   indicates an error. After all, the user specified a setting
 
102
         *   that the software does not know.
 
103
         */
 
104
};
 
105
 
 
106
/* the following structures support expressions, and may (very much later
 
107
 * be the sole foundation for the AST.
 
108
 *
 
109
 * nodetypes (list not yet complete)
 
110
 * F - function
 
111
 * N - number
 
112
 * P - fparamlst
 
113
 * R - rule
 
114
 * S - string
 
115
 * V - var
 
116
 * A - (string) array
 
117
 * ... plus the S_* #define's below:
 
118
 */
 
119
#define S_STOP 4000
 
120
#define S_PRIFILT 4001
 
121
#define S_PROPFILT 4002
 
122
#define S_IF 4003
 
123
#define S_ACT 4004
 
124
#define S_NOP 4005      /* usually used to disable some statement */
 
125
#define S_SET 4006
 
126
#define S_UNSET 4007
 
127
#define S_CALL 4008
 
128
 
 
129
enum cnfFiltType { CNFFILT_NONE, CNFFILT_PRI, CNFFILT_PROP, CNFFILT_SCRIPT };
 
130
static inline char*
 
131
cnfFiltType2str(enum cnfFiltType filttype)
 
132
{
 
133
        switch(filttype) {
 
134
        case CNFFILT_NONE:
 
135
                return("filter:none");
 
136
        case CNFFILT_PRI:
 
137
                return("filter:pri");
 
138
        case CNFFILT_PROP:
 
139
                return("filter:prop");
 
140
        case CNFFILT_SCRIPT:
 
141
                return("filter:script");
 
142
        }
 
143
        return("error:invalid_filter_type");    /* should never be reached */
 
144
}
 
145
 
 
146
 
 
147
struct cnfstmt {
 
148
        unsigned nodetype;
 
149
        struct cnfstmt *next;
 
150
        uchar *printable; /* printable text for debugging */
 
151
        union {
 
152
                struct {
 
153
                        struct cnfexpr *expr;
 
154
                        struct cnfstmt *t_then;
 
155
                        struct cnfstmt *t_else;
 
156
                } s_if;
 
157
                struct {
 
158
                        uchar *varname;
 
159
                        struct cnfexpr *expr;
 
160
                } s_set;
 
161
                struct {
 
162
                        uchar *varname;
 
163
                } s_unset;
 
164
                struct {
 
165
                        es_str_t *name;
 
166
                        struct cnfstmt *stmt;
 
167
                } s_call;
 
168
                struct {
 
169
                        uchar pmask[LOG_NFACILITIES+1]; /* priority mask */
 
170
                        struct cnfstmt *t_then;
 
171
                        struct cnfstmt *t_else;
 
172
                } s_prifilt;
 
173
                struct {
 
174
                        fiop_t operation;
 
175
                        regex_t *regex_cache;/* cache for compiled REs, if used */
 
176
                        struct cstr_s *pCSCompValue;/* value to "compare" against */
 
177
                        sbool isNegated;
 
178
                        uintTiny propID;/* ID of the requested property */
 
179
                        es_str_t *propName;/* name of property for CEE-based filters */
 
180
                        struct cnfstmt *t_then;
 
181
                        struct cnfstmt *t_else;
 
182
                } s_propfilt;
 
183
                struct action_s *act;
 
184
        } d;
 
185
};
 
186
 
 
187
struct cnfexpr {
 
188
        unsigned nodetype;
 
189
        struct cnfexpr *l;
 
190
        struct cnfexpr *r;
 
191
};
 
192
 
 
193
struct cnfnumval {
 
194
        unsigned nodetype;
 
195
        long long val;
 
196
};
 
197
 
 
198
struct cnfstringval {
 
199
        unsigned nodetype;
 
200
        es_str_t *estr;
 
201
};
 
202
 
 
203
struct cnfvar {
 
204
        unsigned nodetype;
 
205
        char *name;
 
206
};
 
207
 
 
208
struct cnfarray {
 
209
        unsigned nodetype;
 
210
        int nmemb;
 
211
        es_str_t **arr;
 
212
};
 
213
 
 
214
struct cnffparamlst {
 
215
        unsigned nodetype; /* P */
 
216
        struct cnffparamlst *next;
 
217
        struct cnfexpr *expr;
 
218
};
 
219
 
 
220
enum cnffuncid {
 
221
        CNFFUNC_INVALID = 0, /**< defunct entry, do not use (should normally not be present) */
 
222
        CNFFUNC_NAME = 1,   /**< use name to call function (for future use) */
 
223
        CNFFUNC_STRLEN,
 
224
        CNFFUNC_GETENV,
 
225
        CNFFUNC_TOLOWER,
 
226
        CNFFUNC_CSTR,
 
227
        CNFFUNC_CNUM,
 
228
        CNFFUNC_RE_MATCH,
 
229
        CNFFUNC_RE_EXTRACT,
 
230
        CNFFUNC_FIELD,
 
231
        CNFFUNC_PRIFILT
 
232
};
 
233
 
 
234
struct cnffunc {
 
235
        unsigned nodetype;
 
236
        es_str_t *fname;
 
237
        unsigned short nParams;
 
238
        enum cnffuncid fID; /* function ID for built-ins, 0 means use name */
 
239
        void *funcdata; /* global data for function-specific use (e.g. compiled regex) */
 
240
        struct cnfexpr *expr[];
 
241
};
 
242
 
 
243
/* future extensions
 
244
struct x {
 
245
        int nodetype;
 
246
};
 
247
*/
 
248
 
 
249
 
 
250
/* the following defines describe the parameter block for puling
 
251
 * config parameters. Note that the focus is on ease and saveness of
 
252
 * use, not performance. For example, we address parameters by name
 
253
 * instead of index, because the former is less error-prone. The (severe)
 
254
 * performance hit does not matter, as it is a one-time hit during config
 
255
 * load but never during actual processing. So there is really no reason
 
256
 * to care.
 
257
 */
 
258
struct cnfparamdescr { /* first the param description */
 
259
        char *name;     /**< not a es_str_t to ease definition in code */
 
260
        ecslCmdHdrlType type;
 
261
        unsigned flags;
 
262
};
 
263
/* flags for cnfparamdescr: */
 
264
#define CNFPARAM_REQUIRED 0x0001
 
265
 
 
266
struct cnfparamblk { /* now the actual param block use in API calls */
 
267
        unsigned short version;
 
268
        unsigned short nParams;
 
269
        struct cnfparamdescr *descr;
 
270
};
 
271
#define CNFPARAMBLK_VERSION 1
 
272
        /**< caller must have same version as engine -- else things may
 
273
         * be messed up. But note that we may support multiple versions
 
274
         * inside the engine, if at some later stage we want to do
 
275
         * that. -- rgerhards, 2011-07-15
 
276
         */
 
277
struct cnfparamvals { /* the values we obtained for param descr. */
 
278
        struct var val;
 
279
        unsigned char bUsed;
 
280
};
 
281
 
 
282
struct funcData_prifilt {
 
283
        uchar pmask[LOG_NFACILITIES+1]; /* priority mask */
 
284
};
 
285
 
 
286
 
 
287
int cnfParseBuffer(char *buf, unsigned lenBuf);
 
288
void readConfFile(FILE *fp, es_str_t **str);
 
289
struct objlst* objlstNew(struct cnfobj *obj);
 
290
void objlstDestruct(struct objlst *lst);
 
291
void objlstPrint(struct objlst *lst);
 
292
struct nvlst* nvlstNewArray(struct cnfarray *ar);
 
293
struct nvlst* nvlstNewStr(es_str_t *value);
 
294
struct nvlst* nvlstSetName(struct nvlst *lst, es_str_t *name);
 
295
void nvlstDestruct(struct nvlst *lst);
 
296
void nvlstPrint(struct nvlst *lst);
 
297
void nvlstChkUnused(struct nvlst *lst);
 
298
struct nvlst* nvlstFindName(struct nvlst *lst, es_str_t *name);
 
299
struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst);
 
300
void cnfobjDestruct(struct cnfobj *o);
 
301
void cnfobjPrint(struct cnfobj *o);
 
302
struct cnfexpr* cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r);
 
303
void cnfexprPrint(struct cnfexpr *expr, int indent);
 
304
void cnfexprEval(struct cnfexpr *expr, struct var *ret, void *pusr);
 
305
int cnfexprEvalBool(struct cnfexpr *expr, void *usrptr);
 
306
void cnfexprDestruct(struct cnfexpr *expr);
 
307
struct cnfnumval* cnfnumvalNew(long long val);
 
308
struct cnfstringval* cnfstringvalNew(es_str_t *estr);
 
309
struct cnfvar* cnfvarNew(char *name);
 
310
struct cnffunc * cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst);
 
311
struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next);
 
312
int cnfDoInclude(char *name);
 
313
int cnfparamGetIdx(struct cnfparamblk *params, char *name);
 
314
struct cnfparamvals* nvlstGetParams(struct nvlst *lst, struct cnfparamblk *params,
 
315
               struct cnfparamvals *vals);
 
316
void cnfparamsPrint(struct cnfparamblk *params, struct cnfparamvals *vals);
 
317
int cnfparamvalsIsSet(struct cnfparamblk *params, struct cnfparamvals *vals);
 
318
void varDelete(struct var *v);
 
319
void cnfparamvalsDestruct(struct cnfparamvals *paramvals, struct cnfparamblk *blk);
 
320
struct cnfstmt * cnfstmtNew(unsigned s_type);
 
321
void cnfstmtPrintOnly(struct cnfstmt *stmt, int indent, sbool subtree);
 
322
void cnfstmtPrint(struct cnfstmt *stmt, int indent);
 
323
struct cnfstmt* scriptAddStmt(struct cnfstmt *root, struct cnfstmt *s);
 
324
struct objlst* objlstAdd(struct objlst *root, struct cnfobj *o);
 
325
char *rmLeadingSpace(char *s);
 
326
struct cnfstmt * cnfstmtNewPRIFILT(char *prifilt, struct cnfstmt *t_then);
 
327
struct cnfstmt * cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then);
 
328
struct cnfstmt * cnfstmtNewAct(struct nvlst *lst);
 
329
struct cnfstmt * cnfstmtNewLegaAct(char *actline);
 
330
struct cnfstmt * cnfstmtNewSet(char *var, struct cnfexpr *expr);
 
331
struct cnfstmt * cnfstmtNewUnset(char *var);
 
332
struct cnfstmt * cnfstmtNewCall(es_str_t *name);
 
333
struct cnfstmt * cnfstmtNewContinue(void);
 
334
void cnfstmtDestructLst(struct cnfstmt *root);
 
335
void cnfstmtOptimize(struct cnfstmt *root);
 
336
struct cnfarray* cnfarrayNew(es_str_t *val);
 
337
struct cnfarray* cnfarrayDup(struct cnfarray *old);
 
338
struct cnfarray* cnfarrayAdd(struct cnfarray *ar, es_str_t *val);
 
339
void cnfarrayContentDestruct(struct cnfarray *ar);
 
340
char* getFIOPName(unsigned iFIOP);
 
341
rsRetVal initRainerscript(void);
 
342
void unescapeStr(uchar *s, int len);
 
343
char * tokenval2str(int tok);
 
344
 
 
345
/* debug helper */
 
346
void cstrPrint(char *text, es_str_t *estr);
 
347
#endif