Validate module metadata to be an object (#2357)
This commit is contained in:
1 parent
5dacc6b3a1
commit
6d694a4a58
7 files changed
+1702
-1389
No files matched your search
@@ -514,6 +514,7 @@ jv block_list_funcs(block body, int omit_underscores) {
|
||||
}
|
||||
|
||||
block gen_module(block metadata) {
|
||||
assert(block_is_const(metadata) && block_const_kind(metadata) == JV_KIND_OBJECT);
|
||||
inst* i = inst_new(MODULEMETA);
|
||||
i->imm.constant = block_const(metadata);
|
||||
if (jv_get_kind(i->imm.constant) != JV_KIND_OBJECT)
|
||||
|
||||
+18
-17
@@ -1,6 +1,6 @@
|
||||
#line 2 "src/lexer.c"
|
||||
#line 1 "src/lexer.c"
|
||||
|
||||
#line 4 "src/lexer.c"
|
||||
#line 3 "src/lexer.c"
|
||||
|
||||
#define YY_INT_ALIGNED short int
|
||||
|
||||
@@ -281,6 +281,7 @@ typedef int16_t flex_int16_t;
|
||||
typedef uint16_t flex_uint16_t;
|
||||
typedef int32_t flex_int32_t;
|
||||
typedef uint32_t flex_uint32_t;
|
||||
typedef uint64_t flex_uint64_t;
|
||||
#else
|
||||
typedef signed char flex_int8_t;
|
||||
typedef short int flex_int16_t;
|
||||
@@ -445,7 +446,7 @@ struct yy_buffer_state
|
||||
/* Number of characters read into yy_ch_buf, not including EOB
|
||||
* characters.
|
||||
*/
|
||||
int yy_n_chars;
|
||||
yy_size_t yy_n_chars;
|
||||
|
||||
/* Whether we "own" the buffer - i.e., we know we created it,
|
||||
* and can realloc() it to grow it, and should free() it to
|
||||
@@ -522,7 +523,7 @@ static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner
|
||||
|
||||
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
|
||||
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
|
||||
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
|
||||
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner );
|
||||
|
||||
void *yyalloc ( yy_size_t , yyscan_t yyscanner );
|
||||
void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
|
||||
@@ -569,7 +570,7 @@ static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
|
||||
*/
|
||||
#define YY_DO_BEFORE_ACTION \
|
||||
yyg->yytext_ptr = yy_bp; \
|
||||
yyleng = (int) (yy_cp - yy_bp); \
|
||||
yyleng = (yy_size_t) (yy_cp - yy_bp); \
|
||||
yyg->yy_hold_char = *yy_cp; \
|
||||
*yy_cp = '\0'; \
|
||||
yyg->yy_c_buf_p = yy_cp;
|
||||
@@ -842,8 +843,8 @@ struct yyguts_t
|
||||
size_t yy_buffer_stack_max; /**< capacity of stack. */
|
||||
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
|
||||
char yy_hold_char;
|
||||
int yy_n_chars;
|
||||
int yyleng_r;
|
||||
yy_size_t yy_n_chars;
|
||||
yy_size_t yyleng_r;
|
||||
char *yy_c_buf_p;
|
||||
int yy_init;
|
||||
int yy_start;
|
||||
@@ -900,7 +901,7 @@ FILE *yyget_out ( yyscan_t yyscanner );
|
||||
|
||||
void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
|
||||
|
||||
int yyget_leng ( yyscan_t yyscanner );
|
||||
yy_size_t yyget_leng ( yyscan_t yyscanner );
|
||||
|
||||
char *yyget_text ( yyscan_t yyscanner );
|
||||
|
||||
@@ -985,7 +986,7 @@ static int input ( yyscan_t yyscanner );
|
||||
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
|
||||
{ \
|
||||
int c = '*'; \
|
||||
int n; \
|
||||
yy_size_t n; \
|
||||
for ( n = 0; n < max_size && \
|
||||
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
|
||||
buf[n] = (char) c; \
|
||||
@@ -1636,7 +1637,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
|
||||
|
||||
else
|
||||
{
|
||||
int num_to_read =
|
||||
yy_size_t num_to_read =
|
||||
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
|
||||
|
||||
while ( num_to_read <= 0 )
|
||||
@@ -1650,7 +1651,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
|
||||
|
||||
if ( b->yy_is_our_buffer )
|
||||
{
|
||||
int new_size = b->yy_buf_size * 2;
|
||||
yy_size_t new_size = b->yy_buf_size * 2;
|
||||
|
||||
if ( new_size <= 0 )
|
||||
b->yy_buf_size += b->yy_buf_size / 8;
|
||||
@@ -1708,7 +1709,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
|
||||
|
||||
if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
|
||||
/* Extend the array by 50%, plus the number we really need. */
|
||||
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
|
||||
yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
|
||||
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
|
||||
(void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
|
||||
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
|
||||
@@ -1815,7 +1816,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
|
||||
|
||||
else
|
||||
{ /* need more input */
|
||||
int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
|
||||
yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
|
||||
++yyg->yy_c_buf_p;
|
||||
|
||||
switch ( yy_get_next_buffer( yyscanner ) )
|
||||
@@ -2193,12 +2194,12 @@ YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
|
||||
* @param yyscanner The scanner object.
|
||||
* @return the newly allocated buffer state object.
|
||||
*/
|
||||
YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
|
||||
YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
|
||||
{
|
||||
YY_BUFFER_STATE b;
|
||||
char *buf;
|
||||
yy_size_t n;
|
||||
int i;
|
||||
yy_size_t i;
|
||||
|
||||
/* Get memory for full buffer, including space for trailing EOB's. */
|
||||
n = (yy_size_t) (_yybytes_len + 2);
|
||||
@@ -2283,7 +2284,7 @@ static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
|
||||
do \
|
||||
{ \
|
||||
/* Undo effects of setting up yytext. */ \
|
||||
int yyless_macro_arg = (n); \
|
||||
yy_size_t yyless_macro_arg = (n); \
|
||||
YY_LESS_LINENO(yyless_macro_arg);\
|
||||
yytext[yyleng] = yyg->yy_hold_char; \
|
||||
yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
|
||||
@@ -2351,7 +2352,7 @@ FILE *yyget_out (yyscan_t yyscanner)
|
||||
/** Get the length of the current token.
|
||||
* @param yyscanner The scanner object.
|
||||
*/
|
||||
int yyget_leng (yyscan_t yyscanner)
|
||||
yy_size_t yyget_leng (yyscan_t yyscanner)
|
||||
{
|
||||
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
|
||||
return yyleng;
|
||||
|
||||
+6
-5
@@ -2,9 +2,9 @@
|
||||
#define jq_yyHEADER_H 1
|
||||
#define jq_yyIN_HEADER 1
|
||||
|
||||
#line 6 "src/lexer.h"
|
||||
#line 5 "src/lexer.h"
|
||||
|
||||
#line 8 "src/lexer.h"
|
||||
#line 7 "src/lexer.h"
|
||||
|
||||
#define YY_INT_ALIGNED short int
|
||||
|
||||
@@ -285,6 +285,7 @@ typedef int16_t flex_int16_t;
|
||||
typedef uint16_t flex_uint16_t;
|
||||
typedef int32_t flex_int32_t;
|
||||
typedef uint32_t flex_uint32_t;
|
||||
typedef uint64_t flex_uint64_t;
|
||||
#else
|
||||
typedef signed char flex_int8_t;
|
||||
typedef short int flex_int16_t;
|
||||
@@ -398,7 +399,7 @@ struct yy_buffer_state
|
||||
/* Number of characters read into yy_ch_buf, not including EOB
|
||||
* characters.
|
||||
*/
|
||||
int yy_n_chars;
|
||||
yy_size_t yy_n_chars;
|
||||
|
||||
/* Whether we "own" the buffer - i.e., we know we created it,
|
||||
* and can realloc() it to grow it, and should free() it to
|
||||
@@ -442,7 +443,7 @@ void yypop_buffer_state ( yyscan_t yyscanner );
|
||||
|
||||
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
|
||||
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
|
||||
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
|
||||
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner );
|
||||
|
||||
void *yyalloc ( yy_size_t , yyscan_t yyscanner );
|
||||
void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
|
||||
@@ -500,7 +501,7 @@ FILE *yyget_out ( yyscan_t yyscanner );
|
||||
|
||||
void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
|
||||
|
||||
int yyget_leng ( yyscan_t yyscanner );
|
||||
yy_size_t yyget_leng ( yyscan_t yyscanner );
|
||||
|
||||
char *yyget_text ( yyscan_t yyscanner );
|
||||
|
||||
|
||||
+1598
-1311
File diff suppressed because it is too large.
Load diff
+71
-56
@@ -1,8 +1,9 @@
|
||||
/* A Bison parser, made by GNU Bison 3.0.4. */
|
||||
/* A Bison parser, made by GNU Bison 3.8.2. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -15,7 +16,7 @@
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
@@ -30,6 +31,10 @@
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
|
||||
especially those whose name start with YY_ or yy_. They are
|
||||
private implementation details that can be changed or removed. */
|
||||
|
||||
#ifndef YY_YY_SRC_PARSER_H_INCLUDED
|
||||
# define YY_YY_SRC_PARSER_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
@@ -40,7 +45,7 @@
|
||||
extern int yydebug;
|
||||
#endif
|
||||
/* "%code requires" blocks. */
|
||||
#line 11 "src/parser.y" /* yacc.c:1909 */
|
||||
#line 11 "src/parser.y"
|
||||
|
||||
#include "locfile.h"
|
||||
struct lexer_param;
|
||||
@@ -57,61 +62,70 @@ struct lexer_param;
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#line 61 "src/parser.h" /* yacc.c:1909 */
|
||||
#line 66 "src/parser.h"
|
||||
|
||||
/* Token type. */
|
||||
/* Token kinds. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
enum yytokentype
|
||||
{
|
||||
INVALID_CHARACTER = 258,
|
||||
IDENT = 259,
|
||||
FIELD = 260,
|
||||
LITERAL = 261,
|
||||
FORMAT = 262,
|
||||
REC = 263,
|
||||
SETMOD = 264,
|
||||
EQ = 265,
|
||||
NEQ = 266,
|
||||
DEFINEDOR = 267,
|
||||
AS = 268,
|
||||
DEF = 269,
|
||||
MODULE = 270,
|
||||
IMPORT = 271,
|
||||
INCLUDE = 272,
|
||||
IF = 273,
|
||||
THEN = 274,
|
||||
ELSE = 275,
|
||||
ELSE_IF = 276,
|
||||
REDUCE = 277,
|
||||
FOREACH = 278,
|
||||
END = 279,
|
||||
AND = 280,
|
||||
OR = 281,
|
||||
TRY = 282,
|
||||
CATCH = 283,
|
||||
LABEL = 284,
|
||||
BREAK = 285,
|
||||
LOC = 286,
|
||||
SETPIPE = 287,
|
||||
SETPLUS = 288,
|
||||
SETMINUS = 289,
|
||||
SETMULT = 290,
|
||||
SETDIV = 291,
|
||||
SETDEFINEDOR = 292,
|
||||
LESSEQ = 293,
|
||||
GREATEREQ = 294,
|
||||
ALTERNATION = 295,
|
||||
QQSTRING_START = 296,
|
||||
QQSTRING_TEXT = 297,
|
||||
QQSTRING_INTERP_START = 298,
|
||||
QQSTRING_INTERP_END = 299,
|
||||
QQSTRING_END = 300,
|
||||
FUNCDEF = 301,
|
||||
NONOPT = 302
|
||||
YYEMPTY = -2,
|
||||
YYEOF = 0, /* "end of file" */
|
||||
YYerror = 256, /* error */
|
||||
YYUNDEF = 257, /* "invalid token" */
|
||||
INVALID_CHARACTER = 258, /* INVALID_CHARACTER */
|
||||
IDENT = 259, /* IDENT */
|
||||
FIELD = 260, /* FIELD */
|
||||
LITERAL = 261, /* LITERAL */
|
||||
FORMAT = 262, /* FORMAT */
|
||||
REC = 263, /* ".." */
|
||||
SETMOD = 264, /* "%=" */
|
||||
EQ = 265, /* "==" */
|
||||
NEQ = 266, /* "!=" */
|
||||
DEFINEDOR = 267, /* "//" */
|
||||
AS = 268, /* "as" */
|
||||
DEF = 269, /* "def" */
|
||||
MODULE = 270, /* "module" */
|
||||
IMPORT = 271, /* "import" */
|
||||
INCLUDE = 272, /* "include" */
|
||||
IF = 273, /* "if" */
|
||||
THEN = 274, /* "then" */
|
||||
ELSE = 275, /* "else" */
|
||||
ELSE_IF = 276, /* "elif" */
|
||||
REDUCE = 277, /* "reduce" */
|
||||
FOREACH = 278, /* "foreach" */
|
||||
END = 279, /* "end" */
|
||||
AND = 280, /* "and" */
|
||||
OR = 281, /* "or" */
|
||||
TRY = 282, /* "try" */
|
||||
CATCH = 283, /* "catch" */
|
||||
LABEL = 284, /* "label" */
|
||||
BREAK = 285, /* "break" */
|
||||
LOC = 286, /* "__loc__" */
|
||||
SETPIPE = 287, /* "|=" */
|
||||
SETPLUS = 288, /* "+=" */
|
||||
SETMINUS = 289, /* "-=" */
|
||||
SETMULT = 290, /* "*=" */
|
||||
SETDIV = 291, /* "/=" */
|
||||
SETDEFINEDOR = 292, /* "//=" */
|
||||
LESSEQ = 293, /* "<=" */
|
||||
GREATEREQ = 294, /* ">=" */
|
||||
ALTERNATION = 295, /* "?//" */
|
||||
QQSTRING_START = 296, /* QQSTRING_START */
|
||||
QQSTRING_TEXT = 297, /* QQSTRING_TEXT */
|
||||
QQSTRING_INTERP_START = 298, /* QQSTRING_INTERP_START */
|
||||
QQSTRING_INTERP_END = 299, /* QQSTRING_INTERP_END */
|
||||
QQSTRING_END = 300, /* QQSTRING_END */
|
||||
FUNCDEF = 301, /* FUNCDEF */
|
||||
NONOPT = 302 /* NONOPT */
|
||||
};
|
||||
typedef enum yytokentype yytoken_kind_t;
|
||||
#endif
|
||||
/* Tokens. */
|
||||
/* Token kinds. */
|
||||
#define YYEMPTY -2
|
||||
#define YYEOF 0
|
||||
#define YYerror 256
|
||||
#define YYUNDEF 257
|
||||
#define INVALID_CHARACTER 258
|
||||
#define IDENT 259
|
||||
#define FIELD 260
|
||||
@@ -160,17 +174,16 @@ struct lexer_param;
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 31 "src/parser.y" /* yacc.c:1909 */
|
||||
#line 31 "src/parser.y"
|
||||
|
||||
jv literal;
|
||||
block blk;
|
||||
|
||||
#line 172 "src/parser.h" /* yacc.c:1909 */
|
||||
};
|
||||
#line 185 "src/parser.h"
|
||||
|
||||
};
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
@@ -192,6 +205,8 @@ struct YYLTYPE
|
||||
|
||||
|
||||
|
||||
|
||||
int yyparse (block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr);
|
||||
|
||||
|
||||
#endif /* !YY_YY_SRC_PARSER_H_INCLUDED */
|
||||
@@ -319,6 +319,10 @@ Module:
|
||||
FAIL(@$, "Module metadata must be constant");
|
||||
$$ = gen_noop();
|
||||
block_free($2);
|
||||
} else if (block_const_kind($2) != JV_KIND_OBJECT) {
|
||||
FAIL(@$, "Module metadata must be an object");
|
||||
$$ = gen_noop();
|
||||
block_free($2);
|
||||
} else {
|
||||
$$ = gen_module($2);
|
||||
}
|
||||
|
||||
@@ -1495,6 +1495,10 @@ null
|
||||
module (.+1); 0
|
||||
jq: error: Module metadata must be constant at <top-level>, line 1:
|
||||
|
||||
%%FAIL
|
||||
module []; 0
|
||||
jq: error: Module metadata must be an object at <top-level>, line 1:
|
||||
|
||||
%%FAIL
|
||||
include "a" (.+1); 0
|
||||
jq: error: Module metadata must be constant at <top-level>, line 1:
|
||||
|
||||
Reference in new issue
Block a user