From patchwork Mon Oct 7 21:49:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 175426 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4846037ill; Mon, 7 Oct 2019 14:49:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPHVdpFnRfvXywP4wp4lYBWBLT+sIW1Aop+48q/iosCjhv5IoPP6KzfPpANQIT7cs1J2MB X-Received: by 2002:a92:d0c6:: with SMTP id y6mr30322830ila.307.1570484996480; Mon, 07 Oct 2019 14:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570484996; cv=none; d=google.com; s=arc-20160816; b=oNnEzJQqZPHR3tAI/71RTdyDhm8ddSFCWIGZWB+2H6ZKTOFdOgHeW2QDOQb98Ey2qB zbXPDNt5D6/UUWwCvi6CGygcVR6IAEnj9jf8zHVYkmWcyDBht2ZKCvJohAjzzE/2/3oh 9wpJCtGG7j1zdJW1UUYzovF4x7hicgpkdX8rfB38Xr4R/YkthaFwoSSbjL0/xAdyV5yN SM56c+SxmInAHYI6ZxRMwLRy1UzTDZw9yLtI/7rnJJYSVn8juE04NZhI21LhDyZOADLC qQmoXXE9xhBpwP4u/dWXjbRZaG+8jKMiZPSqLL6ZegOZE2ozXvC3H/Zu60fmq+ADbPXY 2tSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=WElK69WwTq5tW09hwRCCPa6mz5lhrDBfTZ5pUXY1PIQ=; b=ruj2OVdLi66JEru451J3nQtNiZ+tP+bdrfoC2+QBi4Wddyr+OxuQcZej5l8EjPjNSU Qjqr4WfIgcC/qgAkOIMZk8WmtR3DsFPaBim0m/7JZmPzq4SV7XqQkwgTyiZWGSIFODO0 wemDI5s/JNZtcSwi/d3HATUGblEK+6GvvKL5x2K2wfEzFxRyP9zne7Djyjuxjj0W/atz tsgArPzzux7r2EPiM8H8FSxuvX79NA6kkmoxYt2f5J8vsgi70o7/C37Va967s2l/V/2g irykcv5dvMYTGF83llUOJx4TaZYsRm8wH6mPV5U/WjMb0bpRrxtHb5S4WJsaGRUuNGTm 81uQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id j15si17936508jad.5.2019.10.07.14.49.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2019 14:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F7EB308FC22; Mon, 7 Oct 2019 21:49:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1CA9E5C240; Mon, 7 Oct 2019 21:49:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D3E8A4EE75; Mon, 7 Oct 2019 21:49:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x97LnVoD014614 for ; Mon, 7 Oct 2019 17:49:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB0185C219; Mon, 7 Oct 2019 21:49:31 +0000 (UTC) Delivered-To: libvir-list@redhat.com Received: from worklaptop.redhat.com (ovpn-123-156.rdu2.redhat.com [10.10.123.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D2D05C1D4; Mon, 7 Oct 2019 21:49:31 +0000 (UTC) From: Cole Robinson To: libvir-list@redhat.com Date: Mon, 7 Oct 2019 17:49:26 -0400 Message-Id: <16d9ed51f14f1c74afce25c58aeedd85b0ec6daa.1570482718.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/30] storagefile: Fix backing format \0 check X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 07 Oct 2019 21:49:55 +0000 (UTC) >From qemu.git docs/interop/qcow2.txt == String header extensions == Some header extensions (such as the backing file format name and the external data file name) are just a single string. In this case, the header extension length is the string length and the string is not '\0' terminated. (The header extension padding can make it look like a string is '\0' terminated, but neither is padding always necessary nor is there a guarantee that zero bytes are used for padding.) So we shouldn't be checking for a \0 byte at the end of the backing format section. I think in practice there always is a \0 but we shouldn't depend on that. Signed-off-by: Cole Robinson --- src/util/virstoragefile.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) -- 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 8cd576a463..5a4e4b24ae 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -506,13 +506,18 @@ qcow2GetExtensions(const char *buf, case QCOW2_HDR_EXTENSION_END: goto done; - case QCOW2_HDR_EXTENSION_BACKING_FORMAT: - if (buf[offset+len] != '\0') - break; - *backingFormat = virStorageFileFormatTypeFromString(buf+offset); + case QCOW2_HDR_EXTENSION_BACKING_FORMAT: { + VIR_AUTOFREE(char *) tmp = NULL; + if (VIR_ALLOC_N(tmp, len + 1) < 0) + return -1; + memcpy(tmp, buf + offset, len); + tmp[len] = '\0'; + + *backingFormat = virStorageFileFormatTypeFromString(tmp); if (*backingFormat <= VIR_STORAGE_FILE_NONE) return -1; } + } offset += len; }