main/texobj: Check that texture id > 0 before looking it up in hash-table
authorEduardo Lima Mitev <elima@igalia.com>
Wed, 23 Nov 2016 13:44:05 +0000 (14:44 +0100)
committerEduardo Lima Mitev <elima@igalia.com>
Thu, 24 Nov 2016 07:23:45 +0000 (08:23 +0100)
_mesa_lookup_texture_err() is not currently checking that the
texture-id can be zero, but _mesa_HashLookup() doesn't expect the key
to be zero, and will fail an assertion.

Considering that _mesa_lookup_texture_err() is called from
_mesa_GetTextureImage and _mesa_GetTextureSubImage with user provided
arguments, we must validate the texture-id before looking it up in the
hash-table.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/main/texobj.c

index fbd498dd93547301a414195972e55390e660f76c..e5b70701c4432b009f2dcf3dfb297a7ed2f04594 100644 (file)
@@ -116,9 +116,10 @@ _mesa_lookup_texture(struct gl_context *ctx, GLuint id)
 struct gl_texture_object *
 _mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func)
 {
-   struct gl_texture_object *texObj;
+   struct gl_texture_object *texObj = NULL;
 
-   texObj = _mesa_lookup_texture(ctx, id); /* Returns NULL if not found. */
+   if (id > 0)
+      texObj = _mesa_lookup_texture(ctx, id); /* Returns NULL if not found. */
 
    if (!texObj)
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture)", func);