Commit 6bc264ae by Jamie Madill Committed by Commit Bot

Fix potential bad access in LinkProgram.

This could happen when linking a program with missing attachments and shaders that have no compiled sources. Also re-enables the EGL program cache control tests, which were disabled due to a wrong extension name check. Bug: chromium:827158 Change-Id: I181f878093c6e3a4acc51552ade8e7c084733a3d Reviewed-on: https://chromium-review.googlesource.com/989262Reviewed-by: 's avatarLuc Ferron <lucferron@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 94bbed1e
...@@ -1049,9 +1049,16 @@ Error Program::link(const gl::Context *context) ...@@ -1049,9 +1049,16 @@ Error Program::link(const gl::Context *context)
double startTime = platform->currentTime(platform); double startTime = platform->currentTime(platform);
unlink(); unlink();
mInfoLog.reset();
// Validate we have properly attached shaders before checking the cache.
if (!linkValidateShaders(context, mInfoLog))
{
return NoError();
}
ProgramHash programHash; ProgramHash programHash;
auto *cache = context->getMemoryProgramCache(); MemoryProgramCache *cache = context->getMemoryProgramCache();
if (cache) if (cache)
{ {
ANGLE_TRY_RESULT(cache->getProgram(context, this, &mState, &programHash), mLinked); ANGLE_TRY_RESULT(cache->getProgram(context, this, &mState, &programHash), mLinked);
...@@ -1068,12 +1075,9 @@ Error Program::link(const gl::Context *context) ...@@ -1068,12 +1075,9 @@ Error Program::link(const gl::Context *context)
// Cache load failed, fall through to normal linking. // Cache load failed, fall through to normal linking.
unlink(); unlink();
mInfoLog.reset();
if (!linkValidateShaders(context, mInfoLog)) // Re-link shaders after the unlink call.
{ ASSERT(linkValidateShaders(context, mInfoLog));
return NoError();
}
if (mState.mAttachedComputeShader) if (mState.mAttachedComputeShader)
{ {
...@@ -1284,6 +1288,7 @@ void Program::unlink() ...@@ -1284,6 +1288,7 @@ void Program::unlink()
mValidated = false; mValidated = false;
mLinked = false; mLinked = false;
mInfoLog.reset();
} }
bool Program::isLinked() const bool Program::isLinked() const
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
using namespace angle; using namespace angle;
constexpr EGLint kEnabledCacheSize = 0x10000; constexpr EGLint kEnabledCacheSize = 0x10000;
constexpr char kEGLExtName[] = "EGL_ANGLE_program_cache_control "; constexpr char kEGLExtName[] = "EGL_ANGLE_program_cache_control";
void TestCacheProgram(PlatformMethods *platform, void TestCacheProgram(PlatformMethods *platform,
const ProgramKeyType &key, const ProgramKeyType &key,
...@@ -239,4 +239,24 @@ TEST_P(EGLProgramCacheControlTest, SaveAndReload) ...@@ -239,4 +239,24 @@ TEST_P(EGLProgramCacheControlTest, SaveAndReload)
EXPECT_TRUE(mCachedBinary.empty()); EXPECT_TRUE(mCachedBinary.empty());
} }
// Tests that trying to link a program without correct shaders doesn't buggily call the cache.
TEST_P(EGLProgramCacheControlTest, LinkProgramWithBadShaders)
{
ANGLE_SKIP_TEST_IF(!extensionAvailable());
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
GLuint program = glCreateProgram();
glAttachShader(program, shader);
glLinkProgram(program);
GLint linkStatus = 0;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
EXPECT_GL_NO_ERROR();
glDeleteShader(shader);
glDeleteProgram(program);
}
ANGLE_INSTANTIATE_TEST(EGLProgramCacheControlTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL()); ANGLE_INSTANTIATE_TEST(EGLProgramCacheControlTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment