Blame SOURCES/0001-glx-check-return-from-__glXGetAnswerBuffer.patch

0fd959
From 61a292adf45405641de1c522a04c148e0a152acd Mon Sep 17 00:00:00 2001
0fd959
From: Keith Packard <keithp@keithp.com>
0fd959
Date: Thu, 9 Oct 2014 15:17:17 +0200
0fd959
Subject: [PATCH] glx: check return from __glXGetAnswerBuffer
0fd959
0fd959
This function can return NULL; make sure every caller tests for that.
0fd959
0fd959
Reviewed-by: Adam Jackson <ajax@redhat.com>
0fd959
Signed-off-by: Keith Packard <keithp@keithp.com>
0fd959
---
0fd959
 glx/indirect_dispatch.c      | 25 +++++++++++++++++++++++++
0fd959
 glx/indirect_dispatch_swap.c | 26 ++++++++++++++++++++++++++
0fd959
 2 files changed, 51 insertions(+)
0fd959
0fd959
diff --git a/glx/indirect_dispatch.c b/glx/indirect_dispatch.c
0fd959
index 329b2e6..f6cabef 100644
0fd959
--- a/glx/indirect_dispatch.c
0fd959
+++ b/glx/indirect_dispatch.c
0fd959
@@ -2464,6 +2464,9 @@ __glXDisp_AreTexturesResident(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLboolean answerBuffer[200];
0fd959
         GLboolean *residences =
0fd959
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
0fd959
+
0fd959
+        if (residences == NULL)
0fd959
+            return BadAlloc;
0fd959
         retval =
0fd959
             glAreTexturesResident(n, (const GLuint *) (pc + 4), residences);
0fd959
         __glXSendReply(cl->client, residences, n, 1, GL_TRUE, retval);
0fd959
@@ -2488,6 +2491,9 @@ __glXDisp_AreTexturesResidentEXT(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLboolean answerBuffer[200];
0fd959
         GLboolean *residences =
0fd959
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
0fd959
+
0fd959
+        if (residences == NULL)
0fd959
+            return BadAlloc;
0fd959
         retval =
0fd959
             glAreTexturesResident(n, (const GLuint *) (pc + 4), residences);
0fd959
         __glXSendReply(cl->client, residences, n, 1, GL_TRUE, retval);
0fd959
@@ -2593,6 +2599,9 @@ __glXDisp_GenTextures(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *textures =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (textures == NULL)
0fd959
+            return BadAlloc;
0fd959
         glGenTextures(n, textures);
0fd959
         __glXSendReply(cl->client, textures, n, 4, GL_TRUE, 0);
0fd959
         error = Success;
0fd959
@@ -2616,6 +2625,9 @@ __glXDisp_GenTexturesEXT(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *textures =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (textures == NULL)
0fd959
+            return BadAlloc;
0fd959
         glGenTextures(n, textures);
0fd959
         __glXSendReply(cl->client, textures, n, 4, GL_TRUE, 0);
0fd959
         error = Success;
0fd959
@@ -3883,6 +3895,9 @@ __glXDisp_GenQueries(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *ids =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (ids == NULL)
0fd959
+            return BadAlloc;
0fd959
         GenQueries(n, ids);
0fd959
         __glXSendReply(cl->client, ids, n, 4, GL_TRUE, 0);
0fd959
         error = Success;
0fd959
@@ -4253,6 +4268,9 @@ __glXDisp_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *programs =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (programs == NULL)
0fd959
+            return BadAlloc;
0fd959
         GenProgramsARB(n, programs);
0fd959
         __glXSendReply(cl->client, programs, n, 4, GL_TRUE, 0);
0fd959
         error = Success;
0fd959
@@ -4630,6 +4648,10 @@ __glXDisp_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *framebuffers =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (framebuffers == NULL)
0fd959
+            return BadAlloc;
0fd959
+
0fd959
         GenFramebuffers(n, framebuffers);
0fd959
         __glXSendReply(cl->client, framebuffers, n, 4, GL_TRUE, 0);
0fd959
         error = Success;
0fd959
@@ -4655,6 +4677,9 @@ __glXDisp_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *renderbuffers =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (renderbuffers == NULL)
0fd959
+            return BadAlloc;
0fd959
         GenRenderbuffers(n, renderbuffers);
0fd959
         __glXSendReply(cl->client, renderbuffers, n, 4, GL_TRUE, 0);
0fd959
         error = Success;
0fd959
diff --git a/glx/indirect_dispatch_swap.c b/glx/indirect_dispatch_swap.c
0fd959
index 647d0c9..c0bb64d 100644
0fd959
--- a/glx/indirect_dispatch_swap.c
0fd959
+++ b/glx/indirect_dispatch_swap.c
0fd959
@@ -2731,6 +2731,9 @@ __glXDispSwap_AreTexturesResident(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLboolean answerBuffer[200];
0fd959
         GLboolean *residences =
0fd959
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
0fd959
+
0fd959
+        if (residences == NULL)
0fd959
+            return BadAlloc;
0fd959
         retval =
0fd959
             glAreTexturesResident(n,
0fd959
                                   (const GLuint *)
0fd959
@@ -2759,6 +2762,9 @@ __glXDispSwap_AreTexturesResidentEXT(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLboolean answerBuffer[200];
0fd959
         GLboolean *residences =
0fd959
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
0fd959
+
0fd959
+        if (residences == NULL)
0fd959
+            return BadAlloc;
0fd959
         retval =
0fd959
             glAreTexturesResident(n,
0fd959
                                   (const GLuint *)
0fd959
@@ -2878,6 +2884,9 @@ __glXDispSwap_GenTextures(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *textures =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (textures == NULL)
0fd959
+            return BadAlloc;
0fd959
         glGenTextures(n, textures);
0fd959
         (void) bswap_32_array((uint32_t *) textures, n);
0fd959
         __glXSendReplySwap(cl->client, textures, n, 4, GL_TRUE, 0);
0fd959
@@ -2903,6 +2912,9 @@ __glXDispSwap_GenTexturesEXT(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *textures =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (textures == NULL)
0fd959
+            return BadAlloc;
0fd959
         glGenTextures(n, textures);
0fd959
         (void) bswap_32_array((uint32_t *) textures, n);
0fd959
         __glXSendReplySwap(cl->client, textures, n, 4, GL_TRUE, 0);
0fd959
@@ -4290,6 +4302,9 @@ __glXDispSwap_GenQueries(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *ids =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+        if (ids == NULL)
0fd959
+            return BadAlloc;
0fd959
+
0fd959
         GenQueries(n, ids);
0fd959
         (void) bswap_32_array((uint32_t *) ids, n);
0fd959
         __glXSendReplySwap(cl->client, ids, n, 4, GL_TRUE, 0);
0fd959
@@ -4697,6 +4712,9 @@ __glXDispSwap_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *programs =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+        if (programs == NULL)
0fd959
+            return BadAlloc;
0fd959
+
0fd959
         GenProgramsARB(n, programs);
0fd959
         (void) bswap_32_array((uint32_t *) programs, n);
0fd959
         __glXSendReplySwap(cl->client, programs, n, 4, GL_TRUE, 0);
0fd959
@@ -5122,6 +5140,10 @@ __glXDispSwap_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *framebuffers =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (framebuffers == NULL)
0fd959
+            return BadAlloc;
0fd959
+
0fd959
         GenFramebuffers(n, framebuffers);
0fd959
         (void) bswap_32_array((uint32_t *) framebuffers, n);
0fd959
         __glXSendReplySwap(cl->client, framebuffers, n, 4, GL_TRUE, 0);
0fd959
@@ -5149,6 +5171,10 @@ __glXDispSwap_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
0fd959
         GLuint *renderbuffers =
0fd959
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
0fd959
                                  4);
0fd959
+
0fd959
+        if (renderbuffers == NULL)
0fd959
+            return BadAlloc;
0fd959
+
0fd959
         GenRenderbuffers(n, renderbuffers);
0fd959
         (void) bswap_32_array((uint32_t *) renderbuffers, n);
0fd959
         __glXSendReplySwap(cl->client, renderbuffers, n, 4, GL_TRUE, 0);
0fd959
-- 
0fd959
1.9.3
0fd959