From owner-svn-src-head@freebsd.org Thu Mar 23 02:30:54 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 F39C2D181D9; Thu, 23 Mar 2017 02:30:53 +0000 (UTC) (envelope-from imp@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 AA8D6144C; Thu, 23 Mar 2017 02:30:53 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2N2Uq7M047504; Thu, 23 Mar 2017 02:30:52 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2N2UqS2047503; Thu, 23 Mar 2017 02:30:52 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201703230230.v2N2UqS2047503@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 23 Mar 2017 02:30:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315770 - head/lib/libefivar X-SVN-Group: head 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, 23 Mar 2017 02:30:54 -0000 Author: imp Date: Thu Mar 23 02:30:52 2017 New Revision: 315770 URL: https://svnweb.freebsd.org/changeset/base/315770 Log: Define StrCmp in a funky was to be bug-compatible with EDK2 code. Paper over a coverity issue: *** CID 1372592: API usage errors (BAD_COMPARE) /lib/libefivar/efivar-dp-parse.c: 2723 in DevPathFromTextiSCSI() Truncating the result of "strcmp" to "unsigned short" may cause it to be misinterpreted as 0. Note that "strcmp" may return an integer besides -1, 0, or 1. We do this by making StrCmp return either 0 or 1 for equal or not-equal. There's a bug in the DevPathFromTextiSCSI cast of the return value and this workaround will fix it without breaking other users of StrCmp (all of which test for == 0). https://bugzilla.tianocore.org/show_bug.cgi?id=440 has been filed upstream to log this issue. CID: 1372592 Sponsored by: Netflix Modified: head/lib/libefivar/uefi-dplib.h (contents, props changed) Modified: head/lib/libefivar/uefi-dplib.h ============================================================================== --- head/lib/libefivar/uefi-dplib.h Thu Mar 23 02:29:59 2017 (r315769) +++ head/lib/libefivar/uefi-dplib.h Thu Mar 23 02:30:52 2017 (r315770) @@ -508,7 +508,16 @@ UefiDevicePathLibConvertTextToDevicePath #define LShiftU64(x, s) ((x) << s) #define ReadUnaligned64(x) le64dec(x) #define ReallocatePool(old, new, ptr) realloc(ptr, new) -#define StrCmp(a, b) strcmp(a, b) +/* + * Quirky StrCmp returns 0 if equal, 1 if not. This is what the code + * expects, though that expectation is likely a bug (it casts the + * return value. EDK2's StrCmp returns values just like C's strcmp, + * but the parse code casts this to an UINTN, which is bogus. This + * definition papers over that bogusness to do the right thing. If + * iSCSI protocol string processing is ever fixed, we can remove this + * bletcherous kludge. + */ +#define StrCmp(a, b) (strcmp(a, b) != 0) #define StrCpyS(d, l, s) strcpy(d, s) #define StrHexToUint64(x) strtoll(x, NULL, 16) #define StrHexToUintn(x) strtoll(x, NULL, 16)