4951519272498588cb869a0371f75fad102c877f — Simon Ser 5 months ago aff5a58
parser: fail on invalid parameter

POSIX says '$' followed by an invalid character is unspecified behaviour. Make
the parser fail instead of handling it as a string.

This diverges from the dash implementation.

Fixes: aff5a58f0f99 ("parser: handle `$` followed by invalid char more gracefully")
1 files changed, 2 insertions(+), 9 deletions(-)

M parser/word.c
M parser/word.c => parser/word.c +2 -9
@@ 434,15 434,8 @@ struct mrsh_word *expect_dollar(struct mrsh_parser *state) {
 			} else {
 				// 2.6. If an unquoted '$' is followed by a character that is
 				// not one of the following […] the result is unspecified.
-				char str[] = {'$', c, '\0'};
-				struct mrsh_word_string *ws =
-					mrsh_word_string_create(strdup(str), false);
-				if (ws == NULL) {
-					return NULL;
-				}
-				ws->range.begin = dollar_pos;
-				ws->range.end = state->pos;
-				return &ws->word;
+				parser_set_error(state, "invalid parameter name");
+				return NULL;
 			}
 		}