From owner-svn-src-head@freebsd.org Sun Nov 3 14:36:17 2019 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 ACC1E1B6D10; Sun, 3 Nov 2019 14:36:17 +0000 (UTC) (envelope-from tsoome@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 475dlj45tzz4C9K; Sun, 3 Nov 2019 14:36:17 +0000 (UTC) (envelope-from tsoome@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 6B8C9D3C4; Sun, 3 Nov 2019 14:36:17 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xA3EaHO4022033; Sun, 3 Nov 2019 14:36:17 GMT (envelope-from tsoome@FreeBSD.org) Received: (from tsoome@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xA3EaHdf022032; Sun, 3 Nov 2019 14:36:17 GMT (envelope-from tsoome@FreeBSD.org) Message-Id: <201911031436.xA3EaHdf022032@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tsoome set sender to tsoome@FreeBSD.org using -f From: Toomas Soome Date: Sun, 3 Nov 2019 14:36:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354284 - head/stand/libsa/zfs X-SVN-Group: head X-SVN-Commit-Author: tsoome X-SVN-Commit-Paths: head/stand/libsa/zfs X-SVN-Commit-Revision: 354284 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: Sun, 03 Nov 2019 14:36:17 -0000 Author: tsoome Date: Sun Nov 3 14:36:16 2019 New Revision: 354284 URL: https://svnweb.freebsd.org/changeset/base/354284 Log: loader: zfs.c is missing malloc checks, fix it malloc() can return NULL, we need to check the return value. Modified: head/stand/libsa/zfs/zfs.c Modified: head/stand/libsa/zfs/zfs.c ============================================================================== --- head/stand/libsa/zfs/zfs.c Sun Nov 3 13:25:47 2019 (r354283) +++ head/stand/libsa/zfs/zfs.c Sun Nov 3 14:36:16 2019 (r354284) @@ -110,9 +110,10 @@ zfs_open(const char *upath, struct open_file *f) return (EINVAL); /* allocate file system specific data structure */ - fp = malloc(sizeof(struct file)); - bzero(fp, sizeof(struct file)); - f->f_fsdata = (void *)fp; + fp = calloc(1, sizeof(struct file)); + if (fp == NULL) + return (ENOMEM); + f->f_fsdata = fp; rc = zfs_lookup(mount, upath, &fp->f_dnode); fp->f_seekp = 0; @@ -129,9 +130,7 @@ zfs_close(struct open_file *f) struct file *fp = (struct file *)f->f_fsdata; dnode_cache_obj = NULL; - f->f_fsdata = (void *)0; - if (fp == (struct file *)0) - return (0); + f->f_fsdata = NULL; free(fp); return (0); @@ -250,7 +249,9 @@ zfs_readdir(struct open_file *f, struct dirent *d) return (rc); fp->f_seekp = bsize; - fp->f_zap_leaf = (zap_leaf_phys_t *)malloc(bsize); + fp->f_zap_leaf = malloc(bsize); + if (fp->f_zap_leaf == NULL) + return (ENOMEM); rc = dnode_read(spa, &fp->f_dnode, fp->f_seekp, fp->f_zap_leaf, @@ -675,8 +676,9 @@ zfs_dev_open(struct open_file *f, ...) } mount = malloc(sizeof(*mount)); if (mount == NULL) - return (ENOMEM); - rv = zfs_mount(spa, dev->root_guid, mount); + rv = ENOMEM; + else + rv = zfs_mount(spa, dev->root_guid, mount); if (rv != 0) { free(mount); return (rv);