Revision 5e2dafeb json-streamer.c

b/json-streamer.c
56 56

  
57 57
    qlist_append(parser->tokens, dict);
58 58

  
59
    if (parser->brace_count < 0 ||
59
    if (type == JSON_ERROR) {
60
        goto out_emit_bad;
61
    } else if (parser->brace_count < 0 ||
60 62
        parser->bracket_count < 0 ||
61 63
        (parser->brace_count == 0 &&
62 64
         parser->bracket_count == 0)) {
63
        parser->brace_count = 0;
64
        parser->bracket_count = 0;
65
        parser->emit(parser, parser->tokens);
66
        QDECREF(parser->tokens);
67
        parser->tokens = qlist_new();
68
        parser->token_size = 0;
65
        goto out_emit;
69 66
    } else if (parser->token_size > MAX_TOKEN_SIZE ||
70 67
               parser->bracket_count > MAX_NESTING ||
71 68
               parser->brace_count > MAX_NESTING) {
72 69
        /* Security consideration, we limit total memory allocated per object
73 70
         * and the maximum recursion depth that a message can force.
74 71
         */
75
        parser->brace_count = 0;
76
        parser->bracket_count = 0;
77
        parser->emit(parser, parser->tokens);
72
        goto out_emit;
73
    }
74

  
75
    return;
76

  
77
out_emit_bad:
78
    /* clear out token list and tell the parser to emit and error
79
     * indication by passing it a NULL list
80
     */
81
    QDECREF(parser->tokens);
82
    parser->tokens = NULL;
83
out_emit:
84
    /* send current list of tokens to parser and reset tokenizer */
85
    parser->brace_count = 0;
86
    parser->bracket_count = 0;
87
    parser->emit(parser, parser->tokens);
88
    if (parser->tokens) {
78 89
        QDECREF(parser->tokens);
79
        parser->tokens = qlist_new();
80
        parser->token_size = 0;
81 90
    }
91
    parser->tokens = qlist_new();
92
    parser->token_size = 0;
82 93
}
83 94

  
84 95
void json_message_parser_init(JSONMessageParser *parser,

Also available in: Unified diff