From: Remi Gacogne Date: Wed, 29 May 2019 13:33:58 +0000 (+0200) Subject: auth: Use mkstemp() to generate a temporary file name X-Git-Tag: dnsdist-1.4.0-beta1~8^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17239e89b38b328bd67cf00c248174d70acab62b;p=pdns auth: Use mkstemp() to generate a temporary file name Reported by Coverity (CID 1401682). --- diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index ee3ffffdf..afeeaadef 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -203,17 +203,27 @@ bool Bind2Backend::startTransaction(const DNSName &qname, int id) d_transaction_id=id; BB2DomainInfo bbd; if(safeGetBBDomainInfo(id, &bbd)) { - d_transaction_tmpname=bbd.d_filename+"."+itoa(random()); - d_of=std::unique_ptr(new ofstream(d_transaction_tmpname.c_str())); + d_transaction_tmpname = bbd.d_filename + "XXXXXX"; + int fd = mkstemp(&d_transaction_tmpname.at(0)); + if (fd == -1) { + throw DBException("Unable to create a unique temporary zonefile '"+d_transaction_tmpname+"': "+stringerror()); + return false; + } + + d_of = std::unique_ptr(new ofstream(d_transaction_tmpname.c_str())); if(!*d_of) { unlink(d_transaction_tmpname.c_str()); + close(fd); + fd = -1; d_of.reset(); throw DBException("Unable to open temporary zonefile '"+d_transaction_tmpname+"': "+stringerror()); } - + close(fd); + fd = -1; + *d_of<<"; Written by PowerDNS, don't edit!"<