From owner-svn-src-all@freebsd.org Tue Oct 3 08:29:47 2017 Return-Path: Delivered-To: svn-src-all@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 4A4BDE34FC2; Tue, 3 Oct 2017 08:29:47 +0000 (UTC) (envelope-from manu@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 18C616A48F; Tue, 3 Oct 2017 08:29:47 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v938Tklw022599; Tue, 3 Oct 2017 08:29:46 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v938TkAd022598; Tue, 3 Oct 2017 08:29:46 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201710030829.v938TkAd022598@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Tue, 3 Oct 2017 08:29:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r324234 - stable/11/usr.sbin/mountd X-SVN-Group: stable-11 X-SVN-Commit-Author: manu X-SVN-Commit-Paths: stable/11/usr.sbin/mountd X-SVN-Commit-Revision: 324234 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Oct 2017 08:29:47 -0000 Author: manu Date: Tue Oct 3 08:29:46 2017 New Revision: 324234 URL: https://svnweb.freebsd.org/changeset/base/324234 Log: MFC r324007, r324012, r324014 r324007: mountd: Replace malloc+strcpy to strdup Reviewed by: bapt Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D12503 r324012: mountd: Remove unneeded cast Reported by: kib X MFC With: r324007 r324014: mountd: Avoid memory leak by freeing dp_dirp Introduced in r324007, the data alloced by strdup was never free'ed. While here, remove cast to caddr_t when freeing dp. Reported by: bde X MFC With: r324007 Modified: stable/11/usr.sbin/mountd/mountd.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/mountd/mountd.c ============================================================================== --- stable/11/usr.sbin/mountd/mountd.c Tue Oct 3 08:14:25 2017 (r324233) +++ stable/11/usr.sbin/mountd/mountd.c Tue Oct 3 08:29:46 2017 (r324234) @@ -101,7 +101,7 @@ struct dirlist { struct dirlist *dp_right; int dp_flag; struct hostlist *dp_hosts; /* List of hosts this dir exported to */ - char dp_dirp[1]; /* Actually malloc'd to size of dir */ + char *dp_dirp; }; /* dp_flag bits */ #define DP_DEFSET 0x1 @@ -1525,12 +1525,8 @@ get_exportlist_one(void) if (ep == (struct exportlist *)NULL) { ep = get_exp(); ep->ex_fs = fsb.f_fsid; - ep->ex_fsdir = (char *)malloc - (strlen(fsb.f_mntonname) + 1); - if (ep->ex_fsdir) - strcpy(ep->ex_fsdir, - fsb.f_mntonname); - else + ep->ex_fsdir = strdup(fsb.f_mntonname); + if (ep->ex_fsdir == NULL) out_of_mem(); if (debug) warnx( @@ -1940,14 +1936,16 @@ add_expdir(struct dirlist **dpp, char *cp, int len) { struct dirlist *dp; - dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len); + dp = malloc(sizeof (struct dirlist)); if (dp == (struct dirlist *)NULL) out_of_mem(); dp->dp_left = *dpp; dp->dp_right = (struct dirlist *)NULL; dp->dp_flag = 0; dp->dp_hosts = (struct hostlist *)NULL; - strcpy(dp->dp_dirp, cp); + dp->dp_dirp = strndup(cp, len); + if (dp->dp_dirp == NULL) + out_of_mem(); *dpp = dp; return (dp->dp_dirp); } @@ -2161,7 +2159,8 @@ free_dir(struct dirlist *dp) free_dir(dp->dp_left); free_dir(dp->dp_right); free_host(dp->dp_hosts); - free((caddr_t)dp); + free(dp->dp_dirp); + free(dp); } }