Re: "command -p" does not correctly limit search to a safe PATH

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

 



On Sun, Jul 14, 2013 at 07:54:58PM +0000, Harald van Dijk wrote:
>
> commit 475e328589fd2e843c138d49fb96699a2a66151d
> Author: Harald van Dijk <harald@xxxxxxxxxxx>
> Date:   Sun Jul 14 21:23:01 2013 +0200
> 
>     command: allow combining -p with -v

Patch applied.  Thanks a lot!

I've also added a little optimisation patch on top to minimise
the size impact.

commit d813a572d94455f1d0d43ccad49edfacd13ee2e3
Author: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Date:   Fri Sep 26 16:42:18 2014 +0800

    [BUILTIN] Small optimisation of command -pv change
    
    This patch moves the pathval call into the describe_command
    function and also eliminates an unnecessary branch when DEBUG
    is off.
    
    Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

diff --git a/ChangeLog b/ChangeLog
index 2fbc628..a8d5fa2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-09-26  Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
+
+	* Small optimisation to command -pv change.
+
 2014-09-26  Harald van Dijk <harald@xxxxxxxxxxx>
 
 	* command: allow combining -p with -v.
diff --git a/src/exec.c b/src/exec.c
index e56e3f6..ec0eadd 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -727,7 +727,7 @@ typecmd(int argc, char **argv)
 	int err = 0;
 
 	for (i = 1; i < argc; i++) {
-		err |= describe_command(out1, argv[i], pathval(), 1);
+		err |= describe_command(out1, argv[i], NULL, 1);
 	}
 	return err;
 }
@@ -743,6 +743,8 @@ describe_command(out, command, path, verbose)
 	struct tblentry *cmdp;
 	const struct alias *ap;
 
+	path = path ?: pathval();
+
 	if (verbose) {
 		outstr(command, out);
 	}
@@ -840,19 +842,19 @@ commandcmd(argc, argv)
 		VERIFY_BRIEF = 1,
 		VERIFY_VERBOSE = 2,
 	} verify = 0;
-	const char *path = pathval();
+	const char *path = NULL;
 
 	while ((c = nextopt("pvV")) != '\0')
 		if (c == 'V')
 			verify |= VERIFY_VERBOSE;
 		else if (c == 'v')
 			verify |= VERIFY_BRIEF;
-		else if (c == 'p')
-			path = defpath;
 #ifdef DEBUG
-		else
+		else if (c != 'p')
 			abort();
 #endif
+		else
+			path = defpath;
 
 	cmd = *argptr;
 	if (verify && cmd)

Cheers,
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux