git: 7c21545c46e1 - main - tftpd: Ensure that tftp_log() preserves errno.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Fri, 10 Mar 2023 13:29:16 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=7c21545c46e1290e66fd9e9300165b4a381161b9

commit 7c21545c46e1290e66fd9e9300165b4a381161b9
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-03-10 13:24:19 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-03-10 13:25:16 +0000

    tftpd: Ensure that tftp_log() preserves errno.
    
    Sponsored by:   Klara, Inc.
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D38956
---
 libexec/tftpd/tftp-utils.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libexec/tftpd/tftp-utils.c b/libexec/tftpd/tftp-utils.c
index 322b5ad9ae62..1647ad8be1c9 100644
--- a/libexec/tftpd/tftp-utils.c
+++ b/libexec/tftpd/tftp-utils.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <netinet/in.h>
 #include <arpa/tftp.h>
 
+#include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -148,8 +149,10 @@ void
 tftp_log(int priority, const char *message, ...)
 {
 	va_list ap;
+	int serrno;
 	char *s;
 
+	serrno = errno;
 	va_start(ap, message);
 	if (_tftp_logtostdout == 0) {
 		vasprintf(&s, message, ap);
@@ -159,6 +162,7 @@ tftp_log(int priority, const char *message, ...)
 		printf("\n");
 	}
 	va_end(ap);
+	errno = serrno;
 }
 
 /*