diff --git a/libraries/libapparmor/src/grammar.y b/libraries/libapparmor/src/grammar.y index 0adde6fc0..7eb47cb9e 100644 --- a/libraries/libapparmor/src/grammar.y +++ b/libraries/libapparmor/src/grammar.y @@ -475,34 +475,3 @@ protocol: TOK_QUOTED_STRING } ; %% - -aa_log_record * -_parse_yacc(char *str) -{ - /* yydebug = 1; */ - YY_BUFFER_STATE lex_buf; - yyscan_t scanner; - - aa_log_record *ret_record = malloc(sizeof(aa_log_record)); - - _init_log_record(ret_record); - - if (ret_record == NULL) - return NULL; - -#if (YYDEBUG != 0) - yydebug = 1; -#endif - - struct string_buf string_buf = {.buf = NULL, .buf_len = 0, .buf_alloc = 0}; - - aalogparse_lex_init_extra(&string_buf, &scanner); - lex_buf = aalogparse__scan_string(str, scanner); - /* Ignore return value to return an AA_RECORD_INVALID event */ - (void)aalogparse_parse(scanner, ret_record); - aalogparse__delete_buffer(lex_buf, scanner); - aalogparse_lex_destroy(scanner); - // free(NULL) is a no-op - free(string_buf.buf); - return ret_record; -} diff --git a/libraries/libapparmor/src/libaalogparse.c b/libraries/libapparmor/src/libaalogparse.c index 934eeb258..23b2c9cf7 100644 --- a/libraries/libapparmor/src/libaalogparse.c +++ b/libraries/libapparmor/src/libaalogparse.c @@ -34,13 +34,42 @@ #include #include "parser.h" +#include "grammar.h" +#include "scanner.h" + /* This is mostly just a wrapper around the code in grammar.y */ aa_log_record *parse_record(char *str) { + YY_BUFFER_STATE lex_buf; + yyscan_t scanner; + aa_log_record *ret_record; + if (str == NULL) return NULL; - return _parse_yacc(str); + ret_record = malloc(sizeof(aa_log_record)); + + _init_log_record(ret_record); + + if (ret_record == NULL) + return NULL; + + struct string_buf string_buf = {.buf = NULL, .buf_len = 0, .buf_alloc = 0}; + +#if (YYDEBUG != 0) + /* Warning: this is still a global even in reentrant parsers */ + aalogparse_debug = 1; +#endif + + aalogparse_lex_init_extra(&string_buf, &scanner); + lex_buf = aalogparse__scan_string(str, scanner); + /* Ignore return value to return an AA_RECORD_INVALID event */ + (void)aalogparse_parse(scanner, ret_record); + aalogparse__delete_buffer(lex_buf, scanner); + aalogparse_lex_destroy(scanner); + /* free(NULL) is a no-op */ + free(string_buf.buf); + return ret_record; } void free_record(aa_log_record *record) diff --git a/libraries/libapparmor/src/parser.h b/libraries/libapparmor/src/parser.h index 521debb4b..d81e4fef8 100644 --- a/libraries/libapparmor/src/parser.h +++ b/libraries/libapparmor/src/parser.h @@ -27,7 +27,6 @@ struct string_buf { }; extern void _init_log_record(aa_log_record *record); -extern aa_log_record *_parse_yacc(char *str); extern char *hex_to_string(char *str); extern char *ipproto_to_string(unsigned int proto);