From nobody Fri Dec 19 21:53:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1619655304; cv=none; d=zohomail.com; s=zohoarc; b=N/pTHbJbNqFk1FQGRc/PB0UWaUZ3rq1HiROHKvw4Uzx6KgovMwncmqLTRcJni/Mt87FuuuMwlyE6s/s14x5Q+JzNI3olW/nFpCVGditCkoGusitdx3Vp/8jjUGRFU9MQ/MiPaYkRhbelZy5Ge73763q8zzlzLuRtDZult11bl+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619655304; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=0XtO/J2QIxV3EsCnIwGPbPpW2RCXziWsO8eq8KNOMcc=; b=iQOcaeIy42SebJaIihPCvkuD2jC2JbmQHOTlthjO5frMf80VHVzdMqBl86Ld3NY0FdipqSxltSAUFEPCCipGqMOXlggqSsODRsC+OK5nCcs5JrX+6RnyeaEfhgGiQyZm5KYA7+XtBrFV9m9gR5yDL0/6fy826hUYGUhw0eLZ71k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619655304364870.0768884365892; Wed, 28 Apr 2021 17:15:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.119616.226194 (Exim 4.92) (envelope-from ) id 1lbuKQ-000786-Lg; Thu, 29 Apr 2021 00:14:50 +0000 Received: by outflank-mailman (output) from mailman id 119616.226194; Thu, 29 Apr 2021 00:14:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lbuKQ-00077z-Ia; Thu, 29 Apr 2021 00:14:50 +0000 Received: by outflank-mailman (input) for mailman id 119616; Thu, 29 Apr 2021 00:14:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lbuKO-00072A-Tq for xen-devel@lists.xenproject.org; Thu, 29 Apr 2021 00:14:48 +0000 Received: from mail-qk1-x736.google.com (unknown [2607:f8b0:4864:20::736]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 436ed0b2-c47d-45a4-a919-3f92849f675e; Thu, 29 Apr 2021 00:14:40 +0000 (UTC) Received: by mail-qk1-x736.google.com with SMTP id o5so65593653qkb.0 for ; Wed, 28 Apr 2021 17:14:40 -0700 (PDT) Received: from localhost.localdomain (c-73-89-138-5.hsd1.vt.comcast.net. [73.89.138.5]) by smtp.gmail.com with ESMTPSA id r185sm1021694qkf.78.2021.04.28.17.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 17:14:39 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 436ed0b2-c47d-45a4-a919-3f92849f675e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=0XtO/J2QIxV3EsCnIwGPbPpW2RCXziWsO8eq8KNOMcc=; b=brDXVwtZ9DOU5zpYvrl7RNpKNGJxeMznujlMSHAqojenCtF9ZFdDnle8brORshOy7M 42qo8z82cPE5wzfyb+2yYp6twrd4mnfILFLsVK+77Pracr3i9pZ6ztpMC99BTMdm1ClA cYKE9wUNf+ykjqnyoqoZIny5xYvuAEi8abL9Bv6/zuc4ztmY6Hr9rK4KeSXqKyojuI83 mC2dAy3kzNXxXwIn1B96GCBBQrpOeBaemjL7aIDEppDSR1t5BREoVz1lQv0cDq0HJchR zI+iRFU2g+no3aAw/asUTOlJ6M7kTf9Jj4nMTw85NAm9DZ8GlLSZFOWPqn0NFfea4Ana CFBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=0XtO/J2QIxV3EsCnIwGPbPpW2RCXziWsO8eq8KNOMcc=; b=rS38t0/Fq5TYiC1cNCFXxkcJwdO32E5vGvGW6xZ2REZ0awie+FmlMl799UV8j9pf+J t7gZqydtFbGaCDOrsMNJH+x0iy/FhumylDnIBTuV/Yh1lSSoTxvVHS9dnMEqG30QdJeW r90Xn0bY5XhailyT4m9OgwbJGLV0Tz0YBthKn3R5BL3bHXIyRWzPr83Jpx5p4+kQtkEP S6diJ9ZYztqGX5B3XpcJsaWtEWOendMgLu8eCi3djim0EY/U7V88bpsQU7QIsh6kQcit CMT6ZIMWhMykaKfKOUkLy1hP87FmFwdzpTZjW8pq+gsd70OZA9wHMkFgLcJ+Ym2urW/R EVXw== X-Gm-Message-State: AOAM5339gN5Vw3hmG8X+/HIXMfyLFRJLeYxkFJC/aVvAcVbhQo6qNFI2 3SA0hVwwgMxa9DHAO9hVwsuzes8LzSk= X-Google-Smtp-Source: ABdhPJzvTftEET+PZK17rrlsHnVK9BhzZX5bMB8KQl6sVY3DdiswQ0xNZIi3w0WOnBBdguaMxlnOJQ== X-Received: by 2002:a37:5a46:: with SMTP id o67mr31675105qkb.240.1619655279544; Wed, 28 Apr 2021 17:14:39 -0700 (PDT) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Cc: Nick Rosbrook , George Dunlap , Ian Jackson , Wei Liu Subject: [PATCH 02/12] golang/xenlight: fix StringList toC conversion Date: Wed, 28 Apr 2021 20:14:24 -0400 Message-Id: <0a15ed9eb6cd70416995f5d9805c98572eb6bd50.1619655104.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: <29e665fc1c9313f5e221e9e5e15d7c2d9c1eb4a7.1619655104.git.rosbrookn@ainfosec.com> References: <29e665fc1c9313f5e221e9e5e15d7c2d9c1eb4a7.1619655104.git.rosbrookn@ainfosec.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The current implementation of StringList.toC does not correctly account for how libxl_string_list is expected to be laid out in C, which is clear when one looks at libxl_string_list_length in libxl.c. In particular, StringList.toC does not account for the extra memory that should be allocated for the "sentinel" entry. And, when using the "slice trick" to create a slice that can address C memory, the unsafe.Pointer conversion should be on a C.libxl_string_list, not *C.libxl_string_list. Fix these problems by (1) allocating an extra slot in the slice used to address the C memory, and explicity set the last entry to nil so the C memory will be zeroed out, and (2) dereferencing csl in the unsafe.Pointer conversion. Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/xenlight.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenl= ight.go index b9189dec5c..13171d0ad1 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -491,13 +491,14 @@ func (sl *StringList) fromC(csl *C.libxl_string_list)= error { =20 func (sl StringList) toC(csl *C.libxl_string_list) error { var char *C.char - size :=3D len(sl) + size :=3D len(sl) + 1 *csl =3D (C.libxl_string_list)(C.malloc(C.ulong(size) * C.ulong(unsafe.Si= zeof(char)))) - clist :=3D (*[1 << 30]*C.char)(unsafe.Pointer(csl))[:size:size] + clist :=3D (*[1 << 30]*C.char)(unsafe.Pointer(*csl))[:size:size] =20 for i, v :=3D range sl { clist[i] =3D C.CString(v) } + clist[len(clist)-1] =3D nil =20 return nil } --=20 2.17.1