Skip to content

Commit

Permalink
base: util: check provided buffer len fits ssize_t in sid_util_fd_rea…
Browse files Browse the repository at this point in the history
…d_all
  • Loading branch information
prajnoha committed Jun 24, 2024
1 parent 323245c commit f9cbd99
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/base/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -59,6 +60,9 @@ ssize_t sid_util_fd_read_all(int fd, void *buf, size_t len)
{
ssize_t n, total = 0;

if (len > SSIZE_MAX)
return -ERANGE;

while (len) {
n = read(fd, buf, len);
if (n < 0) {
Expand Down

0 comments on commit f9cbd99

Please sign in to comment.