diff mbox series

alias: Disallow non-CWORD characters

Message ID ZhkEHWODl9ZFKBhq@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series alias: Disallow non-CWORD characters | expand

Commit Message

Herbert Xu April 12, 2024, 9:51 a.m. UTC
On Wed, Jan 11, 2023 at 02:01:03AM +0000, Harald van Dijk wrote:
>
> Supporting alias names containing non-ASCII characters, while not required
> by POSIX, seems desirable, and almost all other shells (mksh being the
> exception) do appear to support this. I am not yet seeing a good way of
> solving this.

I looked at supporting this properly by either adding or removing
quotes but the complexity is just not worth it.  Let's just ban
these characters.

---8<---
Alias names containing control characters may match words from
the parser that shouldn't be matched.  Disallow such characters
from appearing in an alias name.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
diff mbox series

Patch

diff --git a/src/alias.c b/src/alias.c
index cee07e9..3cd3413 100644
--- a/src/alias.c
+++ b/src/alias.c
@@ -41,6 +41,7 @@ 
 #include "mystring.h"
 #include "alias.h"
 #include "options.h"	/* XXX for argptr (should remove?) */
+#include "syntax.h"
 
 #define ATABSIZE 39
 
@@ -55,6 +56,11 @@  void
 setalias(const char *name, const char *val)
 {
 	struct alias *ap, **app;
+	const char *p;
+
+	for (p = name; *p; p++)
+		if (BASESYNTAX[(signed char)*p] != CWORD)
+			sh_error("Invalid alias name: %s", name);
 
 	app = __lookupalias(name);
 	ap = *app;