NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/55526: sh: "command foo" removes function "foo"

The following reply was made to PR bin/55526; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
Subject: Re: bin/55526: sh: "command foo" removes function "foo"
Date: Fri, 31 Jul 2020 21:43:26 +0700

 This looks to be a "day 1" bug in sh, it was fixed where
 command is applied to a builtin by dsl@ back in 2003, but
 this case, for an external command wasn't noticed, and
 has been there apparently forever (it is certainly in the
 NetBSD 6 sh, I still have that one around to test).
 I wondered how I never encountered this problem, as I
 very often redefine "cd" in ways which eventually get
 to execute "command cd" - but then I saw that the two
 cases run through different paths in the code, and this
 one was long fixed.
 I have a fix I will commit after my test build and ATF
 run completes, but the effect of this, is that while it
 will be correct, it won't be efficient.   The hash table
 which in sh s used to hold functions, builtins, just
 about everything, can only have one entry for a name, it
 is either a function (or builtin) or it is the results
 of a PATH search from a previous execution of the command.
 They cannot both be present - the bug is in adding the
 path found (/bin/ls in the example) to the has table, in
 the "ls" slot (whereupon the function gets lost), and the
 short term fix will be just not to do that (which means
 that when one runs "command ls" and there is a function "ls"
 the results of the PATH search to find /bin/ls will never
 be cached (if there is no function, it still will be, it
 is that which will inhibit the addition, not the use of
 I'll look and see if there's a reasonable way to handle both
 later (to have both the function and the hashed path).
 ps: note that this combined "do everything" hash table is one
 of the features of ash derived shells which make them relatively
 fast - there is just one lookup of a command, no "is this a function,
 no, then is it a builtin, no, then is it in the hash table, no, then
 do a path search" just "is it in the hash table, if no, then search
 path and add it" with a "don't find functions" flag for use with the
 "command" builtin.

Home | Main Index | Thread Index | Old Index