From: djm@openbsd.org Date: Tue, 30 Sep 2025 00:06:06 +0000 (+0000) Subject: upstream: avoid a fatal() when sftp tab-completes filenames that X-Git-Url: https://git.feebdaed.xyz/?a=commitdiff_plain;h=1f7556753869654ba5e2bf61e384c5da2db5ca6a;p=0xmirror%2Fopenssh-portable.git upstream: avoid a fatal() when sftp tab-completes filenames that 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 --- diff --git a/sftp.c b/sftp.c index c77a608a8..bdcf97708 100644 --- 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 * @@ -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]);