mirror of
git://git.musl-libc.org/musl
synced 2024-12-14 18:55:23 +00:00
fix undefined behavior in getdelim via null pointer arithmetic and memcpy
both passing a null pointer to memcpy with length 0, and adding 0 to a null pointer, are undefined. in some sense this is 'benign' UB, but having it precludes use of tooling that strictly traps on UB. there may be better ways to fix it, but conditioning the operations which are intended to be no-ops in the k==0 case on k being nonzero is a simple and safe solution.
This commit is contained in:
parent
b713b8b2e4
commit
e3e7189c11
@ -55,9 +55,11 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
|
||||
*s = tmp;
|
||||
*n = m;
|
||||
}
|
||||
memcpy(*s+i, f->rpos, k);
|
||||
f->rpos += k;
|
||||
i += k;
|
||||
if (k) {
|
||||
memcpy(*s+i, f->rpos, k);
|
||||
f->rpos += k;
|
||||
i += k;
|
||||
}
|
||||
if (z) break;
|
||||
if ((c = getc_unlocked(f)) == EOF) {
|
||||
if (!i || !feof(f)) {
|
||||
|
Loading…
Reference in New Issue
Block a user