Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [patch] Avoid race in zf_mkdir
- X-seq: zsh-workers 47476
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: [patch] Avoid race in zf_mkdir
- Date: Thu, 22 Oct 2020 15:30:59 +0200
- Archived-at: <https://zsh.org/workers/47476>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-10/CAN%3D4vMr%2B57w69nEmmmFi%2BgbXxfTDwws-T0AQpDdnOS0fuKmqaA%40mail.gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-il1-f180.google.com) smtp.remote-ip=209.85.166.180; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RRLJrs6IO1BcN/J5nCgVw5PEUkIfWsM9i/lbZ+IV2SA=; b=gnJ9RgWSxzAPHiu8rTNmhiNxgkVspqJb5PzBJSpNvjMtc7xviDITuh8qEZg27UqzMo nsgxjkbnTWtyW++v1or6C99A4OQSDZZzK9zUFitjajdCG/QvSDq8hK9jcvT7byn4lkel UMUS3BFfZBXVMiMerQNym0VSb8GONmuxhXNXxu4LFu2qp5tvzEj5IQLfnVSX64YkU9G2 JVwaePqxVUJFinD3mZt52oLVZuvqg4B94FMkSgyGt9rFmtlz01ufPTZqns5Wgr6eHQoP 2Ankf4x1NQPvvwbWR2Oj3YSS8xDGeuLPCm1zFgq6gNn+utw+zrPpwHy8iP9QXRGrgma5 vY/w==
- In-reply-to: <CAN=4vMqxasXspkeObObB0tgwnEidSkL8oJPeU_uMaS2kwUdKig@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <20201009200737.GA78914@CptOrmolo.darkstar> <CAH+w=7anY9r+-MYki4cycVuaP2+d9L3W5u8k3sHyZx4R5kvafg@mail.gmail.com> <CAN=4vMoJrD+g4Go37yT6gF-Lx61vHm45GvmG1Fx6-+3yyb1hAQ@mail.gmail.com> <CAH+w=7ZRvW3Yq3XO6TwbK1hgSDNE8ynX0eQOU2dTuLcAELNUDg@mail.gmail.com> <20201009205357.GA6449@CptOrmolo.darkstar> <CAN=4vMqJ8SXkz_EVqwL7-9gCQYg9GMczOztAtsErirXGEDRq8Q@mail.gmail.com> <CAH+w=7ZfkwJY6a1LzR3n=LsOmB21WKUZMXfNzXN1hNDFpdeG2w@mail.gmail.com> <CAN=4vMpuSaF6BDhhUP=tnvDDMTN=iKExkmtb5QgtoeCqN_9D3g@mail.gmail.com> <CAN=4vMqihCrowyGTxKhkdzOQq3GcmWes3fuzYXJ1DBN9WsLnmA@mail.gmail.com> <CAH+w=7ZWYjRC8TX0-BekfW932pw_P15YSad03SJaHL8=3-S+zA@mail.gmail.com> <CAN=4vMqxasXspkeObObB0tgwnEidSkL8oJPeU_uMaS2kwUdKig@mail.gmail.com>
- Sender: zsh-workers-request@xxxxxxx
On Thu, Oct 15, 2020 at 5:36 PM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Thu, Oct 15, 2020 at 5:29 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > - I'm paranoid about tests like "while (n--)", I prefer "while (n-- > 0)".
>
> Changed. (Not publishing the new patch yet. Will do so once this
> discussion concludes.)
Here's the fixed version. Will commit soon.
Roman.
diff --git a/Src/Modules/files.c b/Src/Modules/files.c
index 6d20e38a8..7ebacba6c 100644
--- a/Src/Modules/files.c
+++ b/Src/Modules/files.c
@@ -122,19 +122,29 @@ domkdir(char *nam, char *path, mode_t mode, int p)
{
int err;
mode_t oumask;
+ struct stat st;
+ int n = 8;
char const *rpath = unmeta(path);
- if(p) {
- struct stat st;
-
- if(!stat(rpath, &st) && S_ISDIR(st.st_mode))
+ while(n-- > 0) {
+ oumask = umask(0);
+ err = mkdir(rpath, mode) ? errno : 0;
+ umask(oumask);
+ if (!err)
+ return 0;
+ if(!p || err != EEXIST)
+ break;
+ if(stat(rpath, &st)) {
+ if(errno == ENOENT)
+ continue;
+ err = errno;
+ break;
+ }
+ if(S_ISDIR(st.st_mode))
return 0;
+ break;
}
- oumask = umask(0);
- err = mkdir(rpath, mode) ? errno : 0;
- umask(oumask);
- if(!err)
- return 0;
+
zwarnnam(nam, "cannot make directory `%s': %e", path, err);
return 1;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author