From owner-freebsd-audit Tue Oct 24 8: 0:59 2000 Delivered-To: freebsd-audit@freebsd.org Received: from lucifer.ninth-circle.org (lucifer.bart.nl [194.158.168.74]) by hub.freebsd.org (Postfix) with ESMTP id F2F0E37B4C5 for ; Tue, 24 Oct 2000 08:00:55 -0700 (PDT) Received: (from asmodai@localhost) by lucifer.ninth-circle.org (8.11.0/8.11.0) id e9OF0sS98388 for audit@FreeBSD.ORG; Tue, 24 Oct 2000 17:00:54 +0200 (CEST) (envelope-from asmodai) Date: Tue, 24 Oct 2000 17:00:54 +0200 From: Jeroen Ruigrok van der Werven To: audit@FreeBSD.ORG Subject: Re: printjob.c mktemp() problem Message-ID: <20001024170054.Q93799@lucifer.bart.nl> References: <20001024140510.G93799@lucifer.bart.nl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="sm4nu43k4a2Rpi4c" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20001024140510.G93799@lucifer.bart.nl>; from jruigrok@via-net-works.nl on Tue, Oct 24, 2000 at 02:05:10PM +0200 Organisation: VIA Net.Works The Netherlands Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --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 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