git: 927ed6112270 - stable/15 - inetd: use snprintf() in inetd_setproctitle()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 06 Nov 2026 19:54:49 UTC
The branch stable/15 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=927ed6112270ba5e1a07b770dd9d2a6096f9ae39

commit 927ed6112270ba5e1a07b770dd9d2a6096f9ae39
Author:     Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-10-20 15:40:28 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-06 15:52:19 +0000

    inetd: use snprintf() in inetd_setproctitle()
    
    inetd_setproctitle() formats se_service (the service name taken verbatim
    from inetd.conf) and the peer address into an 80-byte buffer with
    sprintf(). A long service name can overflow it. Bound both calls with
    snprintf().
    
    MFC after:      1 week
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D60879
    
    (cherry picked from commit 9ab2bf0f4296e8bfafe4dc70f2f200265e6933bd)
---
 usr.sbin/inetd/inetd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c
index 33316ce170a1..ef7ff023ec3b 100644
--- a/usr.sbin/inetd/inetd.c
+++ b/usr.sbin/inetd/inetd.c
@@ -2090,9 +2090,9 @@ inetd_setproctitle(const char *a, int s)
 	if (getpeername(s, (struct sockaddr *)&ss, &size) == 0) {
 		getnameinfo((struct sockaddr *)&ss, size, pbuf, sizeof(pbuf),
 			    NULL, 0, NI_NUMERICHOST);
-		(void) sprintf(buf, "%s [%s]", a, pbuf);
+		(void) snprintf(buf, sizeof(buf), "%s [%s]", a, pbuf);
 	} else
-		(void) sprintf(buf, "%s", a);
+		(void) snprintf(buf, sizeof(buf), "%s", a);
 	setproctitle("%s", buf);
 }