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
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++;