From owner-svn-src-head@freebsd.org Tue Apr 28 20:34:27 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C16DE2C480D; Tue, 28 Apr 2020 20:34:27 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49BYKH4mg2z4GbK; Tue, 28 Apr 2020 20:34:27 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9E8D82A0D4; Tue, 28 Apr 2020 20:34:27 +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 03SKYRFx079945; Tue, 28 Apr 2020 20:34:27 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03SKYRNb079944; Tue, 28 Apr 2020 20:34:27 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <202004282034.03SKYRNb079944@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Tue, 28 Apr 2020 20:34:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360452 - head/bin/sh X-SVN-Group: head X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: head/bin/sh X-SVN-Commit-Revision: 360452 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.29 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: Tue, 28 Apr 2020 20:34:27 -0000 Author: jilles Date: Tue Apr 28 20:34:27 2020 New Revision: 360452 URL: https://svnweb.freebsd.org/changeset/base/360452 Log: sh: Assert INTOFF rather than applying it in ck* As I noted in https://reviews.freebsd.org/D22756, INTOFF should be in effect when calling ckmalloc/ckrealloc/ckfree to avoid memory leaks and double frees. Therefore, change the functions to check if INTOFF is in effect instead of applying it. Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D24599 Modified: head/bin/sh/memalloc.c Modified: head/bin/sh/memalloc.c ============================================================================== --- head/bin/sh/memalloc.c Tue Apr 28 20:14:38 2020 (r360451) +++ head/bin/sh/memalloc.c Tue Apr 28 20:34:27 2020 (r360452) @@ -50,6 +50,13 @@ __FBSDID("$FreeBSD$"); #include #include +static void +badalloc(const char *message) +{ + write(2, message, strlen(message)); + abort(); +} + /* * Like malloc, but returns an error when out of space. */ @@ -59,9 +66,9 @@ ckmalloc(size_t nbytes) { pointer p; - INTOFF; + if (!is_int_on()) + badalloc("Unsafe ckmalloc() call\n"); p = malloc(nbytes); - INTON; if (p == NULL) error("Out of space"); return p; @@ -75,9 +82,9 @@ ckmalloc(size_t nbytes) pointer ckrealloc(pointer p, int nbytes) { - INTOFF; + if (!is_int_on()) + badalloc("Unsafe ckrealloc() call\n"); p = realloc(p, nbytes); - INTON; if (p == NULL) error("Out of space"); return p; @@ -86,9 +93,9 @@ ckrealloc(pointer p, int nbytes) void ckfree(pointer p) { - INTOFF; + if (!is_int_on()) + badalloc("Unsafe ckfree() call\n"); free(p); - INTON; }