aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2024-10-16 01:04:18 +0000
committerNIIBE Yutaka <[email protected]>2024-10-16 01:04:18 +0000
commit71840b57f48680b7555451a29026d9c6de4fe2bc (patch)
tree51e55d9c503234dc1756c679c098933066166b15 /common
parentgpgsm: Fix cached istrusted lookup. (diff)
downloadgnupg-71840b57f48680b7555451a29026d9c6de4fe2bc.tar.gz
gnupg-71840b57f48680b7555451a29026d9c6de4fe2bc.zip
common: Fix a race condition in creating socketdir.
* common/homedir.c (_gnupg_socketdir_internal): Check return code of gnupg_mkdir and handle the case of GPG_ERR_EEXIST. -- GnuPG-bug-id: 7332 Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'common')
-rw-r--r--common/homedir.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/common/homedir.c b/common/homedir.c
index a73182e30..8ef402b33 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -1124,6 +1124,7 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
{
#if defined(HAVE_W32_SYSTEM)
char *name;
+ gpg_err_code_t ec;
(void)skip_checks;
@@ -1201,7 +1202,8 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
else if (!skip_checks)
{
/* Try to create the directory and check again. */
- if (gnupg_mkdir (name, "-rwx"))
+ ec = gnupg_mkdir (name, "-rwx");
+ if (ec && ec != GPG_ERR_EEXIST)
*r_info |= 16; /* mkdir failed. */
else if (gnupg_stat (name, &sb))
{
@@ -1259,6 +1261,7 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
const char *s;
char *name = NULL;
const char *gnupgname = my_gnupg_dirname ();
+ gpg_err_code_t ec;
*r_info = 0;
@@ -1316,8 +1319,14 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
goto leave;
}
- /* Try to create the directory and check again. */
- if (gnupg_mkdir (prefix, "-rwx"))
+ /* Try to create the directory and check again.
+ * Here comes a possible race condition:
+ * stat(2) above failed by ENOENT, but another process does
+ * mkdir(2) before we do mkdir(2)
+ * So, an error with EEXIST should be handled.
+ */
+ ec = gnupg_mkdir (prefix, "-rwx");
+ if (ec && ec != GPG_ERR_EEXIST)
{
*r_info |= 16; /* mkdir failed. */
goto leave;
@@ -1376,7 +1385,8 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
else if (!skip_checks)
{
/* Try to create the directory and check again. */
- if (gnupg_mkdir (name, "-rwx"))
+ ec = gnupg_mkdir (name, "-rwx");
+ if (ec && ec != GPG_ERR_EEXIST)
*r_info |= 16; /* mkdir failed. */
else if (stat (prefix, &sb))
{