mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
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 <gniibe@fsij.org>
This commit is contained in:
parent
374195e741
commit
71840b57f4
@ -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))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user