]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: Plug more mem leaks in sftp by making
authordtucker@openbsd.org <dtucker@openbsd.org>
Tue, 28 Mar 2023 07:44:32 +0000 (07:44 +0000)
committerDarren Tucker <dtucker@dtucker.net>
Tue, 28 Mar 2023 08:03:54 +0000 (19:03 +1100)
make_absolute_pwd_glob work in the same way as make_absolute: you
pass it a dynamically allocated string and it either returns it, or
frees it and allocates a new one. Patch from emaste at freebsd.org and
https://reviews.freebsd.org/D37253 ok djm@

OpenBSD-Commit-ID: 85f7404e9d47fd28b222fbc412678f3361d2dffc

sftp-client.c
sftp.c

index 87b4d142aa74563bbeab7ec9b776722b41b8f76f..29f4c64d1f80e55973c17cd390bc119e15fa46ba 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.c,v 1.169 2023/03/08 04:43:12 guenther Exp $ */
+/* $OpenBSD: sftp-client.c,v 1.170 2023/03/28 07:44:32 dtucker Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -2895,6 +2895,10 @@ path_append(const char *p1, const char *p2)
        return(ret);
 }
 
+/*
+ * Arg p must be dynamically allocated.  It will either be returned or
+ * freed and a replacement allocated.  Caller must free returned string.
+ */
 char *
 make_absolute(char *p, const char *pwd)
 {
diff --git a/sftp.c b/sftp.c
index 29081db3d434dd0333ccf97342404d3fff09d572..6c5aab7a554dc147a132528ab8d4fd62338ddc1a 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.229 2023/03/12 09:41:18 dtucker Exp $ */
+/* $OpenBSD: sftp.c,v 1.230 2023/03/28 07:44:32 dtucker Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -616,15 +616,19 @@ escape_glob(const char *s)
        return ret;
 }
 
+/*
+ * Arg p must be dynamically allocated.  make_absolute will either return it
+ * or free it and and allocate a new one.  Caller must free returned string.
+ */
 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 +641,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 +2001,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);