libc: 'readlink' returns non-zero terminated buffer

Make so to handle zero termination correctly for 'stat' calls and for debugging
output.

Issue #1048
This commit is contained in:
Sebastian Sumpf 2014-01-20 17:17:58 +01:00 committed by Norman Feske
parent b7575319bf
commit 1b1693e6ff
2 changed files with 6 additions and 2 deletions

View File

@ -205,10 +205,13 @@ static void resolve_symlinks(char const *path, Absolute_path &resolved_path)
PDBGV("found symlink: %s", next_iteration_working_path.base());
FNAME_FUNC_WRAPPER_GENERIC(res = , readlink,
next_iteration_working_path.base(),
symlink_target, sizeof(symlink_target));
symlink_target, sizeof(symlink_target) - 1);
if (res < 1)
throw Symlink_resolve_error();
/* zero terminate target */
symlink_target[res] = 0;
if (symlink_target[0] == '/')
/* absolute target */
next_iteration_working_path.import(symlink_target, cwd().base());

View File

@ -659,7 +659,8 @@ class Plugin : public Libc::Plugin
ssize_t result = read(fd, buf, bufsiz);
if (verbose)
PDBG("result = %zd, buf = %s", result, buf);
PDBG("result = %zd, buf = %s", result, buf[result] ?
"<not zero terminated>" : buf);
close(fd);
return result;