[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bash-3.2.39] race condition on AIX when using libtool with bash
From: |
Michael Haubenwallner |
Subject: |
Re: [bash-3.2.39] race condition on AIX when using libtool with bash |
Date: |
Thu, 31 Jul 2008 09:16:23 +0200 |
On Wed, 2008-07-30 at 18:53 +0200, Michael Haubenwallner wrote:
<snip>
> Now I can see (stripped the unimportant):
> open("GetWMCMapW.loT", O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE) = 4
> kfcntl(4, 14, 0x00000001) = 1
> close(4) = 0
> open("/tmp//sh-thd-1217607265",
> O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_LARGEFILE) = 4
> kfcntl(4, F_DUPFD, 0x00000000) = 5
> kwrite(5, " p i c _ o b j e c t = '".., 32) = 32
> close(5) = 0
> open("/tmp//sh-thd-1217607265", O_RDONLY|O_LARGEFILE) = 5
> close(4) = 0
> unlink("/tmp//sh-thd-1217607265") = 0
> kfcntl(5, 14, 0x00000000) = 0
> close(5) = 0
> execve("/usr/bin/cat", 0x200234E8, 0x20026968) argc: 1
> argv: cat
> kread(0, " p i c _ o b j e c t = '".., 4096) = 32
> kwrite(1, " p i c _ o b j e c t = '".., 32) = 32
> kread(0, " p i c _ o b j e c t = '".., 4096) = 0
> close(1) = 0
> _exit(0)
>
> So I'm sure the missing commands above _are_ executed.
>
>
> My speculation:
> 1) bash opens the here-document twice, first O_WRONLY, second O_RDONLY,
> dup2'ing the second handle to stdin before doing exec('cat'), removing
> the file immediately after the second open.
>
> 2) ksh opens the here-document only once, with O_RDWR, and dup's that
> handle to stdin before doing exec('cat'), removing the file immediately
> after the open.
Forgot to mention that ksh does fseek() to zero before exec("cat").
>
> Could one think of: when opening the file the second time, the content
> of the first write isn't on-disk yet (because the content might fit into
> some aix write buffer), or already removed by someone else in the
> meantime, or something like that?
Sorry, I've been wrong here: "cat" actually _can_ read the content, so
the double-open is not the problem here. Although IMHO it still might be
better for security and performance reasons to open() only once, and
fseek() to zero like ksh does.
/haubi/
--
Michael Haubenwallner
Gentoo on a different level