[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] tools/pygrub: Fix TOCTOU race introduced by c/s 63dcc68



commit beb0ef5f747bac4c6464383d74259b14adbfce19
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed Oct 29 14:09:41 2014 +0000
Commit:     Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Tue Nov 4 10:03:31 2014 +0000

    tools/pygrub: Fix TOCTOU race introduced by c/s 63dcc68
    
    In addition, use os.makedirs() which will also create intermediate 
directories
    if they don't exist.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
    CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
    CC: Wei Liu <wei.liu2@xxxxxxxxxx>
    CC: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
    CC: Olaf Hering <olaf@xxxxxxxxx>
    Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/pygrub/src/pygrub |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index 4cc846f..aa7e562 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
@@ -851,8 +851,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()
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.