b=569943; validate Enable/Disable args; r=vladimir
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 08 Jun 2010 14:45:23 -0400
changeset 43317 048ddcc077d887abe98079036c8eeffd6a8f5f4e
parent 43316 1aacd24d112fed4fca15216a6c932cf0f2749808
child 43318 213ff7652a1ddc9596a765be28ca04f797be2ffe
push id13651
push userbjacob@mozilla.com
push dateTue, 08 Jun 2010 18:46:34 +0000
treeherdermozilla-central@048ddcc077d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladimir
bugs569943
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
b=569943; validate Enable/Disable args; r=vladimir
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextGL.cpp
content/canvas/src/WebGLContextValidate.cpp
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -294,16 +294,17 @@ protected:
     PRBool mInvalidated;
 
     WebGLuint mActiveTexture;
     WebGLenum mSynthesizedGLError;
 
     PRBool SafeToCreateCanvas3DContext(nsHTMLCanvasElement *canvasElement);
     PRBool ValidateGL();
     PRBool ValidateBuffers(PRUint32 count);
+    static PRBool ValidateCapabilityEnum(WebGLenum cap);
 
     void Invalidate();
 
     void MakeContextCurrent() { gl->MakeCurrent(); }
 
     // helpers
     nsresult TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum internalformat,
                              WebGLsizei width, WebGLsizei height, WebGLint border,
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -755,19 +755,16 @@ GL_SAME_METHOD_1(DepthFunc, DepthFunc, W
 GL_SAME_METHOD_1(DepthMask, DepthMask, WebGLboolean)
 
 #ifdef USE_GLES2
 GL_SAME_METHOD_2(DepthRangef, DepthRange, float, float)
 #else
 GL_SAME_METHOD_2(DepthRange, DepthRange, float, float)
 #endif
 
-// XXX arg check!
-GL_SAME_METHOD_1(Disable, Disable, WebGLenum)
-
 NS_IMETHODIMP
 WebGLContext::DisableVertexAttribArray(WebGLuint index)
 {
     if (index > mAttribBuffers.Length())
         return ErrorInvalidValue("DisableVertexAttribArray: index out of range");
 
     MakeContextCurrent();
 
@@ -879,18 +876,35 @@ WebGLContext::DrawElements(WebGLenum mod
 
     gl->fDrawElements(mode, count, type, (GLvoid*) (byteOffset));
 
     Invalidate();
 
     return NS_OK;
 }
 
-// XXX definitely need to validate this
-GL_SAME_METHOD_1(Enable, Enable, PRUint32)
+NS_IMETHODIMP WebGLContext::Enable(WebGLenum cap)
+{
+    if (!ValidateCapabilityEnum(cap))
+        return ErrorInvalidEnum("Enable: invalid capability enum");
+
+    MakeContextCurrent();
+    gl->fEnable(cap);
+    return NS_OK;
+}
+
+NS_IMETHODIMP WebGLContext::Disable(WebGLenum cap)
+{
+    if (!ValidateCapabilityEnum(cap))
+        return ErrorInvalidEnum("Disable: invalid capability enum");
+
+    MakeContextCurrent();
+    gl->fDisable(cap);
+    return NS_OK;
+}
 
 NS_IMETHODIMP
 WebGLContext::EnableVertexAttribArray(WebGLuint index)
 {
     if (index > mAttribBuffers.Length())
         return ErrorInvalidValue("EnableVertexAttribArray: index out of range");
 
     MakeContextCurrent();
@@ -1934,24 +1948,28 @@ WebGLContext::IsTexture(nsIWebGLTexture 
 {
     PRBool isDeleted;
     *retval = CheckConversion<WebGLTexture>(tobj, 0, &isDeleted) && !isDeleted;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-WebGLContext::IsEnabled(WebGLenum k, WebGLboolean *retval)
+WebGLContext::IsEnabled(WebGLenum cap, WebGLboolean *retval)
 {
+    if(!ValidateCapabilityEnum(cap)) {
+        *retval = 0; // as per the OpenGL ES spec
+        return ErrorInvalidEnum("IsEnabled: invalid capability enum");
+    }
+
     MakeContextCurrent();
-    *retval = gl->fIsEnabled(k);
+    *retval = gl->fIsEnabled(cap);
     return NS_OK;
 }
 
-
 GL_SAME_METHOD_1(LineWidth, LineWidth, float)
 
 NS_IMETHODIMP
 WebGLContext::LinkProgram(nsIWebGLProgram *pobj)
 {
     GLuint progname;
     WebGLProgram *program;
     if (!GetConcreteObjectAndGLName(pobj, &program, &progname))
--- a/content/canvas/src/WebGLContextValidate.cpp
+++ b/content/canvas/src/WebGLContextValidate.cpp
@@ -98,8 +98,25 @@ WebGLContext::ValidateBuffers(PRUint32 c
           LogMessage("VBO too small for bound attrib index %d: need at least %d bytes, but have only %d", i, needed, vd.buf->ByteLength());
           return PR_FALSE;
       }
     }
 
     return PR_TRUE;
 }
 
+PRBool WebGLContext::ValidateCapabilityEnum(WebGLenum cap)
+{
+    switch (cap) {
+        case LOCAL_GL_BLEND:
+        case LOCAL_GL_CULL_FACE:
+        case LOCAL_GL_DEPTH_TEST:
+        case LOCAL_GL_DITHER:
+        case LOCAL_GL_POLYGON_OFFSET_FILL:
+        case LOCAL_GL_SAMPLE_ALPHA_TO_COVERAGE:
+        case LOCAL_GL_SAMPLE_COVERAGE:
+        case LOCAL_GL_SCISSOR_TEST:
+        case LOCAL_GL_STENCIL_TEST:
+            return PR_TRUE;
+        default:
+            return PR_FALSE;
+    }
+}