[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fdopendir: Fix fd leak and test failure on native Windows
|
From: |
KO Myung-Hun |
|
Subject: |
Re: fdopendir: Fix fd leak and test failure on native Windows |
|
Date: |
Thu, 11 May 2023 00:44:17 +0900 |
|
User-agent: |
Mozilla/5.0 (OS/2; Warp 4.5; rv:10.0.6esrpre) Gecko/20120715 Firefox/10.0.6esrpre SeaMonkey/2.7.2 |
Bruno Haible wrote:
> KO Myung-Hun wrote:
>>> @@ -78,11 +82,17 @@ _gl_unregister_dirp_fd (int fd)
>>> int
>>> dirfd (DIR *dir_p)
>>> {
>>> +#if GNULIB_defined_DIR
>>> + int fd = dir_p->fd_to_close;
>>
>> dirfd() allows to take an invalid `dir_p' ?
>
> No; this must be a misunderstanding.
>
> dirfd is specified at
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html
> Which says that if "The dirp argument does not refer to a valid directory
> stream"
> the function may fail with error EINVAL. It may alternatively simply crash
> ("the behavior is undefined").
>
Then, gnulib decided to crash instead of returning -1 with setting errno
to EINAL if dir_p has the garbage value which is not returned by opendir() ?
> In this code, we have two cases, depending on platforms:
> - If GNULIB_defined_DIR, it means that gnulib has defined or overridden
> the 'DIR' type, to include an 'fd_to_close' field'.
> Currently that's only on native Windows, but I'm suggesting that the same
> code could also be used on kLIBC.
> - Otherwise, gnulib uses either the system-provided dirfd function or macro,
> or does a lookup in dir_p->d_fd or dir_p->dd_fd.
>
> Bruno
>
>
>
--
KO Myung-Hun
Korean OS/2 User Community : https://www.os2.kr/