On Sat, Jun 6, 2026 at 8:54 PM <[email protected]> wrote:
>
> From: Diego Nieto Cid <[email protected]>
>
> fcntl with the F_DUPFD_CLOEXEC expect a third int argument
> which would take whatever garbage is in the stack if not
> provided.

Good catch, thanks!

And a reminder that my own work [0][1] on making glibc emit a
compile-time error on getting this wrong never landed.

[0]: https://sourceware.org/pipermail/libc-alpha/2023-July/150498.html
[1]: https://sourceware.org/pipermail/libc-alpha/2023-May/148569.html

> ---
>  main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/main.c b/main.c
> index 423d249..b34232f 100644
> --- a/main.c
> +++ b/main.c
> @@ -427,7 +427,7 @@ establish_connection ()
>    if (fd < 0)
>      error (1, errno, "Cannot open connection");
>
> -  fd_dup = fcntl (fd, F_DUPFD_CLOEXEC);
> +  fd_dup = fcntl (fd, F_DUPFD_CLOEXEC, fd);

But why use fd, should we not pass 0 if we don't care about the
resulting numeric value?

Sergey

Reply via email to