From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKKWJ-0000FP-7S for qemu-devel@nongnu.org; Tue, 05 Jul 2016 03:11:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKKWD-00058T-RE for qemu-devel@nongnu.org; Tue, 05 Jul 2016 03:11:46 -0400 Received: from [59.151.112.132] (port=6997 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKKWD-000572-B9 for qemu-devel@nongnu.org; Tue, 05 Jul 2016 03:11:41 -0400 Message-ID: <577B5EC2.40709@cn.fujitsu.com> Date: Tue, 5 Jul 2016 15:16:18 +0800 From: Changlong Xie MIME-Version: 1.0 References: <1467636059-12557-1-git-send-email-pbonzini@redhat.com> <20160705065635.GA29307@ad.usersys.redhat.com> In-Reply-To: <20160705065635.GA29307@ad.usersys.redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] json-streamer: fix double-free on exiting during a parse List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , Paolo Bonzini Cc: qemu-devel@nongnu.org, armbru@redhat.com On 07/05/2016 02:56 PM, Fam Zheng wrote: > On Mon, 07/04 14:40, Paolo Bonzini wrote: >> Now that json-streamer tries not to leak tokens on incomplete parse, >> the tokens can be freed twice if QEMU destroys the json-streamer >> object during the parser->emit call. To fix this, create the new >> empty GQueue earlier, so that it is already in place when the old >> one is passed to parser->emit. >> >> Reported-by: Changlong Xie >> Signed-off-by: Paolo Bonzini > > Two meta questions: > > Is there a reproducer and/or test case coverage? tests/qemu-iotests/071 > > Does qemu-stable need this? > http://lists.nongnu.org/archive/html/qemu-devel/2016-07/msg00465.html Thanks -Xie > Fam > >> --- >> qobject/json-streamer.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c >> index 7164390..c51c202 100644 >> --- a/qobject/json-streamer.c >> +++ b/qobject/json-streamer.c >> @@ -39,6 +39,7 @@ static void json_message_process_token(JSONLexer *lexer, GString *input, >> { >> JSONMessageParser *parser = container_of(lexer, JSONMessageParser, lexer); >> JSONToken *token; >> + GQueue *tokens; >> >> switch (type) { >> case JSON_LCURLY: >> @@ -96,9 +97,12 @@ out_emit: >> /* send current list of tokens to parser and reset tokenizer */ >> parser->brace_count = 0; >> parser->bracket_count = 0; >> - /* parser->emit takes ownership of parser->tokens. */ >> - parser->emit(parser, parser->tokens); >> + /* parser->emit takes ownership of parser->tokens. Remove our own >> + * reference to parser->tokens before handing it out to parser->emit. >> + */ >> + tokens = parser->tokens; >> parser->tokens = g_queue_new(); >> + parser->emit(parser, tokens); >> parser->token_size = 0; >> } >> >> -- >> 1.8.3.1 >> >> > > > . >