fix: avoid unsigned overflow in home_replace() (#20854)

This commit is contained in:
zeertzjq 2022-10-30 06:49:39 +08:00 committed by GitHub
parent 49fbcb5b82
commit a7d100f052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}
if (dstlen == 0) {
break; // Avoid overflowing below.
}
// if (!one) skip to separator: space or comma.
while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0) {
*dst_p++ = *src++;
}
if (dstlen == 0) {
break; // Avoid overflowing below.
}
// Skip separator.
while ((*src == ' ' || *src == ',') && --dstlen > 0) {
*dst_p++ = *src++;

View File

@ -144,4 +144,10 @@ describe('tabpage', function()
command(' silent :keepalt :: ::: silent! -2 tabmove')
eq(1, funcs.nvim_tabpage_get_number(0))
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)