Mesa (main): mesa: Ensure ARB programs end in a newline

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 2 16:57:34 UTC 2022


Module: Mesa
Branch: main
Commit: 53a94fbdd57acbbe2bc745901cbfeca968e25273
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=53a94fbdd57acbbe2bc745901cbfeca968e25273

Author: Jesse Natalie <jenatali at microsoft.com>
Date:   Thu Apr 28 15:48:45 2022 -0700

mesa: Ensure ARB programs end in a newline

If the last line of an ARB program has a comment, the program will
fail to parse, because the lexer only considers a comment valid if
it ends in a newline, not EOF. The parser then fails on the '#'.

Reviewed-by: Joshua Ashton <joshua at froggi.es>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16230>

---

 src/mesa/program/program_parse.y | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y
index 349c4f05319..664503f8dfb 100644
--- a/src/mesa/program/program_parse.y
+++ b/src/mesa/program/program_parse.y
@@ -2541,9 +2541,9 @@ _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *st
    state->prog->Target = target;
    state->prog->Parameters = _mesa_new_parameter_list();
 
-   /* Make a copy of the program string and force it to be NUL-terminated.
+   /* Make a copy of the program string and force it to be newline and NUL-terminated.
     */
-   strz = (GLubyte *) ralloc_size(state->mem_ctx, len + 1);
+   strz = (GLubyte *) ralloc_size(state->mem_ctx, len + 2);
    if (strz == NULL) {
       if (state->prog->Parameters) {
          _mesa_free_parameter_list(state->prog->Parameters);
@@ -2553,7 +2553,8 @@ _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *st
       return GL_FALSE;
    }
    memcpy (strz, str, len);
-   strz[len] = '\0';
+   strz[len]     = '\n';
+   strz[len + 1] = '\0';
 
    state->prog->String = strz;
 
@@ -2578,10 +2579,12 @@ _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *st
 
    _mesa_set_program_error(ctx, -1, NULL);
 
-   _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len);
+   _mesa_program_lexer_ctor(& state->scanner, state, (const char *) strz, len + 1);
    yyparse(state);
    _mesa_program_lexer_dtor(state->scanner);
 
+   /* Remove the newline we added so reflection returns the original string */
+   strz[len] = '\0';
 
    if (ctx->Program.ErrorPos != -1) {
       goto error;



More information about the mesa-commit mailing list