#include <common/macros.h>
+#define WIDTH_u64_SCANF_IS_A_BROKEN_API "20"
+#define WIDTH_o64_SCANF_IS_A_BROKEN_API "22"
+#define WIDTH_x64_SCANF_IS_A_BROKEN_API "17"
+#define WIDTH_lg_SCANF_IS_A_BROKEN_API "4096" /* Hugely optimistic approximation */
+
LTTNG_HIDDEN
int yydebug;
LTTNG_HIDDEN
int filter_parser_debug = 0;
LTTNG_HIDDEN
-int yyparse(struct filter_parser_ctx *parser_ctx);
+int yyparse(struct filter_parser_ctx *parser_ctx, yyscan_t scanner);
LTTNG_HIDDEN
-int yylex(union YYSTYPE *yyval, struct filter_parser_ctx *parser_ctx);
+int yylex(union YYSTYPE *yyval, yyscan_t scanner);
LTTNG_HIDDEN
int yylex_init_extra(struct filter_parser_ctx *parser_ctx, yyscan_t * ptr_yy_globals);
LTTNG_HIDDEN
for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
alloclen *= 2);
- gstr = malloc(alloclen);
+ gstr = zmalloc(alloclen);
+ if (!gstr) {
+ goto end;
+ }
cds_list_add(&gstr->gc, &parser_ctx->allocated_strings);
gstr->alloclen = alloclen;
+end:
return gstr;
}
struct filter_ast *ast = filter_parser_get_ast(scanner);
struct filter_node *node;
- node = malloc(sizeof(*node));
+ node = zmalloc(sizeof(*node));
if (!node)
return NULL;
memset(node, 0, sizeof(*node));
struct filter_ast *ast = filter_parser_get_ast(scanner);
struct filter_node *node;
- node = malloc(sizeof(*node));
+ node = zmalloc(sizeof(*node));
if (!node)
return NULL;
memset(node, 0, sizeof(*node));
}
LTTNG_HIDDEN
-void yyerror(struct filter_parser_ctx *parser_ctx, const char *str)
+void yyerror(struct filter_parser_ctx *parser_ctx, yyscan_t scanner, const char *str)
{
fprintf(stderr, "error %s\n", str);
}
#define parse_error(parser_ctx, str) \
do { \
- yyerror(parser_ctx, YY_("parse error: " str "\n")); \
+ yyerror(parser_ctx, parser_ctx->scanner, YY_("parse error: " str "\n")); \
YYERROR; \
} while (0)
{
struct filter_ast *ast;
- ast = malloc(sizeof(*ast));
+ ast = zmalloc(sizeof(*ast));
if (!ast)
return NULL;
memset(ast, 0, sizeof(*ast));
LTTNG_HIDDEN
int filter_parser_ctx_append_ast(struct filter_parser_ctx *parser_ctx)
{
- return yyparse(parser_ctx);
+ return yyparse(parser_ctx, parser_ctx->scanner);
}
LTTNG_HIDDEN
yydebug = filter_parser_debug;
- parser_ctx = malloc(sizeof(*parser_ctx));
+ parser_ctx = zmalloc(sizeof(*parser_ctx));
if (!parser_ctx)
return NULL;
memset(parser_ctx, 0, sizeof(*parser_ctx));
%define api.pure
/* %locations */
%parse-param {struct filter_parser_ctx *parser_ctx}
-%lex-param {struct filter_parser_ctx *parser_ctx}
+%parse-param {yyscan_t scanner}
+%lex-param {yyscan_t scanner}
%start translation_unit
%token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE
%token ESCSEQ CHAR_STRING_TOKEN
{
$$ = make_node(parser_ctx, NODE_EXPRESSION);
$$->u.expression.type = AST_EXP_CONSTANT;
- sscanf(yylval.gs->s, "%" PRIu64,
- &$$->u.expression.u.constant);
+ if (sscanf(yylval.gs->s, "%" WIDTH_u64_SCANF_IS_A_BROKEN_API SCNu64,
+ &$$->u.expression.u.constant) != 1) {
+ parse_error(parser_ctx, "cannot scanf decimal constant");
+ }
}
| OCTAL_CONSTANT
{
$$ = make_node(parser_ctx, NODE_EXPRESSION);
$$->u.expression.type = AST_EXP_CONSTANT;
- sscanf(yylval.gs->s, "0%" PRIo64,
- &$$->u.expression.u.constant);
+ if (!strcmp(yylval.gs->s, "0")) {
+ $$->u.expression.u.constant = 0;
+ } else if (sscanf(yylval.gs->s, "0%" WIDTH_o64_SCANF_IS_A_BROKEN_API SCNo64,
+ &$$->u.expression.u.constant) != 1) {
+ parse_error(parser_ctx, "cannot scanf octal constant");
+ }
}
| HEXADECIMAL_CONSTANT
{
$$ = make_node(parser_ctx, NODE_EXPRESSION);
$$->u.expression.type = AST_EXP_CONSTANT;
- sscanf(yylval.gs->s, "0x%" PRIx64,
- &$$->u.expression.u.constant);
+ if (sscanf(yylval.gs->s, "0x%" WIDTH_x64_SCANF_IS_A_BROKEN_API SCNx64,
+ &$$->u.expression.u.constant) != 1) {
+ parse_error(parser_ctx, "cannot scanf hexadecimal constant");
+ }
}
| FLOAT_CONSTANT
{
$$ = make_node(parser_ctx, NODE_EXPRESSION);
$$->u.expression.type = AST_EXP_FLOAT_CONSTANT;
- sscanf(yylval.gs->s, "%lg",
- &$$->u.expression.u.float_constant);
+ if (sscanf(yylval.gs->s, "%" WIDTH_lg_SCANF_IS_A_BROKEN_API "lg",
+ &$$->u.expression.u.float_constant) != 1) {
+ parse_error(parser_ctx, "cannot scanf float constant");
+ }
}
| STRING_LITERAL_START DQUOTE
{