* src/progress.c (prepare_filename): Replace zero-width mbc (\xe2\x80\x8b, ...)

This commit is contained in:
Вячеслав Петрищев 2020-01-04 13:24:43 +06:00 committed by Tim Rühsen
parent ec68da677f
commit 68548acf0f

View File

@ -614,20 +614,21 @@ prepare_filename(char *dest, const char *src)
{
size_t i;
mbc = mbi_cur(iter);
if (mb_isprint(mbc))
{
if (dest)
for (i=0; i<mb_len(mbc); i++)
*dest++ = *(mb_ptr(mbc) + i);
ret += mb_len(mbc);
}
else
/* replace invalid || unprintable || zero-width mbc ws hexdgt code */
if (!mb_isprint (mbc) || !mb_width (mbc))
for (i=0; i < mb_len (mbc); i++)
{
if (dest)
dest += sprintf (dest, "%%%02x", (unsigned char) *(mb_ptr(mbc) + i));
ret += 3;
}
else
{
if (dest)
for (i=0; i < mb_len (mbc); i++)
*dest++ = *(mb_ptr (mbc) + i);
ret += mb_len (mbc);
}
mbi_advance (iter);
}
}
@ -677,7 +678,9 @@ bar_create (const char *f_download, wgint initial, wgint total)
bp->initial_length = initial;
bp->total_length = total;
/* replace unprintable chars and invalid sequences */
/* Zero-width mbc must be replaced to avoid buffer overflow.
Another way is to allocate a buffer that allows contain
full f_download, but in this case some escape sequences may break "bar" */
bp->f_download = xmalloc (prepare_filename (NULL, f_download));
prepare_filename (bp->f_download, f_download);