diff mbox series

exec: hashcmd: don't early-exit when first -r is found

Message ID 20221214025113.c6lxog5v3wp4vzbt@tarta.nabijaczleweli.xyz (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series exec: hashcmd: don't early-exit when first -r is found | expand

Commit Message

Ahelenia Ziemiańska Dec. 14, 2022, 2:51 a.m. UTC
This fixes incorrectly-accepted "hash -rv" being equivalent to hash -r
(well, hash -r[literally anything] being equivalent to hash -r)

Also remove -v from the manual, it doesn't appear to have ever existed

Fixes: https://bugs.debian.org/819829
---
 src/dash.1 | 6 ++----
 src/exec.c | 8 +++++++-
 2 files changed, 9 insertions(+), 5 deletions(-)

Comments

Herbert Xu Jan. 5, 2023, 9:44 a.m. UTC | #1
наб <nabijaczleweli@nabijaczleweli.xyz> wrote:
> [-- text/plain, encoding quoted-printable, charset: us-ascii, 68 lines --]
> 
> This fixes incorrectly-accepted "hash -rv" being equivalent to hash -r
> (well, hash -r[literally anything] being equivalent to hash -r)
> 
> Also remove -v from the manual, it doesn't appear to have ever existed
> 
> Fixes: https://bugs.debian.org/819829
> ---
> src/dash.1 | 6 ++----
> src/exec.c | 8 +++++++-
> 2 files changed, 9 insertions(+), 5 deletions(-)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/src/dash.1 b/src/dash.1
index ff02237..3e09090 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -1441,7 +1441,8 @@  cmd \-a \-c arg file file
 cmd \-carg -a file file
 cmd \-a \-carg \-\- file file
 .Ed
-.It hash Fl rv Ar command ...
+.It hash Op Ar command ...
+.It hash Fl r
 The shell maintains a hash table which remembers the
 locations of commands.
 With no arguments whatsoever,
@@ -1457,9 +1458,6 @@  With arguments, the
 .Ic hash
 command removes the specified commands from the hash table (unless
 they are functions) and then locates them.
-With the
-.Fl v
-option, hash prints the locations of the commands as it finds them.
 The
 .Fl r
 option causes the hash command to delete all the entries in the hash table
diff --git a/src/exec.c b/src/exec.c
index 87354d4..d7a1f53 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -36,6 +36,7 @@ 
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #ifdef HAVE_PATHS_H
 #include <paths.h>
@@ -271,11 +272,16 @@  hashcmd(int argc, char **argv)
 	int c;
 	struct cmdentry entry;
 	char *name;
+	bool clear;
 
-	while ((c = nextopt("r")) != '\0') {
+	clear = false;
+	while ((c = nextopt("r")) != '\0')
+		clear = true;
+	if(clear) {
 		clearcmdentry();
 		return 0;
 	}
+
 	if (*argptr == NULL) {
 		for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
 			for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {