From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Olaf Hering <olaf@aepfle.de>, Wei Liu <wei.liu2@citrix.com>,
Ian Campbell <Ian.Campbell@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [PATCH for-4.5] tools/pygrub: Fix TOCTOU race introduced by c/s 63dcc68
Date: Wed, 29 Oct 2014 14:09:41 +0000 [thread overview]
Message-ID: <1414591781-19376-1-git-send-email-andrew.cooper3@citrix.com> (raw)
In addition, use os.makedirs() which will also create intermediate directories
if they don't exist.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
CC: Olaf Hering <olaf@aepfle.de>
---
tools/pygrub/src/pygrub | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index 1ae34a2..37dde32 100644
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -13,7 +13,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
-import os, sys, string, struct, tempfile, re, traceback, stat
+import os, sys, string, struct, tempfile, re, traceback, stat, errno
import copy
import logging
import platform
@@ -846,8 +846,14 @@ if __name__ == "__main__":
if debug:
logging.basicConfig(level=logging.DEBUG)
- if not os.path.isdir(output_directory):
- os.mkdir(output_directory, 0700)
+
+ try:
+ os.makedirs(output_directory, 0700)
+ except OSError,e:
+ if (e.errno == errno.EEXIST) and os.path.isdir(output_directory):
+ pass
+ else:
+ raise
if output is None or output == "-":
fd = sys.stdout.fileno()
--
1.7.10.4
next reply other threads:[~2014-10-29 14:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 14:09 Andrew Cooper [this message]
2014-10-29 16:03 ` [PATCH for-4.5] tools/pygrub: Fix TOCTOU race introduced by c/s 63dcc68 Olaf Hering
2014-10-29 18:09 ` Andrew Cooper
2014-10-29 19:43 ` Olaf Hering
2014-11-04 10:48 ` Ian Campbell
2014-11-04 10:52 ` Please *justify* your use of the for-4.5 tag when posting patches Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1414591781-19376-1-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=olaf@aepfle.de \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).