From 755901d8350088aefd03c769f8c75865bf3d5a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 29 Oct 2004 13:05:03 +0000 Subject: [PATCH] bfs_read_stat() now correctly reports the size of a link for symbolic links that are short enough to be placed in the short symlink region. bfs_read_link() now makes sure that the link read is always null terminated. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9650 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/bfs/kernel_interface.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index f10a30791a..c22ed27852 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -640,7 +640,12 @@ bfs_read_stat(void *_ns, void *_node, struct stat *st) st->st_uid = node->UserID(); st->st_gid = node->GroupID(); st->st_mode = node->Mode(); - st->st_size = node->data.Size(); + + if (inode->IsSymLink() && (node->Flags() & INODE_LONG_SYMLINK) == 0) { + // symlinks report the size of the link here + st->st_size = strlen(node->short_symlink) + 1; + } else + st->st_size = node->data.Size(); st->st_atime = time(NULL); st->st_mtime = st->st_ctime = (time_t)(node->LastModifiedTime() >> INODE_TIME_SHIFT); @@ -1323,13 +1328,15 @@ bfs_read_link(void *_ns, void *_node, char *buffer, size_t bufferSize) RETURN_ERROR(B_BAD_VALUE); if (inode->Flags() & INODE_LONG_SYMLINK) { - if (inode->Size() > bufferSize) + // we also need space for the terminating null byte + if (inode->Size() >= bufferSize) return B_BUFFER_OVERFLOW; status_t status = inode->ReadAt(0, (uint8 *)buffer, &bufferSize); if (status < B_OK) RETURN_ERROR(status); + buffer[bufferSize] = '\0'; return B_OK; }