[klibc] [klibc:update-dash] dash: builtin: describe_command - fix incorrect path

klibc-bot for Harald van Dijk harald at gigawatt.nl
Sat Mar 28 14:48:53 PDT 2020


Commit-ID:  ae4ebb19df70ec73eb3ae9721762d40dd6bd3d1f
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=ae4ebb19df70ec73eb3ae9721762d40dd6bd3d1f
Author:     Harald van Dijk <harald at gigawatt.nl>
AuthorDate: Fri, 26 May 2017 09:59:44 +0200
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 21:42:54 +0000

[klibc] dash: builtin: describe_command - fix incorrect path

[ dash commit f19f3b398a2e947148a646096de94b77c73bb55d ]

Hi,

On 26/05/17 09:04, Youfu Zhang wrote:
> $ PATH=/extra/path:/usr/sbin:/usr/bin:/sbin:/bin \
>> sh -xc 'command -V ls; command -V ls; command -Vp ls; command -vp ls'
> + command -V ls
> ls is /bin/ls
> + command -V ls
> ls is a tracked alias for /bin/ls
> + command -Vp ls
> ls is a tracked alias for (null)
> + command -vp ls
> Segmentation fault (core dumped)
>
> describe_command should respect `path' argument. Looking up in the hash table
> may gives incorrect index in entry.u.index and finally causes incorrect output
> or SIGSEGV.

True, but only when a path is passed in. If the default path is used,
looking up in the hash table is correct, and printing tracked aliases is
intentional.

If it's desirable to drop that feature, then it should be dropped
completely, code shouldn't be left in that can no longer be used. But
it's possible to keep it working: how about this instead?

Signed-off-by: Harald van Dijk <harald at gigawatt.nl>
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/exec.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/usr/dash/exec.c b/usr/dash/exec.c
index ec0eadd8..e9e29b7e 100644
--- a/usr/dash/exec.c
+++ b/usr/dash/exec.c
@@ -743,8 +743,6 @@ describe_command(out, command, path, verbose)
 	struct tblentry *cmdp;
 	const struct alias *ap;
 
-	path = path ?: pathval();
-
 	if (verbose) {
 		outstr(command, out);
 	}
@@ -767,8 +765,17 @@ describe_command(out, command, path, verbose)
 		goto out;
 	}
 
-	/* Then check if it is a tracked alias */
-	if ((cmdp = cmdlookup(command, 0)) != NULL) {
+	/* Then if the standard search path is used, check if it is
+	 * a tracked alias.
+	 */
+	if (path == NULL) {
+		path = pathval();
+		cmdp = cmdlookup(command, 0);
+	} else {
+		cmdp = NULL;
+	}
+
+	if (cmdp != NULL) {
 		entry.cmdtype = cmdp->cmdtype;
 		entry.u = cmdp->param;
 	} else {


More information about the klibc mailing list