diff options
author | Eric Engestrom <[email protected]> | 2018-08-16 15:31:55 +0100 |
---|---|---|
committer | Eric Engestrom <[email protected]> | 2018-08-16 17:38:22 +0100 |
commit | aa78b29ebad710d743747bb9b9755b6eea9ed4d2 (patch) | |
tree | 4029c134224172095ff8a6fa988737c5d513b26a | |
parent | eb6b41749bb8d9f0788a41937c81435f2fc0f94c (diff) |
egl: check for buffer overflow *before* corrupting our memory
Signed-off-by: Eric Engestrom <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
-rw-r--r-- | src/egl/main/eglapi.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 19fae12f5b7..5e5048c4d69 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -538,19 +538,30 @@ _eglCreateExtensionsString(_EGLDisplay *dpy) static void _eglCreateAPIsString(_EGLDisplay *dpy) { +#define addstr(str) \ + { \ + const size_t old_len = strlen(dpy->ClientAPIsString); \ + const size_t add_len = sizeof(str); \ + const size_t max_len = sizeof(dpy->ClientAPIsString) - 1; \ + if (old_len + add_len <= max_len) \ + strcat(dpy->ClientAPIsString, str " "); \ + else \ + assert(!"dpy->ClientAPIsString is not large enough"); \ + } + if (dpy->ClientAPIs & EGL_OPENGL_BIT) - strcat(dpy->ClientAPIsString, "OpenGL "); + addstr("OpenGL"); if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT || dpy->ClientAPIs & EGL_OPENGL_ES2_BIT || dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR) { - strcat(dpy->ClientAPIsString, "OpenGL_ES "); + addstr("OpenGL_ES"); } if (dpy->ClientAPIs & EGL_OPENVG_BIT) - strcat(dpy->ClientAPIsString, "OpenVG "); + addstr("OpenVG"); - assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString)); +#undef addstr } static void |