Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Mangement of fdtable[]

Dear Bart,

Thanks for digging my problem. In fact my codes uses zsocket. I think
they're similar and they actually cause the same bug. I give a TCP example
because I think it's easier to reproduce on different platforms.

In Src/Modules/socket.c, fdtable is checked but not updated. Maybe it sould
be fixed, too?

Best Regards,

Yen Chi Hsuan

On 16 October 2015 at 08:22, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>

> I was puzzling over Yen Chi Hsuan's bug report in 36866 so was looking
> through tcp.c and noticed that it opens file descriptors with socket()
> without marking them used in fdtable[].  The only time they're handled
> "properly" is with "ztcp -l" which makes a movefd() call.
> I think this means some fds may be closed in some cases they shouldn't,
> or conversely left open in cases they shouldn't.  This may apply to fds
> in other modules, e.g., the descriptor from gdbm_open() in db_gdbm.c.
> This further led me to notice that when descriptors are manipulated in
> utils.c, it carefully calls the static check_fd_table() function every
> time to be sure the descriptor has a slot in the table before an FDT_*
> value is poked for it.  Other parts of the code (mostly exec.c) simply
> reference fdtable[N] without error checking.
> I guess this is OK because fdtable[] is allocated zopenmax() slots in
> zsh_main(), but it seems inconsistent if not actually wrong.
> Comments?
> --
> Barton E. Schaefer

Messages sorted by: Reverse Date, Date, Thread, Author