<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/lib/libc/stdlib/realpath.c, branch release/14.4.0</title>
<subtitle>FreeBSD source tree</subtitle>
<id>https://cgit-dev.freebsd.org/src/atom?h=release%2F14.4.0</id>
<link rel='self' href='https://cgit-dev.freebsd.org/src/atom?h=release%2F14.4.0'/>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/'/>
<updated>2025-10-20T16:11:34Z</updated>
<entry>
<title>realpath: Report correct path on failure</title>
<updated>2025-10-20T16:11:34Z</updated>
<author>
<name>Dag-Erling Smørgrav</name>
<email>des@FreeBSD.org</email>
</author>
<published>2025-10-13T11:53:22Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=bebae0e231290833b04935e4c18e25931e766587'/>
<id>urn:sha1:bebae0e231290833b04935e4c18e25931e766587</id>
<content type='text'>
If lstat() fails with EACCES or ENOTDIR, the path we need to return in
the caller-provided buffer is that of the parent directory (which is
either unreadable or not a directory; the latter can only happen in the
case of a race) rather than that of the child we attempted to stat.

Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D53025

(cherry picked from commit 1406de21e176d8700240ac9e473df007cd41eec1)
</content>
</entry>
<entry>
<title>libc: Purge unneeded cdefs.h</title>
<updated>2023-11-27T04:20:09Z</updated>
<author>
<name>Warner Losh</name>
<email>imp@FreeBSD.org</email>
</author>
<published>2023-11-01T22:43:37Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=4025b5b527c870cf095ac9531764f4e4d3feaec2'/>
<id>urn:sha1:4025b5b527c870cf095ac9531764f4e4d3feaec2</id>
<content type='text'>
These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Keep those.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D42385

(cherry picked from commit 559a218c9b257775fb249b67945fe4a05b7a6b9f)
</content>
</entry>
<entry>
<title>Remove $FreeBSD$: one-line .c pattern</title>
<updated>2023-08-16T17:54:42Z</updated>
<author>
<name>Warner Losh</name>
<email>imp@FreeBSD.org</email>
</author>
<published>2023-08-16T17:54:42Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=1d386b48a555f61cb7325543adbbb5c3f3407a66'/>
<id>urn:sha1:1d386b48a555f61cb7325543adbbb5c3f3407a66</id>
<content type='text'>
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
</content>
</entry>
<entry>
<title>vfs: add realpathat syscall</title>
<updated>2020-02-20T16:58:19Z</updated>
<author>
<name>Mateusz Guzik</name>
<email>mjg@FreeBSD.org</email>
</author>
<published>2020-02-20T16:58:19Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=0573d0a9b8ec478348cbf2a7ec370c875eb57dff'/>
<id>urn:sha1:0573d0a9b8ec478348cbf2a7ec370c875eb57dff</id>
<content type='text'>
realpath(3) is used a lot e.g., by clang and is a major source of getcwd
and fstatat calls. This can be done more efficiently in the kernel.

This works by performing a regular lookup while saving the name and found
parent directory. If the terminal vnode is a directory we can resolve it using
usual means. Otherwise we can use the name saved by lookup and resolve the
parent.

