From nobody Thu Feb 16 20:37:33 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PHmwG1PQWz3rVfr; Thu, 16 Feb 2023 20:37:34 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHmwG0dCNz3w4j; Thu, 16 Feb 2023 20:37:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676579854; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jEwMn7roErqzmtzdsPaIYJ0vaVn+J1ed7l33M7KbH08=; b=xOsOGoCrvYhxPKhxAToeNnIdliML/nyx1R6kmrpgGY0XQMWntLG1uEqPB5Um7SOGdPx2Ke 0O8o6dAd0LnXgPc4CnAb4au533b+vswB7dZo9X9yRtHHxqM78E+YhcGYp3Dv4Lo2EOm9BA si5YQK8yMEc7/XWDc1drJYdCWvWjilSTVkb+XYit/TA/s/icueU4njg2jVrf3lo1FLDTJy 3Ii2ztZivr6rPdj2GUUnUG8jKXoHqmIhaelR1UPkjqRv0QkA6GwV8OsT2iLsTROp0I1ozM bsYW8gRsaJm/xnjpZVH5Od6YZ7UWS3otRxok3AWSJ54UjwllSgqqPDtGtDIiKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676579854; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jEwMn7roErqzmtzdsPaIYJ0vaVn+J1ed7l33M7KbH08=; b=iaqy5odSrv8Vu6ej2Occxeq1Xqc6AV/eN9iHVN6SRbdl76jwnLD376Z+lkzvGODeBF0O4n cwwobEBbRY7onS8t/oduQmuppcgd7QtQx5X0FHIYwmHY8LXWyznvHp9AQ9N3PoUHayd69W o2MjMOVR5i01X25/42dqqnEaYCJ6q83U4ZvvHbjtBo2fLrosYZxA9v7HQrvcM8um3O7GCT HWX8a1a3GjftJy22cvvf9Mr7Jj6C034vi/hO9WGA56VyV2JK1yuKJVqIBU/iuK2AC83460 nbUyySjyj+BEhI56cDUU8a5H007DcDFSkSjX2t5Z/4+X+MNTEVxmUQF84Kx4lQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676579854; a=rsa-sha256; cv=none; b=KBj0SgP1uiAfHxmhXz4BIXlvZb9YMNtHnnUJx9szKu0xYbMSK6ikcS6+jXPQ6POctZNdKC qundYOF57Q0TZIQkzJsyDRPlVPPmax4hTeBGOAD9+jSqJ7UW1n1MOQ87sy30tzVuBPUJzn +2koiipEv+l596n0NlNU+0/uqvHUXXTlsmQTnWpD0cJpxFCDaLVFJtaFDdTXB2toC0AvYv Ttp9B1MMWmKhFIE2dHvsTp65t5fccWUoE0tZipsHYVW5Yd82BrIOIpcXTCLkxniZ9NZqOX NmV3rMcgUewLSK6y76uiIC3fHW2iBe2FvPeZDJzm4MVZbA98XLfIqUgg6UJ9DA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PHmwF6Sw7zHfB; Thu, 16 Feb 2023 20:37:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31GKbXVN002475; Thu, 16 Feb 2023 20:37:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31GKbX0L002474; Thu, 16 Feb 2023 20:37:33 GMT (envelope-from git) Date: Thu, 16 Feb 2023 20:37:33 GMT Message-Id: <202302162037.31GKbX0L002474@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: f518229d5520 - main - config: fix some common issues with path() usage List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f518229d552012bfb1129b2bf1d18dfc89a03b58 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=f518229d552012bfb1129b2bf1d18dfc89a03b58 commit f518229d552012bfb1129b2bf1d18dfc89a03b58 Author: Kyle Evans AuthorDate: 2023-02-16 20:36:16 +0000 Commit: Kyle Evans CommitDate: 2023-02-16 20:36:16 +0000 config: fix some common issues with path() usage None of the callers check that the allocation in path() failed, so let's check in path() and abort instead of failing. Along those lines, none of the callers seem to acknowledge that the returned string needs to be free()d -- let's do that as well. There are a couple not addressed in this commit that will be addressed in a future commit by pushing the path() call down into moveifchanged() instead and freeing it properly there. CID: 1505271, 1505250, 1505279 Reviewed by: emaste, imp --- usr.sbin/config/main.cc | 8 +++++++- usr.sbin/config/mkoptions.cc | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/usr.sbin/config/main.cc b/usr.sbin/config/main.cc index ef24d373c8b0..f155b7c5387a 100644 --- a/usr.sbin/config/main.cc +++ b/usr.sbin/config/main.cc @@ -457,6 +457,8 @@ path(const char *file) asprintf(&cp, "%s/%s", destdir, file); else cp = strdup(destdir); + if (cp == NULL) + err(EXIT_FAILURE, "malloc"); return (cp); } @@ -553,6 +555,8 @@ configfile(void) fo = fopen(p, "w"); if (!fo) err(2, "%s", p); + free(p); + if (filebased) { /* Is needed, can be used for backward compatibility. */ configfile_filebased(cfg); @@ -673,8 +677,10 @@ cleanheaders(char *p) if (hl) continue; printf("Removing stale header: %s\n", dp->d_name); - if (unlink(path(dp->d_name)) == -1) + p = path(dp->d_name); + if (unlink(p) == -1) warn("unlink %s", dp->d_name); + free(p); } (void)closedir(dirp); } diff --git a/usr.sbin/config/mkoptions.cc b/usr.sbin/config/mkoptions.cc index f45c1026417c..134c09c2d074 100644 --- a/usr.sbin/config/mkoptions.cc +++ b/usr.sbin/config/mkoptions.cc @@ -294,6 +294,7 @@ tooption(char *name) static char hbuf[MAXPATHLEN]; char nbuf[MAXPATHLEN]; struct opt_list *po; + char *fpath; /* "cannot happen"? the otab list should be complete.. */ (void)strlcpy(nbuf, "options.h", sizeof(nbuf)); @@ -305,7 +306,9 @@ tooption(char *name) } } - (void)strlcpy(hbuf, path(nbuf), sizeof(hbuf)); + fpath = path(nbuf); + (void)strlcpy(hbuf, fpath, sizeof(hbuf)); + free(fpath); return (hbuf); }