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=-0.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 76BD6C433E2 for ; Mon, 8 Jun 2020 11:01:50 +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 55A5D2078D for ; Mon, 8 Jun 2020 11:01:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55A5D2078D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jiFX5-0007gJ-Me; Mon, 08 Jun 2020 11:01:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jiFX4-0007gB-G1 for xen-devel@lists.xenproject.org; Mon, 08 Jun 2020 11:01:34 +0000 X-Inumbo-ID: 69b973c0-a977-11ea-9b55-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 69b973c0-a977-11ea-9b55-bc764e2007e4; Mon, 08 Jun 2020 11:01:33 +0000 (UTC) Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: ifZbNR964yFrd7XAuIQluGtMgKvTWqNSB6993Gum/pgPe7Uqc5oGoLM63y3R2eYbYKREFstAcN s2I80MPcNDuLLq1L/kMn8POoPpZcOGlcMvde1YPmzO6c5WE/c3kqNBKzbxrFdQTJJ07UAx3mAM INOXYv094s+VMqk6Jr6XXxGiYjQ96UcAPBDioLW2Rh+5MEgG3BAPVl8JqOlRTidhH2IwVDovMV 75AadluaD+5MCyPfBB9iUH3IynthP2IPjD1osyCBR8h/ehweAYTZVcocdAXffa4RVUqz30rTn1 Sk4= X-SBRS: 2.7 X-MesageID: 19811329 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,487,1583211600"; d="scan'208";a="19811329" From: Ian Jackson MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-ID: <24286.6790.983312.672969@mariner.uk.xensource.com> Date: Mon, 8 Jun 2020 12:01:26 +0100 To: Olaf Hering Subject: Re: [PATCH v1] tools: fix usage of strncpy In-Reply-To: <20200608100051.16be834e.olaf@aepfle.de> References: <20200608072855.26589-1-olaf@aepfle.de> <20200608100051.16be834e.olaf@aepfle.de> X-Mailer: VM 8.2.0b under 24.5.1 (i686-pc-linux-gnu) X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , xen-devel@lists.xenproject.org, Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Olaf Hering writes ("Re: [PATCH v1] tools: fix usage of strncpy"): > Am Mon, 8 Jun 2020 09:28:54 +0200 > schrieb Olaf Hering : > > off-by-one error in libxl__prepare_sockaddr_un > > There is none, I had read the code backwards... I have just had the same thoughts but in the opposite order. That is at first I thought this was not a problem, but now I think there is. There are some kernel interfaces where a fixed-size buffer is provided, and the kernel will tolerate a null-terminated string, but will in any case not read beyond the end of the buffer. Anything involving IFNAMSIZ comes to mind. But I think sun_path is not one of those. The manpage I have here says that to be portable you must null-terminate sun_path. I know that there are some implementations where it is possible to pass a longer path, effectively treating sun_path as a trailing vla. Looking at your diff, its effect seems to be to ensure null-termination by truncating overlong paths. I think the right approach is to return an error, not to silently truncate. Ian.