From nobody Wed Mar 22 15:05:43 2023 X-Original-To: dev-commits-src-main@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 4PhWxg4rqJz40x38; Wed, 22 Mar 2023 15:05:43 +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 4PhWxg4QLHz3C0n; Wed, 22 Mar 2023 15:05:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679497543; 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=m0sJvvq7mBcDiYd+1o6DB1+CutXuglDrKX6/adFompg=; b=mfNEM2ooXVF6j70iEUoWMeSXFcn3ZlCO1oRrxjENOaPOyeRJfNa/uFTrAaU22FPN8COJmr mwRLyK5k/LT+FxSp9YqlXH3vOISLlRl25uYHZs+A0JO11XMdfcLijruiTVEwRAnm9ZE6tt XXN9jLajrZM9iw9H1EQY/avqA1ung3qdR4lc/2qM4Wmt0TEG0yCPBzGVtgAaZXfsbeThyb EpTISkjKZ0YFwE0qGpNRI4w1IKDAM3JNeTWNygfYyzZN7a55mt5RT1zGXjVFif3lF94Erk Ul6WFnavwqhkkBZwI5gikei5zNKDhjFnZxhm3sJkOGCSLh/6DMeqme6/aJeJAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679497543; 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=m0sJvvq7mBcDiYd+1o6DB1+CutXuglDrKX6/adFompg=; b=sXV063Pf6yHt5PP5WrAyY+oqhIgCWv6gLaP3NnhhR+NO1OnxuXutMZUZ3Bug1Hw7/yGNpI tgcpBHyidRNSJK+QHyhL7/Kfe5pC6xKuF4I/JXA2BmnLzZXF/KPLdHkqqqCEkUs0hlHQUO Kpeqo6ODxfgkO+3wRRaVQVVf1L7qynXctZJhlhSiai6N91JOk5L0eyZe5DI0NgDdOKSLcB zm1j8oLU/n0cLN1/Bq3DOtzIGbN91j1tH1oGpR4ND2MpFJZhaU1V5CwE99QnEa0yaKl5xp Dm89eMIi+8Eb70i5+zZrMNqGoTiY0BH8TYkiYG7FkBATkq923WnUMoWmcyX5zg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679497543; a=rsa-sha256; cv=none; b=h/kIgMauWL59oPPBARLROdBWrz80RwI6E2MC3G0En5bolGtuXjedxr9g4g8g8unHD6hSTb vIfzpw6vPwbwZpc3l8VZxKmTZDjvIthZr3dW3oW8UeKnSdri6U9Gr5qB+zHpjzoApvtrsT tF1vovj/vz80dN7dqLV8qNNm+JFyee12LWkw9TSqWk2uv52pTk6ki9O9+DlF1bdgMfIukD Gr+Xp0znhEs9dQnpLbUepEL8Zq9sKMnQsSKNb8Nj9q7pQ7wiu5jM6ToJPhENrgbChnTyvr OAODsIWKUsdZOiLefzJP9KEaVqgxXAcYxJ32MxQWe7ELQSDE8Yc1onnzVJCBsQ== 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 4PhWxg3B6Kzy8r; Wed, 22 Mar 2023 15:05:43 +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 32MF5hC4076823; Wed, 22 Mar 2023 15:05:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32MF5hLr076822; Wed, 22 Mar 2023 15:05:43 GMT (envelope-from git) Date: Wed, 22 Mar 2023 15:05:43 GMT Message-Id: <202303221505.32MF5hLr076822@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 69c72a57af84 - main - sftp: avoid leaking path arg in calls to make_absolute_pwd_glob List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 69c72a57af843267b220f8367c4cc7162a12d696 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=69c72a57af843267b220f8367c4cc7162a12d696 commit 69c72a57af843267b220f8367c4cc7162a12d696 Author: Ed Maste AuthorDate: 2022-11-03 17:17:40 +0000 Commit: Ed Maste CommitDate: 2023-03-22 14:54:35 +0000 sftp: avoid leaking path arg in calls to make_absolute_pwd_glob As Coverity reports: Overwriting tmp in tmp = make_absolute_pwd_glob(tmp, remote_path) leaks the storage that tmp points to. Consume the first arg in make_absolute_pwd_glob, and add xstrdup() to the one case which did not assign to the same variable that was passed in. With this change make_absolute() and make_absolute_pwd_glob() have the same semantics with respect to freeing the input string. This change was reported to OpenSSH in https://lists.mindrot.org/pipermail/openssh-unix-dev/2022-November/040497.html but was not acted on. It appears that OpenBSD subsequently received a Coverity report for the same issue (their Coverity ID 405196) but fixed only the specific instance reported by Coverity. This change reverts OpenBSD's sftp.c 1.228 / OpenSSH-portable commit 36c6c3eff5e4. Reported by: Coverity Scan CID: 1500409 Reviewed by: markj MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37253 --- crypto/openssh/sftp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crypto/openssh/sftp.c b/crypto/openssh/sftp.c index 29081db3d434..ce7ab7f8f2fe 100644 --- a/crypto/openssh/sftp.c +++ b/crypto/openssh/sftp.c @@ -617,14 +617,14 @@ escape_glob(const char *s) } static char * -make_absolute_pwd_glob(const char *p, const char *pwd) +make_absolute_pwd_glob(char *p, const char *pwd) { char *ret, *escpwd; escpwd = escape_glob(pwd); if (p == NULL) return escpwd; - ret = make_absolute(xstrdup(p), escpwd); + ret = make_absolute(p, escpwd); free(escpwd); return ret; } @@ -637,7 +637,7 @@ process_get(struct sftp_conn *conn, const char *src, const char *dst, glob_t g; int i, r, err = 0; - abs_src = make_absolute_pwd_glob(src, pwd); + abs_src = make_absolute_pwd_glob(xstrdup(src), pwd); memset(&g, 0, sizeof(g)); debug3("Looking up %s", abs_src); @@ -1997,9 +1997,7 @@ complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, memset(&g, 0, sizeof(g)); if (remote != LOCAL) { - tmp2 = make_absolute_pwd_glob(tmp, remote_path); - free(tmp); - tmp = tmp2; + tmp = make_absolute_pwd_glob(tmp, remote_path); remote_glob(conn, tmp, GLOB_DOOFFS|GLOB_MARK, NULL, &g); } else glob(tmp, GLOB_DOOFFS|GLOB_MARK, NULL, &g);