Skip to content

Commit

Permalink
local.c: when target buffer is too small, fail
Browse files Browse the repository at this point in the history
Fix #357

If a target buffer is too small, right now, we try to put a partial fill
in the buffer, and return sucess (which is wrong).

Now we will return EFBIG, and leave the target buffer empty. This will
make the local backends the same as the otherbackends.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz authored and commodo committed Oct 9, 2020
1 parent 80ed865 commit 67273fc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,16 @@ static ssize_t local_read_dev_attr(const struct iio_device *dev,
return -errno;

ret = fread(dst, 1, len, f);

/* if we didn't read the entire file, fail */
if (!feof(f))
ret = -EFBIG;

if (ret > 0)
dst[ret - 1] = '\0';
else
dst[0] = '\0';

fflush(f);
if (ferror(f))
ret = -errno;
Expand Down

0 comments on commit 67273fc

Please sign in to comment.