Path: csiph.com!tncsrv06.tnetconsulting.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Phi Debian Newsgroups: gnu.bash.bug Subject: Re: command_not_found_handle() flaw Date: Tue, 10 Mar 2020 20:57:26 +0100 Lines: 46 Approved: bug-bash@gnu.org Message-ID: References: <7900c11e-7c5c-1b2b-2ed5-7203bd73c2a9@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1583870264 27686 209.51.188.17 (10 Mar 2020 19:57:44 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Bug reports for the GNU Bourne Again SHell To: Chester Ramey Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lbMb347bKAsf2MmZzV/hGjijDAh7yk1ulKUYGsvrTeA=; b=rupquhdhxO3mazWeZTXfLJX9dg8oZSUjFfzWHJ9ztOusNroompd/N+Ci52awslt088 SpKD7dF4r84RCFa7JJYrLm8e0PQWjlLRK6LYc6lpbzaeHnm1ANXCKp611yF+RajoOTQ5 SQ08TSeeZs2o/9VO7jMM3umoOqWy2z8gdIKXlGmkc8/vVMnwwlNtVoNm+PVZ/0T7g6b1 tOGdwF46q//kzAwc5y/Acv8OvJFFH/Qy0gMhFqd6CYRMO1/aJmYRrHLL73euazF07fai EsiKvR3BWzGpeYviHE7AyyyoZ9NMUIsUVG4VvAV+ZafcYBC6WolJyOqoeo5FfP94cVvC 1oPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lbMb347bKAsf2MmZzV/hGjijDAh7yk1ulKUYGsvrTeA=; b=W+vHp0WgWD7qi4RF6H2qOe3Uz1XMYnLUYW09W17mBmHinrGAztaQaHcCcurwbLInJ4 YLIcS5/bQO/aCRiSEul3k/oC+yktuhskBLRkwL2fWhwxSQjqYsws+Ka/PcEEsZes4ACo IVHIoPrVPu4jZAO2jCzeEbqrGW1PPsI2THWmLSyyivL7iMNZKtbicKTSIqVx9i6g4la1 dkHahngbhpyxBqHK5mfB0BuD1Nppz9QfTPeFNJF09X9HwAi+TzTGqISLv04TzBXTpiND 3+ORBs65rSQAkTZvwDhVrVFYSBTKCmNiHcasttfqRTF0Lbj+YK605/XtC6Ewk5NKZXrB L0vQ== X-Gm-Message-State: ANhLgQ2DOic9CxKRX8mWwoIhfDEqzP9DeOC6CwkMP/iSDInDdeWXS6GC 8vA4llsGyjY0AhjB/8zEL6p91g5D8X4DTaU8aRc= X-Google-Smtp-Source: ADFU+vvTuGqwkOyR0oT5xW9qzYmOMbeGAr5CfIcgDu+q9UBaimSp1GJT7NfEYU4n5fGU8kBUISgwl5asD4hYvNAp3L0= X-Received: by 2002:a37:a94b:: with SMTP id s72mr9335026qke.48.1583870257386; Tue, 10 Mar 2020 12:57:37 -0700 (PDT) In-Reply-To: <7900c11e-7c5c-1b2b-2ed5-7203bd73c2a9@case.edu> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::72c 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: X-Mailman-Original-References: <7900c11e-7c5c-1b2b-2ed5-7203bd73c2a9@case.edu> Xref: csiph.com gnu.bash.bug:16011 Hi All, I think it is a bug, it is not working as intended at least in the man page, it says. If that function exists, it is invoked with the original command and the original command's arguments as its arguments, and the function's exit status becomes the exit status of the shell. If that function is not defined, the shell prints an error message and returns an exit status of 127. A function invocation, don't imply a sub shell. Secondly, if yuio insist on going on the subshell path, then $$ and $PPID ought to be setup appropriately, here ther are plain bogus. Third, the argument saying to late we forked already is dumb, it is too late because the sequence hookf = find_function (NOTFOUND_HOOK); execute_shell_function (hookf, wl); is misplaced after the fork, while it should be done before the fork. I provided a fix that no one tested, that don't jeoparise the existing code or behavior, and to respect what a function invocation is. I can survive a "don't fix" well I can fix for myself, but has it is you must at least fix 2 points, fix the doc, sayin the command_not_found_handle() is called in a subshell and fix $$ and $PPID that are bogus in the subshell. BTW fixing $$ and $PPID will take more effort that just placing the hook before the fork, but that's your decision indeed :) I think that either command_not_found_handle() is a gross hack to satisfy command-not-found distro package, and in this case it should simply not be documented in the docco, or else it should be done as specifed i.e a function incovation is not a subshell running a function, that frankly is a bit ridiculous. Cheers, Phi