From owner-svn-src-head@freebsd.org Thu Oct 26 18:32:05 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E6300E507AD; Thu, 26 Oct 2017 18:32:05 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C2B7B644E6; Thu, 26 Oct 2017 18:32:05 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9QIW4Js097215; Thu, 26 Oct 2017 18:32:04 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9QIW4RX097214; Thu, 26 Oct 2017 18:32:04 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201710261832.v9QIW4RX097214@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Thu, 26 Oct 2017 18:32:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325017 - head/sys/contrib/libnv X-SVN-Group: head X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: head/sys/contrib/libnv X-SVN-Commit-Revision: 325017 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Oct 2017 18:32:06 -0000 Author: jilles Date: Thu Oct 26 18:32:04 2017 New Revision: 325017 URL: https://svnweb.freebsd.org/changeset/base/325017 Log: libnv: Fix strict-aliasing violation with cookie In rS323851, some casts were adjusted in calls to nvlist_next() and nvlist_get_pararr() in order to make scan-build happy. I think these changes just confused scan-build into not reporting the strict-aliasing violation. For example, nvlist_xdescriptors() is causing nvlist_next() to write to its local variable nvp of type nvpair_t * using the lvalue *cookiep of type void *, which is not allowed. Given the APIs of nvlist_next(), nvlist_get_parent() and nvlist_get_pararr(), one possible fix is to create a local void *cookie in nvlist_xdescriptors() and other places, and to convert the value to nvpair_t * when necessary. This patch implements that fix. Reviewed by: oshogbo MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D12760 Modified: head/sys/contrib/libnv/nvlist.c Modified: head/sys/contrib/libnv/nvlist.c ============================================================================== --- head/sys/contrib/libnv/nvlist.c Thu Oct 26 17:56:34 2017 (r325016) +++ head/sys/contrib/libnv/nvlist.c Thu Oct 26 18:32:04 2017 (r325017) @@ -707,15 +707,17 @@ out: static int * nvlist_xdescriptors(const nvlist_t *nvl, int *descs) { + void *cookie; nvpair_t *nvp; int type; NVLIST_ASSERT(nvl); PJDLOG_ASSERT(nvl->nvl_error == 0); - nvp = NULL; + cookie = NULL; do { - while (nvlist_next(nvl, &type, (void *)&nvp) != NULL) { + while (nvlist_next(nvl, &type, &cookie) != NULL) { + nvp = cookie; switch (type) { case NV_TYPE_DESCRIPTOR: *descs = nvpair_get_descriptor(nvp); @@ -737,7 +739,7 @@ nvlist_xdescriptors(const nvlist_t *nvl, int *descs) } case NV_TYPE_NVLIST: nvl = nvpair_get_nvlist(nvp); - nvp = NULL; + cookie = NULL; break; case NV_TYPE_NVLIST_ARRAY: { @@ -749,12 +751,12 @@ nvlist_xdescriptors(const nvlist_t *nvl, int *descs) PJDLOG_ASSERT(nitems > 0); nvl = value[0]; - nvp = NULL; + cookie = NULL; break; } } } - } while ((nvl = nvlist_get_pararr(nvl, (void *)&nvp)) != NULL); + } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL); return (descs); } @@ -784,6 +786,7 @@ size_t nvlist_ndescriptors(const nvlist_t *nvl) { #ifndef _KERNEL + void *cookie; nvpair_t *nvp; size_t ndescs; int type; @@ -792,16 +795,17 @@ nvlist_ndescriptors(const nvlist_t *nvl) PJDLOG_ASSERT(nvl->nvl_error == 0); ndescs = 0; - nvp = NULL; + cookie = NULL; do { - while (nvlist_next(nvl, &type, (void *)&nvp) != NULL) { + while (nvlist_next(nvl, &type, &cookie) != NULL) { + nvp = cookie; switch (type) { case NV_TYPE_DESCRIPTOR: ndescs++; break; case NV_TYPE_NVLIST: nvl = nvpair_get_nvlist(nvp); - nvp = NULL; + cookie = NULL; break; case NV_TYPE_NVLIST_ARRAY: { @@ -813,7 +817,7 @@ nvlist_ndescriptors(const nvlist_t *nvl) PJDLOG_ASSERT(nitems > 0); nvl = value[0]; - nvp = NULL; + cookie = NULL; break; } case NV_TYPE_DESCRIPTOR_ARRAY: @@ -827,7 +831,7 @@ nvlist_ndescriptors(const nvlist_t *nvl) } } } - } while ((nvl = nvlist_get_pararr(nvl, (void *)&nvp)) != NULL); + } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL); return (ndescs); #else