From patchwork Fri Dec 18 16:53:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 558996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D59D01402BD for ; Sat, 19 Dec 2015 04:04:22 +1100 (AEDT) Received: from localhost ([::1]:33820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9yS4-0006OL-KM for incoming@patchwork.ozlabs.org; Fri, 18 Dec 2015 12:04:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9yHg-0004Pq-8V for qemu-devel@nongnu.org; Fri, 18 Dec 2015 11:53:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9yHf-0007T0-8O for qemu-devel@nongnu.org; Fri, 18 Dec 2015 11:53:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9yHf-0007Sm-3B for qemu-devel@nongnu.org; Fri, 18 Dec 2015 11:53:35 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id A8210C0B9329; Fri, 18 Dec 2015 16:53:34 +0000 (UTC) Received: from localhost.localdomain.com (vpn1-6-27.ams2.redhat.com [10.36.6.27]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBIGrUcj025802; Fri, 18 Dec 2015 11:53:33 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 18 Dec 2015 16:53:17 +0000 Message-Id: <1450457600-19865-3-git-send-email-berrange@redhat.com> In-Reply-To: <1450457600-19865-1-git-send-email-berrange@redhat.com> References: <1450457600-19865-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell Subject: [Qemu-devel] [PULL v1 2/5] qemu-char: convert to use error checked base64 decode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Switch from using g_base64_decode over to qbase64_decode in order to get error checking of the base64 input data. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange --- qapi-schema.json | 2 -- qemu-char.c | 8 +++++++- qmp-commands.hx | 2 -- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 516b145..2e31733 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -295,8 +295,6 @@ # @format: #optional data encoding (default 'utf8'). # - base64: data must be base64 encoded text. Its binary # decoding gets written. -# Bug: invalid base64 is currently not rejected. -# Whitespace *is* invalid. # - utf8: data's UTF-8 encoding is written # - data itself is always Unicode regardless of format, like # any other string. diff --git a/qemu-char.c b/qemu-char.c index 66703e3..00a7526 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -32,6 +32,7 @@ #include "qapi/qmp-input-visitor.h" #include "qapi/qmp-output-visitor.h" #include "qapi-visit.h" +#include "qemu/base64.h" #include #include @@ -3264,7 +3265,12 @@ void qmp_ringbuf_write(const char *device, const char *data, } if (has_format && (format == DATA_FORMAT_BASE64)) { - write_data = g_base64_decode(data, &write_count); + write_data = qbase64_decode(data, -1, + &write_count, + errp); + if (!write_data) { + return; + } } else { write_data = (uint8_t *)data; write_count = strlen(data); diff --git a/qmp-commands.hx b/qmp-commands.hx index 6f3a25d..7b235ee 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -512,8 +512,6 @@ Arguments: - "data": data to write (json-string) - "format": data format (json-string, optional) - Possible values: "utf8" (default), "base64" - Bug: invalid base64 is currently not rejected. - Whitespace *is* invalid. Example: