From: Wayne Davison Date: Fri, 26 Nov 2010 17:35:43 +0000 (-0800) Subject: Avoid splitting a multi-byte character when trimming a name. X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/9f5c16e51d274ad9c11b58396c0f9627d95611fb?ds=sidebyside Avoid splitting a multi-byte character when trimming a name. Fixes bug 7816. --- diff --git a/receiver.c b/receiver.c index ba3566b8..0bc65177 100644 --- a/receiver.c +++ b/receiver.c @@ -129,6 +129,14 @@ int get_tmpname(char *fnametmp, const char *fname, BOOL make_unique) added = maxname - 1; suf = fnametmp + length + added; + /* Trim any dangling high-bit chars if the first-trimmed char (if any) is + * also a high-bit char, just in case we cut into a multi-byte sequence. + * We are guaranteed to stop because of the leading '.' we added. */ + if ((int)f[added] & 0x80) { + while ((int)suf[-1] & 0x80) + suf--; + } + if (make_unique) { static unsigned counter_limit; unsigned counter;