summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGL/SoftwareGLContext.cpp
diff options
context:
space:
mode:
authorJesse Buhagiar <jooster669@gmail.com>2021-04-24 02:21:13 +1000
committerAndreas Kling <kling@serenityos.org>2021-05-08 10:13:22 +0200
commit55b3ecfbd3b5d3dc363c3e72aeb3d9183b575b22 (patch)
treea25c4a8046975af7594b3dabd3b1505212ff4824 /Userland/Libraries/LibGL/SoftwareGLContext.cpp
parent1959efe063b4d29300e88d411e46bef02afdca43 (diff)
downloadserenity-55b3ecfbd3b5d3dc363c3e72aeb3d9183b575b22.zip
LibGL: Check for matrix stack over/underflow
We now correctly set the gloabl error if we detect that a matrix stack overflow will occur in `glPushMatrix` or `glPopMatrix`
Diffstat (limited to 'Userland/Libraries/LibGL/SoftwareGLContext.cpp')
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 9ee041f490..c6b54c40ef 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -48,6 +48,9 @@ enum ClippingPlane {
FAR = 5
};
+// FIXME: We should set this up when we create the context!
+static constexpr size_t MATRIX_STACK_LIMIT = 1024;
+
// FIXME: Change this to accept a vertex!
// Determines whether or not a vertex is inside the frustum for a given plane
static bool vert_inside_plane(const FloatVector4& vec, ClippingPlane plane)
@@ -518,9 +521,17 @@ void SoftwareGLContext::gl_push_matrix()
switch (m_current_matrix_mode) {
case GL_PROJECTION:
+ if (m_projection_matrix_stack.size() >= MATRIX_STACK_LIMIT) {
+ m_error = GL_STACK_OVERFLOW;
+ return;
+ }
m_projection_matrix_stack.append(m_projection_matrix);
break;
case GL_MODELVIEW:
+ if (m_model_view_matrix_stack.size() >= MATRIX_STACK_LIMIT) {
+ m_error = GL_STACK_OVERFLOW;
+ return;
+ }
m_model_view_matrix_stack.append(m_model_view_matrix);
break;
default:
@@ -543,9 +554,17 @@ void SoftwareGLContext::gl_pop_matrix()
// FIXME: Make sure stack::top() doesn't cause any nasty issues if it's empty (that could result in a lockup/hang)
switch (m_current_matrix_mode) {
case GL_PROJECTION:
+ if (m_projection_matrix_stack.size() == 0) {
+ m_error = GL_STACK_UNDERFLOW;
+ return;
+ }
m_projection_matrix = m_projection_matrix_stack.take_last();
break;
case GL_MODELVIEW:
+ if (m_model_view_matrix_stack.size() == 0) {
+ m_error = GL_STACK_UNDERFLOW;
+ return;
+ }
m_model_view_matrix = m_model_view_matrix_stack.take_last();
break;
default: