History log of /haiku/src/system/kernel/fs/KPath.cpp
Revision Date Author Comments
# 90bf90fa 10-Feb-2020 waddlesplash <waddlesplash@gmail.com>

kernel: Move memset of KPath buffer to after NULL check.


# d29d80eb 09-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Initialize allocated KPath buffers to 0.

KPaths are most commonly used in the VFS syscall paths,
and so they are typically user_memcpy'd to/from userland.
In the "to" case this is not really necessary (but it should
be so small of a performance difference as to not matter),
but in the "from" case, we must always clear the buffer
we received from the allocator, so as not to leak information
to userland.

Part of #14961.


# 42e3c6f9 10-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

KPath: Use an object_cache for the path buffers in the normal case.

This was (following the packagefs changes) the number-one (by call
count) consumer of malloc() during the boot -- 52866 calls, and 100%
of them either 1024 or 1025 bytes!

Virtually all of these are ephemeral (indeed, the object_cache
stats after a boot with this patch shows there is only a single slab
of 64 buffers allocated, and most of them unused), so this is
probably a significant performance boost.

Change-Id: I659f5707510cbfeafa735d35eea7b92732ead666


# a07f133e 16-Dec-2018 Augustin Cavalier <waddlesplash@gmail.com>

KPath: Prevent setting a KPath to itself causing use-after-free.

SetTo frees the buffer before setting it to the new one,
but if KPath sets itself to ... itself, then it will of course
try to access the buffer again.

Spotted by clang-analyzer (amidst quite a few false positives,
so this doesn't seem like an especially good rabbit hole
to go down right now.)


# 655aae6a 30-Apr-2017 Axel Dörfler <axeld@pinc-software.de>

KPathTest: Fix build for GCC 5.

* Also fixed a warning in KPath.
* Sorry, again!


# e9843da3 30-Apr-2017 Axel Dörfler <axeld@pinc-software.de>

KPath: Added LAZY_ALLOC flag.

* This allows KPath to not allocate a buffer when initialized
without path.
* Added test cases for this.
* Added test for LockBuffer().
* Enhanced tests to allow building them in debug mode.
* Moved calling vfs_normalize_path() into own private method.
* Improved error codes; B_NO_MEMORY is now only returned if the
allocation actually failed.
* If used with LAZY_ALLOC, Path() and LockBuffer() are now allowed
to return a NULL path.


# f94671c3 30-Apr-2017 Axel Dörfler <axeld@pinc-software.de>

KPath.Adopt(): Fixed path length.

* Issue was hidden due to inappropriate test values; changed test
to uncover it.


# eac83fb3 30-Apr-2017 Axel Dörfler <axeld@pinc-software.de>

KPath: Replaced booleans with flags field.

* No functional change intended; I chose the flags in a way that it
should still work even if I missed a reference.


# e1b4aed0 30-Apr-2017 Axel Dörfler <axeld@pinc-software.de>

KPath: Fixed Normalize() return code, changed Leaf().

* Normalize() now returns the error code that vfs_normalize_path()
returns.
* Leaf() now returns "" instead of "/" for the root. It's not used
outside of KPath.
* Adapted RemoveLeaf() to deal with this correctly.
* "KPath = string" no longer changes the buffer size.
* Added missing operator tests for =, ==, and !=.


# 4be51875 29-Apr-2017 Axel Dörfler <axeld@pinc-software.de>

KPath.Adopt() fixed incorrect path/buffer length.

* The other object was left in an inconsistent state.
* This lets the unit test for Adopt() pass.


# 3582d4fe 29-Apr-2017 Axel Dörfler <axeld@pinc-software.de>

Minor style cleanup.


# 9abf4591 07-Nov-2012 czeidler <haiku@clemens-zeidler.de>

Ok there are some more, thanks Rene.


# 71d45a0f 07-Nov-2012 czeidler <haiku@clemens-zeidler.de>

Coding style.


