Fix implausible overflow when reading symlinks

* src/safe.c (read_symlink): Check for integer overflow
in bufferi size calculation.
This commit is contained in:
Paul Eggert 2024-09-09 16:01:42 -07:00
parent 5e84bda3ff
commit fe8ffd9ba4

View File

@ -317,7 +317,10 @@ static struct symlink *read_symlink(int dirfd, const char *name)
errno = saved_errno;
return nullptr;
}
symlink = xmalloc (sizeof (*symlink) + st.st_size + 1);
idx_t symlinksize;
if (ckd_add (&symlinksize, st.st_size, 1 + sizeof *symlink))
xalloc_die ();
symlink = ximalloc (symlinksize);
buffer = (char *)(symlink + 1);
ret = readlinkat (dirfd, name, buffer, st.st_size);
if (ret <= 0)