From owner-svn-src-head@freebsd.org Mon Jan 15 22:17:17 2018 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 20049E7ABA0; Mon, 15 Jan 2018 22:17:17 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F0A4872073; Mon, 15 Jan 2018 22:17:16 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4595B17327; Mon, 15 Jan 2018 22:17:16 +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 w0FMHGht092943; Mon, 15 Jan 2018 22:17:16 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0FMHG2x092942; Mon, 15 Jan 2018 22:17:16 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201801152217.w0FMHG2x092942@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Mon, 15 Jan 2018 22:17:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328029 - head/stand/efi/libefi X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/stand/efi/libefi X-SVN-Commit-Revision: 328029 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.25 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: Mon, 15 Jan 2018 22:17:17 -0000 Author: imp Date: Mon Jan 15 22:17:15 2018 New Revision: 328029 URL: https://svnweb.freebsd.org/changeset/base/328029 Log: When returning an error and freeing allocated memory from ucs2_to_utf8 and utf8_to_ucs2, be sure to NULL out the return pointer too, rather than return a pointer to free memory. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D13917 Modified: head/stand/efi/libefi/efichar.c Modified: head/stand/efi/libefi/efichar.c ============================================================================== --- head/stand/efi/libefi/efichar.c Mon Jan 15 21:59:20 2018 (r328028) +++ head/stand/efi/libefi/efichar.c Mon Jan 15 22:17:15 2018 (r328029) @@ -116,8 +116,10 @@ ucs2_to_utf8(const efi_char *nm, char **name) if (len >= sz) { /* Absent bugs, we'll never return EOVERFLOW */ - if (freeit) + if (freeit) { free(*name); + *name = NULL; + } return (EOVERFLOW); } *cp++ = '\0'; @@ -150,11 +152,8 @@ utf8_to_ucs2(const char *name, efi_char **nmp, size_t */ if ((c & 0xc0) != 0x80) { /* Initial characters. */ - if (bytes != 0) { - if (freeit) - free(nm); - return (EILSEQ); - } + if (bytes != 0) + goto ilseq; if ((c & 0xf8) == 0xf0) { ucs4 = c & 0x07; bytes = 3; @@ -173,29 +172,31 @@ utf8_to_ucs2(const char *name, efi_char **nmp, size_t if (bytes > 0) { ucs4 = (ucs4 << 6) + (c & 0x3f); bytes--; - } else if (bytes == 0) { - if (freeit) - free(nm); - return (EILSEQ); - } + } else if (bytes == 0) + goto ilseq; } if (bytes == 0) { - if (ucs4 > 0xffff) { - if (freeit) - free(nm); - return (EILSEQ); - } + if (ucs4 > 0xffff) + goto ilseq; *nm++ = (efi_char)ucs4; sz -= 2; } } if (sz < 2) { - if (freeit) + if (freeit) { free(nm); + *nmp = NULL; + } return (EDOOFUS); } sz -= 2; *nm = 0; *len -= sz; return (0); +ilseq: + if (freeit) { + free(nm); + *nmp = NULL; + } + return (EILSEQ); }