From patchwork Thu Jul 1 09:56:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 12353857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA3A9C11F64 for ; Thu, 1 Jul 2021 09:57:23 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B31B2611C2 for ; Thu, 1 Jul 2021 09:57:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B31B2611C2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aepfle.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.148357.274276 (Exim 4.92) (envelope-from ) id 1lytRd-0001BI-AD; Thu, 01 Jul 2021 09:57:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 148357.274276; Thu, 01 Jul 2021 09:57:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRd-0001Az-4G; Thu, 01 Jul 2021 09:57:17 +0000 Received: by outflank-mailman (input) for mailman id 148357; Thu, 01 Jul 2021 09:57:15 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRb-0004XT-Rv for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:15 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c2f72f25-cc87-4aca-9cb6-6f6e2dcd9778; Thu, 01 Jul 2021 09:56:49 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uf5Mi (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:41 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c2f72f25-cc87-4aca-9cb6-6f6e2dcd9778 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133401; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=tMf89Ke5Bo6A5Pju27XJS58XTaKNVAzyOo/JUVzZcLo=; b=nWvRnJWLur55V1tgXMbgxhtwgiY/CRv+DqprRK4PbMxuavZgH5yfVh6Ft1q6K0pILK ukoX/5a8uZ1sWLc2Dl59Eo1P8rfuFG5CeX1tkPuaiO1Yp13sffMDQCoXL9BtIc88MGxC xaewNcFmtlO6jV0QGeHsyjupGZkh3fhdXtuAVgjL9vjObeMtg+zcORScKLD9Q3q0aIG8 mWLyRU+I9vvlWbHwTxEK9ZiwmNdPdaf07uDSeTPf1nAr36mF38LC/W0irQXludbzbgZW 6zJkmdBGWIhWfs1EdSfjDEE9mss+4Zk9z3hGYyssgufhn2QBpe2er1jvzpcmJYqZ+/2W oLhw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= , Ian Jackson , Wei Liu Subject: [PATCH v20210701 05/40] tools: handle libxl__physmap_info.name properly in convert-legacy-stream Date: Thu, 1 Jul 2021 11:56:00 +0200 Message-Id: <20210701095635.15648-6-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-1-olaf@aepfle.de> MIME-Version: 1.0 The trailing member name[] in libxl__physmap_info is written as a cstring into the stream. The current code does a sanity check if the last byte is zero. This attempt fails with python3.4 because name[-1] returns a type int. As a result the comparison with byte(\00) fails: File "/usr/lib/xen/bin/convert-legacy-stream", line 347, in read_libxl_toolstack raise StreamError("physmap name not NUL terminated") StreamError: physmap name not NUL terminated To handle both python variants the cstring is unpacked into the actual string and the trailing nil. Signed-off-by: Olaf Hering --- tools/python/scripts/convert-legacy-stream | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/python/scripts/convert-legacy-stream b/tools/python/scripts/convert-legacy-stream index 66ee3d2f5d..9003ac4f6d 100755 --- a/tools/python/scripts/convert-legacy-stream +++ b/tools/python/scripts/convert-legacy-stream @@ -336,20 +336,21 @@ def read_libxl_toolstack(vm, data): if len(data) < namelen: raise StreamError("Remaining data too short for physmap name") - name = data[:namelen] + c_string = data[:namelen] data = data[namelen:] # Strip padding off the end of name if twidth == 64: - name = name[:-4] + c_string = c_string[:-4] - if name[-1] != b'\x00': + name, nil = unpack("={0}sB".format(len(c_string) - 1), c_string) + if nil != 0: raise StreamError("physmap name not NUL terminated") root = b"physmap/%x" % (phys, ) kv = [root + b"/start_addr", b"%x" % (start, ), root + b"/size", b"%x" % (size, ), - root + b"/name", name[:-1]] + root + b"/name", name] for key, val in zip(kv[0::2], kv[1::2]): info(" '%s' = '%s'" % (key.decode(), val.decode()))