37e7c073c6f0365ed8255c83168835503c5e1921 — Simon Ser 2 months ago dd5a12c
shell/task/word: refuse to apply string param ops on $#

Refuse to apply string parameter operations on $#, except the string length
operator.
1 files changed, 3 insertions(+), 1 deletions(-)

M shell/task/word.c
M shell/task/word.c => shell/task/word.c +3 -1
@@ 313,7 313,9 @@ int run_word(struct context *ctx, struct mrsh_word **word_ptr) {
 		case MRSH_PARAM_DPERCENT:
 		case MRSH_PARAM_HASH:
 		case MRSH_PARAM_DHASH:
-			if (strcmp(wp->name, "@") == 0 || strcmp(wp->name, "*") == 0) {
+			if (strcmp(wp->name, "@") == 0 || strcmp(wp->name, "*") == 0 ||
+					(wp->op != MRSH_PARAM_LEADING_HASH &&
+					strcmp(wp->name, "#") == 0)) {
 				fprintf(stderr, "%s: using this parameter operator on $%s "
 					"is undefined behaviour\n",
 					ctx->state->frame->argv[0], wp->name);