]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Leave parser untouched if a file could not be successfully parsed
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 02:46:34 +0000 (03:46 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 02:46:34 +0000 (03:46 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y

index 21f9acd85735ac3b88592766c7511db1aa4f7bf9..62d1b5a0c871f8fef044d5437738ec66d4ca1894 100644 (file)
@@ -273,18 +273,29 @@ static char* pakfire_parser_make_canonical_name(const char* name) {
        return buffer;
 }
 
-int pakfire_parser_parse_data(PakfireParser parser, const char* data, size_t len) {
+int pakfire_parser_parse_data(PakfireParser parent, const char* data, size_t len) {
        Pakfire pakfire = pakfire_parser_get_pakfire(parser);
 
        DEBUG(pakfire, "Parsing the following data:\n%s\n", data);
 
+       // Create a new sub-parser
+       PakfireParser parser = pakfire_parser_create(pakfire, parent);
+
        num_lines = 1;
 
        YY_BUFFER_STATE buffer = yy_scan_bytes(data, len);
        int r = yyparse(parser);
        yy_delete_buffer(buffer);
 
+       // If everything was parsed successfully, we merge the sub-parser into
+       // the parent parser. That way, it will be untouched if something could
+       // not be successfully parsed.
+       if (r == 0) {
+               parent = pakfire_parser_merge(parent, parser);
+       }
+
        pakfire_unref(pakfire);
+       pakfire_parser_unref(parser);
 
        return r;
 }