From 4c7e6ca78b922d80ecf007a31e5d85ed67d40ce5 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Wed, 17 Jan 2018 19:24:31 -0800 Subject: [PATCH] Don't try to open non-existant file Merge from Widevine repo of http://go/wvgerrit/40883 The oemcrypto dynamic adapter will try to load a keybox from the filesystem if oemcrypto reports it doesn't have one. Previously, it would check the size of the file, and then open the file before responding to errors. Opening a non-existant file would result in a segfault. With this CL, we do not try to open the file if the size is not positive. Test: unit tests Bug: 72129404 Change-Id: I243b5d49837455c0ce07802e32e4d7e809286cfd --- .../cdm/core/src/oemcrypto_adapter_dynamic.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp index 4d4c8c57..b0aef465 100644 --- a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp +++ b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp @@ -714,8 +714,16 @@ class Adapter { return false; } ssize_t size = file_system.FileSize(filename); + if (size <= 0) { + LOGW("Could not find %s. Falling Back to L3.", filename.c_str()); + level1_.Terminate(); + metrics->OemCryptoDynamicAdapterMetrics::SetInitializationMode( + wvcdm::metrics:: + OEMCrypto_INITIALIZED_USING_L3_COULD_NOT_OPEN_FACTORY_KEYBOX); + return false; + } wvcdm::File* file = file_system.Open(filename, file_system.kReadOnly); - if (size <= 0 || !file) { + if (!file) { LOGW("Could not open %s. Falling Back to L3.", filename.c_str()); level1_.Terminate(); metrics->OemCryptoDynamicAdapterMetrics::SetInitializationMode(