aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2024-11-27 20:36:46 +0000
committerEd Maste <emaste@FreeBSD.org>2024-12-02 21:10:31 +0000
commit957f7a2a58e550bd31d8ebec67f99d19087746a2 (patch)
treeca2d6407c116449a86751eeb47cd99c4670e9b9c
parent2d7d4c66269d25cda284fd7129ae561f40d253a0 (diff)
comsat: Improve use of setuid()
Just return from jkfprintf if either (a) user lookup fails (that is, getpwnam fails) or (b) setuid() to the user's uid fails. If comsat is invoked from inetd using the default of tty:tty we will now return due to setuid() failing rather than fopen() failing. PR: 270404 Reviewed by: kevans Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47823 (cherry picked from commit 062b69ba045dc0fef3d9b8d73365d2798c05a480)
-rw-r--r--libexec/comsat/comsat.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c
index 138881db9e4a..3f94f8d56201 100644
--- a/libexec/comsat/comsat.c
+++ b/libexec/comsat/comsat.c
@@ -225,8 +225,10 @@ jkfprintf(FILE *tp, char user[], char file[], off_t offset)
unsigned char line[BUFSIZ];
/* Set effective uid to user in case mail drop is on nfs */
- if ((p = getpwnam(user)) != NULL)
- (void) setuid(p->pw_uid);
+ if ((p = getpwnam(user)) == NULL)
+ return;
+ if (setuid(p->pw_uid) != 0)
+ return;
if ((fi = fopen(file, "r")) == NULL)
return;