Skip to content

Commit

Permalink
fsdev: Fix overrun after readlink() fills buffer completely
Browse files Browse the repository at this point in the history
readlink() returns the number of bytes written to the buffer, and it
doesn't write a terminating null byte.  do_readlink() writes it
itself.  Overruns the buffer when readlink() filled it completely.

Fix by reserving space for the null byte when calling readlink(), like
we do elsewhere.

Signed-off-by: Markus Armbruster <[email protected]>
Signed-off-by: Aneesh Kumar K.V <[email protected]>
  • Loading branch information
Markus Armbruster authored and kvaneesh committed Feb 26, 2014
1 parent d5001cf commit d77f777
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fsdev/virtfs-proxy-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ static int do_readlink(struct iovec *iovec, struct iovec *out_iovec)
}
buffer = g_malloc(size);
v9fs_string_init(&target);
retval = readlink(path.data, buffer, size);
retval = readlink(path.data, buffer, size - 1);
if (retval > 0) {
buffer[retval] = '\0';
v9fs_string_sprintf(&target, "%s", buffer);
Expand Down

0 comments on commit d77f777

Please sign in to comment.