conf: clamp pw_strv_insert_at invalid pos to [0, len]

Invalid pos was clamped to len+1, which could insert past the terminating NULL.
Clamp negative indices to 0 and values above len to len.
This commit is contained in:
zuozhiwei 2026-04-20 11:17:40 +08:00 committed by Wim Taymans
parent f0a33cddbd
commit 0a38fedeec

View file

@ -918,8 +918,11 @@ static char **pw_strv_insert_at(char **strv, int len, int pos, const char *str)
while (strv != NULL && strv[len] != NULL)
len++;
}
if (pos < 0 || pos > len)
pos = len+1;
if (pos < 0)
pos = 0;
else if (pos > len)
pos = len;
n = realloc(strv, sizeof(char*) * (len + 2));
if (n == NULL) {