[PATCH] alias: Disallow non-CWORD characters

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

 



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@xxxxxxxxxxx>

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 <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt




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

  Powered by Linux