From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDD4u-0003rZ-Bn for qemu-devel@nongnu.org; Fri, 01 Aug 2014 09:41:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDD4j-0007lR-7B for qemu-devel@nongnu.org; Fri, 01 Aug 2014 09:41:00 -0400 Received: from mail-we0-x233.google.com ([2a00:1450:400c:c03::233]:42742) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDD4i-0007kG-Tw for qemu-devel@nongnu.org; Fri, 01 Aug 2014 09:40:49 -0400 Received: by mail-we0-f179.google.com with SMTP id u57so4421387wes.10 for ; Fri, 01 Aug 2014 06:40:47 -0700 (PDT) Sender: Levente Kurusa From: Levente Kurusa Date: Fri, 1 Aug 2014 15:40:00 +0200 Message-Id: <1406900401-19550-3-git-send-email-lkurusa@redhat.com> In-Reply-To: <1406900401-19550-1-git-send-email-lkurusa@redhat.com> References: <1406900401-19550-1-git-send-email-lkurusa@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] block: vpc: introduce vpc_check_signature function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , Stefan Hajnoczi Cc: Andrew Jones , Stefan Weil , Levente Kurusa , Fam Zheng , QEMU Developers Check the signature in a helper function instead of in plain code in order to avoid code duplication Reviewed-by: Andrew Jones Signed-off-by: Levente Kurusa --- block/vpc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 2ba8fc2..a6a7213 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -156,11 +156,15 @@ static uint32_t vpc_checksum(uint8_t* buf, size_t size) return ~res; } +static int vpc_check_signature(const void *buf) +{ + return !strncmp((char *)buf, "conectix", 8); +} static int vpc_probe(BlockDriverState *bs, const uint8_t *buf, int buf_size, const char *filename) { - if (buf_size >= 8 && !strncmp((char *)buf, "conectix", 8)) + if (buf_size >= 8 && vpc_check_signature(buf)) return 100; return 0; } @@ -184,7 +188,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } footer = (VHDFooter *) s->footer_buf; - if (strncmp(footer->creator, "conectix", 8)) { + if (!vpc_check_signature(footer->creator)) { int64_t offset = bdrv_getlength(bs->file); if (offset < 0) { ret = offset; @@ -200,7 +204,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } - if (strncmp(footer->creator, "conectix", 8)) { + if (!vpc_check_signature(footer->creator)) { error_setg(errp, "invalid VPC image"); ret = -EINVAL; goto fail; -- 1.9.3