Merge pull request #20870 from neovim/backport-20854-to-release-0.8

[Backport release-0.8] fix: avoid unsigned overflow in home_replace()
This commit is contained in:
zeertzjq
2022-10-30 07:06:30 +08:00
committed by GitHub
2 changed files with 12 additions and 0 deletions

View File

@@ -1119,10 +1119,16 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si
len = envlen; len = envlen;
} }
if (dstlen == 0) {
break; // Avoid overflowing below.
}
// if (!one) skip to separator: space or comma. // if (!one) skip to separator: space or comma.
while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0) { while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0) {
*dst_p++ = *src++; *dst_p++ = *src++;
} }
if (dstlen == 0) {
break; // Avoid overflowing below.
}
// Skip separator. // Skip separator.
while ((*src == ' ' || *src == ',') && --dstlen > 0) { while ((*src == ' ' || *src == ',') && --dstlen > 0) {
*dst_p++ = *src++; *dst_p++ = *src++;

View File

@@ -144,4 +144,10 @@ describe('tabpage', function()
command(' silent :keepalt :: ::: silent! -2 tabmove') command(' silent :keepalt :: ::: silent! -2 tabmove')
eq(1, funcs.nvim_tabpage_get_number(0)) eq(1, funcs.nvim_tabpage_get_number(0))
end) end)
it(':tabs does not overflow IObuff with long path with comma #20850', function()
meths.buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024))
command('tabs')
assert_alive()
end)
end) end)