Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Sam Liddicott Newsgroups: gnu.bash.bug Subject: leaks fd for internal functions but not external command Date: Tue, 23 Jul 2019 15:33:07 +0100 Lines: 52 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1563892437 17259 209.51.188.17 (23 Jul 2019 14:33:57 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org, bash@packages.debian.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=liddicott-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=2jh8IG3G1I59VErZjACyV2R341was6bQFVpYpWKCrdk=; b=HBo2k84qA1HfR7pj7n4HaBFWAEoDZdFtuoABTwY2ru58JwZAlQqB96REBXTm3uVavP 7RsRrFc7EyApyBONg2//rh/UHmgiOjXI7LZhjGN3AO+JEnCli0Xmq07fvZVamf4mFfou jFfYgXwdK/lOEvTtTcvBqB3vVHNqAxhyRYJbKKFSTcM28lGVr3sr6xyijzC7jROcdHBH JETnF612fj/wMIxihfN4pGwpbO4H8+eSxdS0ckByCn8MRtGANMPL3QtV+hcHs1KjFC8E v7PIJjoZy2lC1YP03G8z2nAr68zBP0tMHzWN2wCe+1/eJoCwHKkTGVZgsgCznPLuzeu2 Ouxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=2jh8IG3G1I59VErZjACyV2R341was6bQFVpYpWKCrdk=; b=jqYdxczFQN6sjGlmnWQV1Aqim/21yRB3UuLPoS0fLBGDetfnRRIvcKxkSWhhPfCTh/ vOCVfAmF1EfRf3tTHWkaq4d3eXJ5lkcznRQfdh4i7L7oZSfXw9WS7hbz8F1O/ZNHb4by yVHwIuvsLD7xWPQJgztXXTbf6y++EeOX8wEj5PR75axTaycdjzpW3U3LiZdbeB0my9/P 6ngdrDq/pO9HWhKTXJGjAWn5XM+J1Z7JesGp8kdITpTylvMXFe/7AQDmXVajaBOsy661 Ob5lO9sYb56RsjDqy9nHsEPB+gKKXzOSKy85d769fzl/dQzIAsh+tLPv9IVxWg+EITHI v6Ag== X-Gm-Message-State: APjAAAVZEDqk7vR3FBFY2q41hqBtONsvCUgEh13BNI6/TDUlFrAXNk3D 6T5p7vqId8R4K+YOgl76KWEBcSgzeOiw3z2to4AG9z21Tls= X-Google-Smtp-Source: APXvYqz68/3voCZTDZegGZZzQZ3/vqWBt3FHBkS1u0ZNSqM+fwehWkOTgu7bzmCtaXvaKsE8EQph/pmOfLqWu3kHOtE= X-Received: by 2002:a2e:89ca:: with SMTP id c10mr24412594ljk.106.1563892423886; Tue, 23 Jul 2019 07:33:43 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::241 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com gnu.bash.bug:15205 Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../. -I.././include -I.././lib -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/build/bash-N2nMjo/bash-4.4.18=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wno-parentheses -Wno-format-security uname output: Linux sojo 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 4.4 Patch Level: 20 Release Status: release Description: Bash redirection sequence cases a file descriptor to be leaked if the main command is an internal function but not if it is an external command. Based on prior conversation, I suspect it is supposed to leak in the internal case (though that is annoying) but it is inconsistent that it does not for the external case. Repeat-By: bash -c is used to get a pure environment for test The perl-esque 'line noise' {_}>&2 2>&1 1>&${_} {_}<&- is to swap stdout with stderr while providing no other fd for any invoked processes to hang on to. (Yes _ is abused) test 1: leaks fd 10 for internal echo bash -c 'echo 1 {_}>&2 2>&1 1>&${_} {_}<&- ; echo done ; lsof -p $$ | grep CHR' test 2: does not leak fd for external /bin/echo bash -c '/bin/echo 1 {_}>&2 2>&1 1>&${_} {_}<&- ; echo done ; lsof -p $$ | grep CHR' test 3: does not leak if fd 10 is used explicitly bash -c 'echo 1 10>&2 2>&1 1>&10 10<&- ; echo done ; lsof -p $$ | grep CHR'