[PATCH] alias: Disallow non-CWORD characters

Herbert Xu <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
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 <[email protected]>

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;
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.