]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: avoid truncation of pathnames headed to lstat() for master anongit/master
authordjm@openbsd.org <djm@openbsd.org>
Fri, 5 Jun 2026 08:48:43 +0000 (08:48 +0000)
committerDamien Miller <djm@mindrot.org>
Fri, 5 Jun 2026 08:49:16 +0000 (18:49 +1000)
systems where PATH_MAX is not the actual max; reported by sahvx655-wq via
GHPR688

OpenBSD-Commit-ID: fcbeeff99d857f2f3916ad06570fa05fc38b0f07

sftp-server.c

index ed57339d5b1376894fbb5059fd0cdeb8e20a2d1b..156d5ece58c38b6b3fd97c12836a3ffda2e04a81 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-server.c,v 1.154 2026/05/31 04:59:51 djm Exp $ */
+/* $OpenBSD: sftp-server.c,v 1.155 2026/06/05 08:48:43 djm Exp $ */
 /*
  * Copyright (c) 2000-2004 Markus Friedl.  All rights reserved.
  *
@@ -1136,7 +1136,7 @@ process_readdir(uint32_t id)
                send_status(id, SSH2_FX_FAILURE);
        } else {
                struct stat st;
-               char pathname[PATH_MAX];
+               char *pathname;
                Stat *stats;
                int nstats = 10, count = 0, i;
 
@@ -1146,10 +1146,11 @@ process_readdir(uint32_t id)
                                nstats *= 2;
                                stats = xreallocarray(stats, nstats, sizeof(Stat));
                        }
-/* XXX OVERFLOW ? */
-                       snprintf(pathname, sizeof pathname, "%s%s%s", path,
+                       xasprintf(&pathname, "%s%s%s", path,
                            strcmp(path, "/") ? "/" : "", dp->d_name);
-                       if (lstat(pathname, &st) == -1)
+                       r = lstat(pathname, &st);
+                       free(pathname);
+                       if (r == -1)
                                continue;
                        stat_to_attrib(&st, &(stats[count].attrib));
                        stats[count].name = xstrdup(dp->d_name);