Fix: lttng: uninitialized pointer free'd when no sessiond is present
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-visitor-ir-validate-string.c
CommitLineData
dcd5daf2
JG
1/*
2 * filter-visitor-ir-validate-string.c
3 *
4 * LTTng filter IR validate string
5 *
ab5be9fa 6 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
dcd5daf2 7 *
ab5be9fa 8 * SPDX-License-Identifier: LGPL-2.1-only
dcd5daf2 9 *
dcd5daf2
JG
10 */
11
12#include <stdio.h>
13#include <unistd.h>
14#include <string.h>
15#include <stdlib.h>
16#include <assert.h>
17#include <errno.h>
18#include <inttypes.h>
ed4549a1
DG
19
20#include <common/macros.h>
21
dcd5daf2
JG
22#include "filter-ast.h"
23#include "filter-parser.h"
24#include "filter-ir.h"
25
26enum parse_char_result {
27 PARSE_CHAR_UNKNOWN = -2,
28 PARSE_CHAR_WILDCARD = -1,
29 PARSE_CHAR_NORMAL = 0,
30};
31
32static
33enum parse_char_result parse_char(const char **p)
34{
35 switch (**p) {
36 case '\\':
37 (*p)++;
38 switch (**p) {
39 case '\\':
40 case '*':
41 return PARSE_CHAR_NORMAL;
42 default:
43 return PARSE_CHAR_UNKNOWN;
44 }
45 case '*':
46 return PARSE_CHAR_WILDCARD;
47 default:
48 return PARSE_CHAR_NORMAL;
49 }
50}
51
52static
53int validate_string(struct ir_op *node)
54{
55 switch (node->op) {
56 case IR_OP_UNKNOWN:
57 default:
58 fprintf(stderr, "[error] %s: unknown op type\n", __func__);
59 return -EINVAL;
60
61 case IR_OP_ROOT:
62 return validate_string(node->u.root.child);
63 case IR_OP_LOAD:
64 {
65 int ret = 0;
66
67 if (node->data_type == IR_DATA_STRING) {
68 const char *str;
69
9f449915
PP
70 assert(node->u.load.u.string.value);
71 str = node->u.load.u.string.value;
dcd5daf2 72
dcd5daf2
JG
73 for (;;) {
74 enum parse_char_result res;
75
76 if (!(*str)) {
77 break;
78 }
79
80 res = parse_char(&str);
81 str++;
82
83 switch (res) {
dcd5daf2
JG
84 case PARSE_CHAR_UNKNOWN:
85 ret = -EINVAL;
86 fprintf(stderr,
87 "Unsupported escape character detected.\n");
88 goto end_load;
89 case PARSE_CHAR_NORMAL:
90 default:
91 break;
92 }
93 }
94 }
95end_load:
96 return ret;
97 }
98 case IR_OP_UNARY:
99 return validate_string(node->u.unary.child);
100 case IR_OP_BINARY:
101 {
102 int ret = validate_string(node->u.binary.left);
103
104 if (ret)
105 return ret;
106 return validate_string(node->u.binary.right);
107 }
108 case IR_OP_LOGICAL:
109 {
110 int ret;
111
112 ret = validate_string(node->u.logical.left);
113 if (ret)
114 return ret;
115 return validate_string(node->u.logical.right);
116 }
117 }
118}
119
ed4549a1 120LTTNG_HIDDEN
dcd5daf2
JG
121int filter_visitor_ir_validate_string(struct filter_parser_ctx *ctx)
122{
123 return validate_string(ctx->ir_root);
124}
This page took 0.077523 seconds and 5 git commands to generate.