Date: Tue, 24 Oct 2000 17:00:54 +0200 From: Jeroen Ruigrok van der Werven <jruigrok@via-net-works.nl> To: audit@FreeBSD.ORG Subject: Re: printjob.c mktemp() problem Message-ID: <20001024170054.Q93799@lucifer.bart.nl> In-Reply-To: <20001024140510.G93799@lucifer.bart.nl>; from jruigrok@via-net-works.nl on Tue, Oct 24, 2000 at 02:05:10PM %2B0200 References: <20001024140510.G93799@lucifer.bart.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
--sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline -On [20001024 14:10], Jeroen Ruigrok van der Werven (jruigrok@via-net-works.nl) wrote: >Am I right into thinking this might be a good candidate for a >mktemp()->mkstemp() conversion? See attached patch. The patch might not be totally accurate yet, but that due to the code throwing me off at one point, namely the dup2(n, 2); and the unlink(tempfile); Also, is the syslog level ok for a tempfile which couldn't be created? -- Jeroen Ruigrok van der Werven Network- and systemadministrator <jruigrok@via-net-works.nl> VIA Net.Works The Netherlands BSD: Technical excellence at its best http://www.via-net-works.nl These days get so long and I got nothing to do... --sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="printjob.c.diff" --- printjob.c.orig Tue Oct 24 15:38:17 2000 +++ printjob.c Tue Oct 24 16:59:20 2000 @@ -168,8 +168,6 @@ signal(SIGQUIT, abortpr); signal(SIGTERM, abortpr); - (void) mktemp(tempfile); - /* * uses short form file names */ @@ -553,7 +551,7 @@ int format; char *file; { - register int n, i; + register int n, i = -1; register char *prog; int fi, fo; FILE *fp; @@ -733,7 +731,11 @@ if ((child = dofork(pp, DORETURN)) == 0) { /* child */ dup2(fi, 0); dup2(fo, 1); - n = open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, 0664); + if ((n = mkstemp(tempfile)) == -1) { + syslog(LOG_WARNING, "%s: %s: %m", pp->printer, tempfile); + return -1; + } + fchmod(n, 0664); if (n >= 0) dup2(n, 2); closelog(); --sm4nu43k4a2Rpi4c-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001024170054.Q93799>