]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: avoid a fatal() when sftp tab-completes filenames that
authordjm@openbsd.org <djm@openbsd.org>
Tue, 30 Sep 2025 00:06:06 +0000 (00:06 +0000)
committerDamien Miller <djm@mindrot.org>
Tue, 30 Sep 2025 00:08:18 +0000 (10:08 +1000)
share common utf-8 characters that don't encode to a complete codepoint

from menthu.zhou via GHPR#587; ok dtucker@

OpenBSD-Commit-ID: e07e4d8a8cac032ab536570b8214e6ef6839b585

sftp.c

diff --git a/sftp.c b/sftp.c
index c77a608a8e543629cf3b7566910f7c45d0dee0c5..bdcf977080f2ea8aa63b16ab049d965833575223 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.243 2025/09/25 06:23:19 jsg Exp $ */
+/* $OpenBSD: sftp.c,v 1.244 2025/09/30 00:06:06 djm Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -1868,6 +1868,7 @@ complete_ambiguous(const char *word, char **list, size_t count)
 
        if (count > 0) {
                u_int y, matchlen = strlen(list[0]);
+               u_int itemlen = matchlen, wordlen = strlen(word);
 
                /* Find length of common stem */
                for (y = 1; list[y]; y++) {
@@ -1880,6 +1881,10 @@ complete_ambiguous(const char *word, char **list, size_t count)
                        matchlen = x;
                }
 
+               for (; matchlen > wordlen; matchlen--)
+                       if (mblen(list[0] + matchlen, itemlen - matchlen) >= 0)
+                               break;
+
                if (matchlen > strlen(word)) {
                        char *tmp = xstrdup(list[0]);