git: 4f35450ce52a - main - compat_freebsd4: Check for errors from subyte() in freebsd4_uname()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 26 Dec 2023 02:04:18 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=4f35450ce52a7b141e7ae8d37fa257b5f8971dda

commit 4f35450ce52a7b141e7ae8d37fa257b5f8971dda
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-26 01:39:21 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-26 02:04:00 +0000

    compat_freebsd4: Check for errors from subyte() in freebsd4_uname()
    
    This is in preparation for adding a __result_use_check annotation to
    copyin() and related functions.
    
    Reviewed by:    imp, kib, jhb
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43099
---
 sys/kern/kern_xxx.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_xxx.c b/sys/kern/kern_xxx.c
index 540dc75b5545..e8331a5cdb1f 100644
--- a/sys/kern/kern_xxx.c
+++ b/sys/kern/kern_xxx.c
@@ -324,7 +324,9 @@ freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
 		1, 0, 0, 0, 0);
 	if (error)
 		return (error);
-	subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
+	error = subyte(uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
+	if (error)
+		return (EFAULT);
 
 	name[1] = KERN_HOSTNAME;
 	len = sizeof uap->name->nodename;
@@ -332,7 +334,9 @@ freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
 		1, 0, 0, 0, 0);
 	if (error)
 		return (error);
-	subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
+	error = subyte(uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
+	if (error)
+		return (EFAULT);
 
 	name[1] = KERN_OSRELEASE;
 	len = sizeof uap->name->release;
@@ -340,7 +344,9 @@ freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
 		1, 0, 0, 0, 0);
 	if (error)
 		return (error);
-	subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
+	error = subyte(uap->name->release + sizeof(uap->name->release) - 1, 0);
+	if (error)
+		return (EFAULT);
 
 /*
 	name = KERN_VERSION;
@@ -373,7 +379,9 @@ freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
 		1, 0, 0, 0, 0);
 	if (error)
 		return (error);
-	subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
+	error = subyte(uap->name->machine + sizeof(uap->name->machine) - 1, 0);
+	if (error)
+		return (EFAULT);
 	return (0);
 }