From dffaad9de294667c66fab79d7f67717054cc8584 Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Thu, 19 Jan 2017 14:02:47 +0900 Subject: [PATCH] opal/util: fix a race condition in opal_os_dirpath_create() always check the permissions of the created directory, in case some one else created the very same directory but with incompatible permissions Signed-off-by: Gilles Gouaillardet --- opal/util/os_dirpath.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/opal/util/os_dirpath.c b/opal/util/os_dirpath.c index 9ef9ebb96b..2328179d7f 100644 --- a/opal/util/os_dirpath.c +++ b/opal/util/os_dirpath.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2015-2016 Research Organization for Information Science + * Copyright (c) 2015-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2016-2017 Intel, Inc. All rights reserved. * $COPYRIGHT$ @@ -121,6 +121,12 @@ int opal_os_dirpath_create(const char *path, const mode_t mode) opal_argv_free(parts); free(tmp); return OPAL_ERROR; + } else if (i == (len-1) && (mode != (mode & buf.st_mode)) && (0 > chmod(tmp, (buf.st_mode | mode)))) { + opal_show_help("help-opal-util.txt", "dir-mode", true, + tmp, mode, strerror(errno)); + opal_argv_free(parts); + free(tmp); + return(OPAL_ERR_PERM); /* can't set correct mode */ } }