See the review for sample syscall counts.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D23574
</content>
</entry>
<entry>
<title>Fix -Wsign-compare warnings in realpath.c</title>
<updated>2019-06-26T15:43:20Z</updated>
<author>
<name>Alex Richardson</name>
<email>arichardson@FreeBSD.org</email>
</author>
<published>2019-06-26T15:43:20Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=df5e39248342eb6579361b756fb07d2ee08e6955'/>
<id>urn:sha1:df5e39248342eb6579361b756fb07d2ee08e6955</id>
<content type='text'>
This is needed in order to build realpath.c as part of rtld.
</content>
</entry>
<entry>
<title>libc: further adoption of SPDX licensing ID tags.</title>
<updated>2017-11-25T17:12:48Z</updated>
<author>
<name>Pedro F. Giffuni</name>
<email>pfg@FreeBSD.org</email>
</author>
<published>2017-11-25T17:12:48Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=d915a14ef094c8dfc1a5aee70e135abfec01d0f1'/>
<id>urn:sha1:d915a14ef094c8dfc1a5aee70e135abfec01d0f1</id>
<content type='text'>
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
</content>
</entry>
<entry>
<title>Style.</title>
<updated>2017-05-15T17:54:36Z</updated>
<author>
<name>Konstantin Belousov</name>
<email>kib@FreeBSD.org</email>
</author>
<published>2017-05-15T17:54:36Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=cf5cedd78512db4977037e04d5011ae4f020204c'/>
<id>urn:sha1:cf5cedd78512db4977037e04d5011ae4f020204c</id>
<content type='text'>
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
</content>
</entry>
<entry>
<title>Simplify cleanup on failure in realpath(3).</title>
<updated>2017-05-15T17:34:17Z</updated>
<author>
<name>Konstantin Belousov</name>
<email>kib@FreeBSD.org</email>
</author>
<published>2017-05-15T17:34:17Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=d933a4c06b742a42c4ca94951be231b053032436'/>
<id>urn:sha1:d933a4c06b742a42c4ca94951be231b053032436</id>
<content type='text'>
If realpath() allocated memory for result and failed, the memory is
freed in each place where return is performed.  More, the function
needs to track the allocation status, to not free user-supplied
buffer.

Consolidate the memory handling in the wrapper, freeing the buffer if
the actual worker failed.

Reviewed by:	emaste (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D10670
</content>
</entry>
<entry>
<title>Fix several buffer overflows in realpath(3).</title>
<updated>2017-05-15T17:14:53Z</updated>
<author>
<name>Konstantin Belousov</name>
<email>kib@FreeBSD.org</email>
</author>
<published>2017-05-15T17:14:53Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=f81e5b2d9bd4d0199bed864cafb12422cc1d71b6'/>
<id>urn:sha1:f81e5b2d9bd4d0199bed864cafb12422cc1d71b6</id>
<content type='text'>
- The statement "left_len -= s - left;" does not take the slash into
  account if one was found. This results in the invariant
  "left[left_len] == '\0'" being violated (and possible buffer
  overflows). The patch replaces the variable "s" with a size_t
  "next_token_len" for more clarity.
- "slen" from readlink(2) can be 0 when encountering empty
  symlinks. Then, further down, "symlink[slen - 1]" underflows the
  buffer. When slen == 0, realpath(3) should probably return ENOENT
  (http://austingroupbugs.net/view.php?id=825,
  https://lwn.net/Articles/551224/).

Some other minor issues:
- The condition "resolved_len &gt;= PATH_MAX" cannot be true.
- Similarly, "s - left &gt;= sizeof(next_token)" cannot be true, as long
  as "sizeof(next_token) &gt;= sizeof(left)".
- Return ENAMETOOLONG when a resolved symlink from readlink(2) is too
  long for the symlink buffer (instead of just truncating it).
- "resolved_len &gt; 1" below the call to readlink(2) is always true as
  "strlcat(resolved, next_token, PATH_MAX);" always results in a
  string of length &gt; 1. Also, "resolved[resolved_len - 1] = '\0';" is
  not needed; there can never be a trailing slash here.
- The truncation check for "strlcat(symlink, left, sizeof(symlink));"
  should be against "sizeof(symlink)" (the third argument to strlcat)
  instead of "sizeof(left)".

Submitted by:	Jan Kokemц╪ller &lt;jan.kokemueller@gmail.com&gt;
PR:	219154
MFC after:	2 weeks
</content>
</entry>
<entry>
<title>realpath(): Properly fail "." or ".." components after non-directories.</title>
<updated>2014-04-13T19:48:28Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2014-04-13T19:48:28Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=310c8f3c99499326d1053ce811348bf2e35e09af'/>
<id>urn:sha1:310c8f3c99499326d1053ce811348bf2e35e09af</id>
<content type='text'>
If realpath() is called on pathnames like "/dev/null/." or "/dev/null/..",
it should fail with [ENOTDIR]. Pathnames like "/dev/null/" already failed as
they should.

Also, put the check for non-directories after lstatting the previous
component instead of when the empty component (consecutive or trailing
slashes) is detected, saving an lstat() call and some lines of code.

PR:		kern/82980
MFC after:	2 weeks
</content>
</entry>
</feed>
