2017-05-31 2:39 GMT+03:00 Ian Romanick <i...@freedesktop.org>:
> On 05/30/2017 03:45 PM, Vlad Golovkin wrote:
>> ---
>>  src/compiler/glsl/standalone.cpp | 17 ++++++++++-------
>>  1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/src/compiler/glsl/standalone.cpp 
>> b/src/compiler/glsl/standalone.cpp
>> index 52554bb92a..b9cee23642 100644
>> --- a/src/compiler/glsl/standalone.cpp
>> +++ b/src/compiler/glsl/standalone.cpp
>> @@ -459,19 +459,22 @@ standalone_compile_shader(const struct 
>> standalone_options *_options,
>>        if (len < 6)
>>           goto fail;
>>
>> -      const char *const ext = & files[i][len - 5];
>> +      const char *ext = & files[i][len - 5];
>>        /* TODO add support to read a .shader_test */
>> -      if (strncmp(".vert", ext, 5) == 0 || strncmp(".glsl", ext, 5) == 0)
>> +      if (*ext != '.')
>> +         goto fail;
>> +      ++ext;
>> +      if (memcmp("vert", ext, 4) == 0 || memcmp("glsl", ext, 4) == 0)
>
> This is not the same.  If ext points at a NUL character that is, say, at
> the end of page, you don't get to look at the next 3 bytes, and memcmp
> may well do that.  There is no guarantee that memcmp will not access
> beyond the first mismatched byte.

Maybe I am missing something but I think that check above ensures that
files[i] is at least 6 chars long, so there are always 4 non-NUL bytes
to compare.

>
>>        shader->Type = GL_VERTEX_SHADER;
>> -      else if (strncmp(".tesc", ext, 5) == 0)
>> +      else if (memcmp("tesc", ext, 4) == 0)
>>        shader->Type = GL_TESS_CONTROL_SHADER;
>> -      else if (strncmp(".tese", ext, 5) == 0)
>> +      else if (memcmp("tese", ext, 4) == 0)
>>        shader->Type = GL_TESS_EVALUATION_SHADER;
>> -      else if (strncmp(".geom", ext, 5) == 0)
>> +      else if (memcmp("geom", ext, 4) == 0)
>>        shader->Type = GL_GEOMETRY_SHADER;
>> -      else if (strncmp(".frag", ext, 5) == 0)
>> +      else if (memcmp("frag", ext, 4) == 0)
>>        shader->Type = GL_FRAGMENT_SHADER;
>> -      else if (strncmp(".comp", ext, 5) == 0)
>> +      else if (memcmp("comp", ext, 4) == 0)
>>           shader->Type = GL_COMPUTE_SHADER;
>>        else
>>           goto fail;
>>
>
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to