From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23410 invoked by alias); 16 Oct 2015 09:56:24 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36874 Received: (qmail 23342 invoked from network); 16 Oct 2015 09:56:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=z5BpdKwc6eMxrV1XPOKlSk4fsX6C0loAKhbRy/mbOSw=; b=cgciJsXxLG7RfbayLg9+cJ32HUBIXYn/KNWDU1rToBx0wM4n2OROoRuCUOxmbVOGAR LdyKnNRs0YY1AkrD+GciJZoMwBNmBUD6PAL8Gso1S5PctF8REpkts3SsnLprQVkscHOM Hvha/GpNLDc5usO0lZNJeuK5akmo9xqnwzOKC1pHEC8q9mjpF+P9TM4ev5yZpkGSel3J XzyLhD3Ow8hQJxlAhqlB8n7JVKh8dJ27K2g2pBptCVOr38O8J9WP5WEEkrQrKJV85lMp aS2pqGckhLh+VVJ8TJOBjKY+J0Fmm101vLeaekBa8icbP+YS/z4lVjqfGeQrOgf9WLVk n6xg== MIME-Version: 1.0 X-Received: by 10.129.130.6 with SMTP id s6mr9805251ywf.155.1444989380589; Fri, 16 Oct 2015 02:56:20 -0700 (PDT) In-Reply-To: <151015172252.ZM30709@torch.brasslantern.com> References: <151015172252.ZM30709@torch.brasslantern.com> Date: Fri, 16 Oct 2015 17:56:20 +0800 Message-ID: Subject: Re: Mangement of fdtable[] From: Chi Hsuan Yen To: Bart Schaefer Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary=94eb2c07c35ebc0547052235ce9c --94eb2c07c35ebc0547052235ce9c Content-Type: text/plain; charset=UTF-8 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 wrote: > 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 > --94eb2c07c35ebc0547052235ce9c--