From: Paul Smith Date: Sun, 12 Jul 2015 17:25:16 +0000 (-0400) Subject: [SV 45049] Check for '$' being the last character in a string. X-Git-Tag: 4.1.90~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0205d3d08c810e15ef35475f5792dc049daf2f2c;p=thirdparty%2Fmake.git [SV 45049] Check for '$' being the last character in a string. * expand.c (variable_expand_string): Add a single '$' if '$' ends the string. * read.c (find_char_unquote, get_next_mword): Stop if '$' ends the string. * variable.c (parse_variable_definition): Ditto. --- diff --git a/expand.c b/expand.c index 1c87db10..866e8a75 100644 --- a/expand.c +++ b/expand.c @@ -235,8 +235,10 @@ variable_expand_string (char *line, const char *string, long length) switch (*p) { case '$': - /* $$ seen means output one $ to the variable output buffer. */ - o = variable_buffer_output (o, p, 1); + case '\0': + /* $$ or $ at the end of the string means output one $ to the + variable output buffer. */ + o = variable_buffer_output (o, p1, 1); break; case '(': @@ -381,9 +383,6 @@ variable_expand_string (char *line, const char *string, long length) } break; - case '\0': - break; - default: if (isblank ((unsigned char)p[-1])) break; diff --git a/read.c b/read.c index 2b5f08d1..d3747ce8 100644 --- a/read.c +++ b/read.c @@ -2262,6 +2262,10 @@ find_char_unquote (char *string, int map) { char openparen = p[1]; + /* Check if '$' is the last character in the string. */ + if (openparen == '\0') + break; + p += 2; /* Skip the contents of a non-quoted, multi-char variable ref. */ @@ -2735,6 +2739,8 @@ get_next_mword (char *buffer, char *delim, char **startp, unsigned int *length) c = *(p++); if (c == '$') break; + if (c == '\0') + goto done_word; /* This is a variable reference, so note that it's expandable. Then read it to the matching close paren. */ diff --git a/variable.c b/variable.c index 0b89d37c..40d691d0 100644 --- a/variable.c +++ b/variable.c @@ -1445,6 +1445,8 @@ parse_variable_definition (const char *p, struct variable *var) closeparen = ')'; else if (c == '{') closeparen = '}'; + else if (c == '\0') + return NULL; else /* '$$' or '$X'. Either way, nothing special to do here. */ continue;