Bug 1484985 - Avoid writing past the logical length of a string in graphics code. r=jgilbert
authorHenri Sivonen <hsivonen@hsivonen.fi>
Fri, 31 Aug 2018 20:12:34 +0000
changeset 434400 54a320057b31208111ac08818b69c694ff26cb46
parent 434382 dcae3a9fe7b749da82836763c97968052d8f12e3
child 434401 bf6f5ec86920a3f58d16ca6ea2c406b09197e976
push id34554
push usernbeleuzu@mozilla.com
push dateSat, 01 Sep 2018 21:55:14 +0000
treeherdermozilla-central@d718fc7c16e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1484985
milestone63.0a1
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
Bug 1484985 - Avoid writing past the logical length of a string in graphics code. r=jgilbert MozReview-Commit-ID: 7YtpBiaA7Gp Differential Revision: https://phabricator.services.mozilla.com/D3885
gfx/layers/opengl/GLBlitTextureImageHelper.cpp
gfx/layers/opengl/OGLShaderProgram.cpp
--- a/gfx/layers/opengl/GLBlitTextureImageHelper.cpp
+++ b/gfx/layers/opengl/GLBlitTextureImageHelper.cpp
@@ -235,19 +235,18 @@ GLBlitTextureImageHelper::UseBlitProgram
 
         gl->fCompileShader(shaders[i]);
         gl->fGetShaderiv(shaders[i], LOCAL_GL_COMPILE_STATUS, &success);
         NS_ASSERTION(success, "Shader compilation failed!");
 
         if (!success) {
             nsAutoCString log;
             gl->fGetShaderiv(shaders[i], LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
-            log.SetCapacity(len);
+            log.SetLength(len);
             gl->fGetShaderInfoLog(shaders[i], len, (GLint*) &len, (char*) log.BeginWriting());
-            log.SetLength(len);
 
             printf_stderr("Shader %d compilation failed:\n%s\n", i, log.get());
             return;
         }
 
         gl->fAttachShader(mBlitProgram, shaders[i]);
         gl->fDeleteShader(shaders[i]);
     }
@@ -259,19 +258,18 @@ GLBlitTextureImageHelper::UseBlitProgram
 
     GLint success, len = 0;
     gl->fGetProgramiv(mBlitProgram, LOCAL_GL_LINK_STATUS, &success);
     NS_ASSERTION(success, "Shader linking failed!");
 
     if (!success) {
         nsAutoCString log;
         gl->fGetProgramiv(mBlitProgram, LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
-        log.SetCapacity(len);
+        log.SetLength(len);
         gl->fGetProgramInfoLog(mBlitProgram, len, (GLint*) &len, (char*) log.BeginWriting());
-        log.SetLength(len);
 
         printf_stderr("Program linking failed:\n%s\n", log.get());
         return;
     }
 
     gl->fUseProgram(mBlitProgram);
     gl->fUniform1i(gl->fGetUniformLocation(mBlitProgram, "uSrcTexture"), 0);
 }
--- a/gfx/layers/opengl/OGLShaderProgram.cpp
+++ b/gfx/layers/opengl/OGLShaderProgram.cpp
@@ -941,19 +941,18 @@ ShaderProgramOGL::CreateProgram(const ch
    */
   if (!success
 #ifdef DEBUG
       || (len > 10 && gfxEnv::DebugShaders())
 #endif
       )
   {
     nsAutoCString log;
-    log.SetCapacity(len);
+    log.SetLength(len);
     mGL->fGetProgramInfoLog(result, len, (GLint*) &len, (char*) log.BeginWriting());
-    log.SetLength(len);
 
     if (!success) {
       printf_stderr("=== PROGRAM LINKING FAILED ===\n");
     } else {
       printf_stderr("=== PROGRAM LINKING WARNINGS ===\n");
     }
     printf_stderr("=== Log:\n%s\n", log.get());
     printf_stderr("============\n");