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 68150C433E0 for ; Tue, 9 Jun 2020 13:01:17 +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 3D5222067B for ; Tue, 9 Jun 2020 13:01:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D5222067B 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 1jidrs-0006Ej-1F; Tue, 09 Jun 2020 13:00:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jidrq-0006Ee-97 for xen-devel@lists.xenproject.org; Tue, 09 Jun 2020 13:00:38 +0000 X-Inumbo-ID: 362cc180-aa51-11ea-b7bb-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 362cc180-aa51-11ea-b7bb-bc764e2007e4; Tue, 09 Jun 2020 13:00:37 +0000 (UTC) Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: FLHfnbZ19HU5+V4aYCNCFuh8XHpbMIyH5L+DLjdAW7PjoV8RS19U2IBMAAKShMUBg+4qCn4V4F a5MlxdWNfXkhNW7hnE2n7g6wqjRdORcpcdeObt0XlzBNSC9W94nAhroxXgEMpYmycKeSj1+L+2 ZnXsVYbx8GDlhZ81qVyYqRUoN+8Rh7UqDQ3AaqLClW5EEfUV8bpmY1sMI4hIt7pf4MU1AGk+C7 OMJeSCwudICq9jAnDct0hOUtidcMdWSdRPfk4jPTOpfiZMP/Om3IsYn2mM4M5n5xSXkusPem1R tVM= X-SBRS: 2.7 X-MesageID: 19868725 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,492,1583211600"; d="scan'208";a="19868725" From: Ian Jackson MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-ID: <24287.34799.645497.809135@mariner.uk.xensource.com> Date: Tue, 9 Jun 2020 14:00:31 +0100 To: Olaf Hering Subject: Re: [PATCH v2] libxl__prepare_sockaddr_un In-Reply-To: <20200608182539.29415-1-olaf@aepfle.de> References: <20200608182539.29415-1-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 ("[PATCH v2] libxl__prepare_sockaddr_un"): > libxl: remove usage of strncpy from libxl__prepare_sockaddr_un > > The runtime check for the length of path already prevents malfunction. > But gcc does not detect this runtime check and reports incorrect > usage of strncpy. Remove the usage of strncpy and work directly with > the calculated path length. > > In file included from /usr/include/string.h:495, > from libxl_internal.h:38, > from libxl_utils.c:20: > In function 'strncpy', > inlined from 'libxl__prepare_sockaddr_un' at libxl_utils.c:1262:5: > /usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 108 equals destination size [-Werror=stringop-truncation] > 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > cc1: all warnings being treated as errors Thanks for working on this. I found this code a bit confusing: > - if (sizeof(un->sun_path) <= strlen(path)) { > + size_t len = strlen(path); > + > + if (sizeof(un->sun_path) <= len) { > LOG(ERROR, "UNIX socket path '%s' is too long for %s", path, what); > - LOG(DEBUG, "Path must be less than %zu bytes", sizeof(un->sun_path)); > + LOG(DEBUG, "Path of len %zu must be less than %zu bytes", len, sizeof(un->sun_path)); > return ERROR_INVAL; > } > memset(un, 0, sizeof(struct sockaddr_un)); > un->sun_family = AF_UNIX; > - strncpy(un->sun_path, path, sizeof(un->sun_path)); > + memcpy(un->sun_path, path, len); This does not copy the trailing nul. The reader must read up to see the call to memset. Why do you not use strcpy here ? Nevertheless, as this is a minor point of style, Reviewed-by: Ian Jackson Ian.