Title: [164580] trunk/Source/ThirdParty/ANGLE
Revision
164580
Author
[email protected]
Date
2014-02-24 03:14:29 -0800 (Mon, 24 Feb 2014)

Log Message

ANGLE: Stop using unsafe strcpy method
<http://webkit.org/b/129237>
<rdar://problem/11077580>

Reviewed by Dean Jackson.

* include/GLSLANG/ShaderLang.h:
- Drive-by fix for header documentation.

* src/compiler/translator/ShaderLang.cpp:
(ShGetInfoLog):
(ShGetObjectCode):
* src/libGLESv2/Program.cpp:
(gl::InfoLog::append):
- Switch to use strncpy(), and explicitly set NULL terminator at
  the end of the buffer.

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/ANGLE/ChangeLog (164579 => 164580)


--- trunk/Source/ThirdParty/ANGLE/ChangeLog	2014-02-24 10:02:10 UTC (rev 164579)
+++ trunk/Source/ThirdParty/ANGLE/ChangeLog	2014-02-24 11:14:29 UTC (rev 164580)
@@ -1,3 +1,22 @@
+2014-02-23  David Kilzer  <[email protected]>
+
+        ANGLE: Stop using unsafe strcpy method
+        <http://webkit.org/b/129237>
+        <rdar://problem/11077580>
+
+        Reviewed by Dean Jackson.
+
+        * include/GLSLANG/ShaderLang.h:
+        - Drive-by fix for header documentation.
+
+        * src/compiler/translator/ShaderLang.cpp:
+        (ShGetInfoLog):
+        (ShGetObjectCode):
+        * src/libGLESv2/Program.cpp:
+        (gl::InfoLog::append):
+        - Switch to use strncpy(), and explicitly set NULL terminator at
+          the end of the buffer.
+
 2014-02-23  Brent Fulgham  <[email protected]>
 
         [WinCairo] Unreviewed build fix after r164565.

Modified: trunk/Source/ThirdParty/ANGLE/include/GLSLANG/ShaderLang.h (164579 => 164580)


--- trunk/Source/ThirdParty/ANGLE/include/GLSLANG/ShaderLang.h	2014-02-24 10:02:10 UTC (rev 164579)
+++ trunk/Source/ThirdParty/ANGLE/include/GLSLANG/ShaderLang.h	2014-02-24 11:14:29 UTC (rev 164580)
@@ -383,8 +383,8 @@
 // Returns null-terminated object code for a compiled shader.
 // Parameters:
 // handle: Specifies the compiler
-// infoLog: Specifies an array of characters that is used to return
-//          the object code. It is assumed that infoLog has enough memory to
+// objCode: Specifies an array of characters that is used to return
+//          the object code. It is assumed that objCode has enough memory to
 //          accomodate the object code. The size of the buffer required to
 //          store the returned object code can be obtained by calling
 //          ShGetInfo with SH_OBJECT_CODE_LENGTH.

Modified: trunk/Source/ThirdParty/ANGLE/src/compiler/translator/ShaderLang.cpp (164579 => 164580)


--- trunk/Source/ThirdParty/ANGLE/src/compiler/translator/ShaderLang.cpp	2014-02-24 10:02:10 UTC (rev 164579)
+++ trunk/Source/ThirdParty/ANGLE/src/compiler/translator/ShaderLang.cpp	2014-02-24 11:14:29 UTC (rev 164580)
@@ -225,8 +225,12 @@
     TCompiler* compiler = base->getAsCompiler();
     if (!compiler) return;
 
+    size_t infoLogLength = 0;
+    ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLength);
+
     TInfoSink& infoSink = compiler->getInfoSink();
-    strcpy(infoLog, infoSink.info.c_str());
+    strncpy(infoLog, infoSink.info.c_str(), infoLogLength);
+    infoLog[infoLogLength - 1] = '\0';
 }
 
 //
@@ -241,8 +245,12 @@
     TCompiler* compiler = base->getAsCompiler();
     if (!compiler) return;
 
+    size_t objCodeLength = 0;
+    ShGetInfo(handle, SH_OBJECT_CODE_LENGTH, &objCodeLength);
+
     TInfoSink& infoSink = compiler->getInfoSink();
-    strcpy(objCode, infoSink.obj.c_str());
+    strncpy(objCode, infoSink.obj.c_str(), objCodeLength);
+    objCode[objCodeLength - 1] = '\0';
 }
 
 void ShGetVariableInfo(const ShHandle handle,

Modified: trunk/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp (164579 => 164580)


--- trunk/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp	2014-02-24 10:02:10 UTC (rev 164579)
+++ trunk/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp	2014-02-24 11:14:29 UTC (rev 164580)
@@ -106,17 +106,21 @@
 
     if (!mInfoLog)
     {
-        mInfoLog = new char[infoLength + 2];
-        strcpy(mInfoLog, info);
-        strcpy(mInfoLog + infoLength, "\n");
+        const size_t newInfoLogLength = infoLength + 2;
+        mInfoLog = new char[newInfoLogLength];
+        strncpy(mInfoLog, info, newInfoLogLength);
+        strncpy(mInfoLog + infoLength, "\n", newInfoLogLength - infoLength);
+        mInfoLog[newInfoLogLength - 1] = '\0';
     }
     else
     {
         size_t logLength = strlen(mInfoLog);
-        char *newLog = new char[logLength + infoLength + 2];
-        strcpy(newLog, mInfoLog);
-        strcpy(newLog + logLength, info);
-        strcpy(newLog + logLength + infoLength, "\n");
+        const size_t newInfoLogLength = logLength + infoLength + 2;
+        char *newLog = new char[newInfoLogLength];
+        strncpy(newLog, mInfoLog, newInfoLogLength);
+        strncpy(newLog + logLength, info, newInfoLogLength - logLength);
+        strncpy(newLog + logLength + infoLength, "\n", newInfoLogLength - logLength - infoLength);
+        newLog[newInfoLogLength - 1] = '\0';
 
         delete[] mInfoLog;
         mInfoLog = newLog;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to