From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzLNT-0001ml-B4 for qemu-devel@nongnu.org; Mon, 01 Jun 2015 04:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzLNO-0005Rj-39 for qemu-devel@nongnu.org; Mon, 01 Jun 2015 04:47:23 -0400 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:34297) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzLNN-0005Rf-Tr for qemu-devel@nongnu.org; Mon, 01 Jun 2015 04:47:18 -0400 Received: by wibut5 with SMTP id ut5so31515952wib.1 for ; Mon, 01 Jun 2015 01:47:17 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <556C1C0B.6030209@redhat.com> Date: Mon, 01 Jun 2015 10:47:07 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1433142369-14266-1-git-send-email-mrezanin@redhat.com> <87iob7lv1p.fsf@blackfin.pond.sub.org> In-Reply-To: <87iob7lv1p.fsf@blackfin.pond.sub.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] net: fix insecure temporary file creation in SLiRP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , mrezanin@redhat.com Cc: pmatouse@redhat.com, Michael Tokarev , qemu-devel@nongnu.org, P J P On 01/06/2015 09:58, Markus Armbruster wrote: >> > - snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.%ld-%d", >> > - (long)getpid(), instance++); >> > - if (mkdir(s->smb_dir, 0700) < 0) { >> > - error_report("could not create samba server dir '%s'", s->smb_dir); >> > + if (!(tmpdir = mkdtemp(smb_dir))) { mkdtemp is unfortunately missing on Windows, and g_mkdtemp requires glib 2.30. Paolo >> > + error_report("could not create samba server dir '%s'", smb_dir); >> > return -1; >> > } >> > + strncpy(s->smb_dir, tmpdir, sizeof(s->smb_dir)); > We tend to eschew strncpy() and use our (slightly less bad) pstrcpy(). > Recommend to use it here, too. > >> > snprintf(smb_conf, sizeof(smb_conf), "%s/%s", s->smb_dir, >> > "smb.conf"); >> > >> > f = fopen(smb_conf, "w"); > Michael (cc'ed) already posted "[PATCH] slirp: use less predictable > directory name in /tmp for smb config (CVE-2015-4037)"[*]. His patch > clobbers s->smb_dir[] when mkdtemp() fails (missed that in my review), > yours doesn't. > > Suggest you guys figure out together which solution you want. > > Preferably with strncpy() replaced by pstrcpy(): > Reviewed-by: Markus Armbruster