Skip to content

Commit

Permalink
hfsfuse: ensure readlink result is NUL terminated
Browse files Browse the repository at this point in the history
This is required by libfuse, which needs a valid C string to determine
the length of the returned link destination.

Fixes a potential read and disclosure of uninitialized memory of up to
PATH_MAX bytes when reading link destinations on a mounted filesystem.
Bytes following PATH_MAX are terminated by FUSE.

Thanks to @sbond75 for finding this.
  • Loading branch information
0x09 committed Apr 18, 2024
1 parent ed7ad0b commit 529cb8b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hfsfuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ static int hfsfuse_read(const char* path, char* buf, size_t size, off_t offset,
}

static int hfsfuse_readlink(const char* path, char* buf, size_t size) {
if(!size)
return -EINVAL;
struct fuse_file_info info;
if(hfsfuse_open(path,&info)) return -errno;
int bytes = hfsfuse_read(path,buf,size,0,&info);
int bytes = hfsfuse_read(path,buf,size-1,0,&info);
hfsfuse_release(NULL,&info);
if(bytes < 0) return -errno;
buf[bytes] = '\0';
return 0;
}

Expand Down

0 comments on commit 529cb8b

Please sign in to comment.