# bd5bd2c6 27-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Normalize() didn't update fPathLength correctly. This did probably screw
up module image paths in module_init_post_boot_device(). Not sure whether
it also could cause #2776.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27760 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e8d3eff9 26-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* vfs_normalize_path() and _user_normalize_path() use a common helper
function (normalize_path()), now. There was some code duplication
before.
* Added "bool traverseLink" parameter to vfs_normalize_path(). When
true and the leaf component is a symlink, it will be resolved.
* KPath:
- Added similar leaf link traversal parameter to SetTo() and
SetPath().
- Added Normalize().
- Added DetachBuffer(), which returns the object's current buffer and
unsets itself.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27751 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea26d9f0 14-May-2008 Stephan Aßmus <superstippi@gmx.de>

Honour 80 char/line limit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25508 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 56bbbbc9 08-May-2008 Axel Dörfler <axeld@pinc-software.de>

* Added Adopt() method that steals the other path's buffer.
* Fixed operator=(): the second argument of SetTo() is a boolean (normalize),
not the length of the buffer.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25382 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 23a60f42 08-May-2008 Axel Dörfler <axeld@pinc-software.de>

Reordered includes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5fce1ce7 07-May-2008 Stefano Ceccherini <stefano.ceccherini@gmail.com>

The second parameter of KPath::SetTo() is a bool, not a size_t. Reported
by Marc Flerackers. Thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25338 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3532662e 14-Jul-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

Added RemoveLeaf() leaf method. Very handy for recursive directory
iteration code using a single KPath object.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21606 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0d4c16e0 05-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

* Reduced the stack usage of most of the I/O paths - there were several places
that put one or more full paths on the stack before, which could cause some
problems under certain conditions.
* Cleaned up KPath, ie. use size_t instead of int32 where appropriate, added
license.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16585 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d690920 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed system/core to system/kernel.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12360 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9abf4591d5b44b2e3e52190c2b2a427a81be2691 07-Nov-2012 czeidler <haiku@clemens-zeidler.de>

Ok there are some more, thanks Rene.


# 71d45a0f7617c453858d6aceff57c27c156d074e 07-Nov-2012 czeidler <haiku@clemens-zeidler.de>

Coding style.


# bd5bd2c61e4d3339933ace510382db0f89e57689 27-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Normalize() didn't update fPathLength correctly. This did probably screw
up module image paths in module_init_post_boot_device(). Not sure whether
it also could cause #2776.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27760 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e8d3eff9689f3436efa2863b9bf4afc84f79e0a3 26-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* vfs_normalize_path() and _user_normalize_path() use a common helper
function (normalize_path()), now. There was some code duplication
before.
* Added "bool traverseLink" parameter to vfs_normalize_path(). When
true and the leaf component is a symlink, it will be resolved.
* KPath:
- Added similar leaf link traversal parameter to SetTo() and
SetPath().
- Added Normalize().
- Added DetachBuffer(), which returns the object's current buffer and
unsets itself.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27751 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea26d9f0c20a65154e210cef3d3bc797be152d0f 14-May-2008 Stephan Aßmus <superstippi@gmx.de>

Honour 80 char/line limit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25508 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 56bbbbc9ca07e097c948cd59d3f70d4bb363f19c 08-May-2008 Axel Dörfler <axeld@pinc-software.de>

* Added Adopt() method that steals the other path's buffer.
* Fixed operator=(): the second argument of SetTo() is a boolean (normalize),
not the length of the buffer.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25382 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 23a60f423e76739d22149d00d6a88cec02a2d776 08-May-2008 Axel Dörfler <axeld@pinc-software.de>

Reordered includes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5fce1ce7c029271f38d5562d24b3ed68404dd076 07-May-2008 Stefano Ceccherini <stefano.ceccherini@gmail.com>

The second parameter of KPath::SetTo() is a bool, not a size_t. Reported
by Marc Flerackers. Thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25338 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3532662e0c5f385a64db401663b9a136c323a6a9 14-Jul-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

Added RemoveLeaf() leaf method. Very handy for recursive directory
iteration code using a single KPath object.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21606 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0d4c16e0c08ba45ee32177fae63fdeb5b71b52a1 05-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

* Reduced the stack usage of most of the I/O paths - there were several places
that put one or more full paths on the stack before, which could cause some
problems under certain conditions.
* Cleaned up KPath, ie. use size_t instead of int32 where appropriate, added
license.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16585 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d690920ac4d0cd27eb3c118fb2b0862615869e0 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed system/core to system/kernel.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12360 a95241bf-73f2-0310-859d-f6bbb57e9c96