git: 057da12eeaa6 - stable/14 - kern___realpathat(): do not copyout past end of string

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 02 Dec 2024 01:46:18 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=057da12eeaa6700793340ffcfede620135b7f540

commit 057da12eeaa6700793340ffcfede620135b7f540
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-11-25 12:41:46 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-12-02 01:44:55 +0000

    kern___realpathat(): do not copyout past end of string
    
    (cherry picked from commit 67218bcea847c93ccd002335748884b02a3ca807)
---
 sys/kern/vfs_cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index d48c1c0be80a..aa6141cb0230 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -3203,7 +3203,7 @@ kern___realpathat(struct thread *td, int fd, const char *path, char *buf,
 		    &freebuf, &size);
 	}
 	if (error == 0) {
-		error = copyout(retbuf, buf, size);
+		error = copyout(retbuf, buf, min(strlen(retbuf) + 1, size));
 		free(freebuf, M_TEMP);
 	}
 out: