Mesa (mesa_7_7_branch): progs/xdemos: Check for string overflow.

Vinson Lee vlee at kemper.freedesktop.org
Thu Jan 7 02:20:04 UTC 2010


Module: Mesa
Branch: mesa_7_7_branch
Commit: 45ac10fe6a9c01aec9b7245f9a5621402842f466
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=45ac10fe6a9c01aec9b7245f9a5621402842f466

Author: Vinson Lee <vlee at vmware.com>
Date:   Wed Jan  6 18:18:49 2010 -0800

progs/xdemos: Check for string overflow.

---

 progs/xdemos/manywin.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/progs/xdemos/manywin.c b/progs/xdemos/manywin.c
index ee357f3..3b0810b 100644
--- a/progs/xdemos/manywin.c
+++ b/progs/xdemos/manywin.c
@@ -177,14 +177,40 @@ AddHead(const char *displayName, const char *name)
    /* save the info for this head */
    {
       struct head *h = &Heads[NumHeads];
+      const char * tmp;
+
+      if (strlen(name) + 1 > sizeof(h->DisplayName)) {
+         Error(displayName, "name string overflow");
+         return NULL;
+      }
       strcpy(h->DisplayName, name);
+
       h->Dpy = dpy;
       h->Win = win;
       h->Context = ctx;
       h->Angle = 0.0;
-      strcpy(h->Version, (char *) glGetString(GL_VERSION));
-      strcpy(h->Vendor, (char *) glGetString(GL_VENDOR));
-      strcpy(h->Renderer, (char *) glGetString(GL_RENDERER));
+
+      tmp = (char *) glGetString(GL_VERSION);
+      if (strlen(tmp) + 1 > sizeof(h->Version)) {
+         Error(displayName, "GL_VERSION string overflow");
+         return NULL;
+      }
+      strcpy(h->Version, tmp);
+
+      tmp = (char *) glGetString(GL_VENDOR);
+      if (strlen(tmp) + 1 > sizeof(h->Vendor)) {
+         Error(displayName, "GL_VENDOR string overflow");
+         return NULL;
+      }
+      strcpy(h->Vendor, tmp);
+
+      tmp = (char *) glGetString(GL_RENDERER);
+      if (strlen(tmp) + 1 > sizeof(h->Renderer)) {
+         Error(displayName, "GL_RENDERER string overflow");
+         return NULL;
+      }
+      strcpy(h->Renderer, tmp);
+
       NumHeads++;
       return &Heads[NumHeads-1];
    }




More information about the mesa-commit mailing list