Merges to android Pi release (part 6)

These are a set of CLs merged from the wv cdm repo to the android repo.

* Enable Cast for Android Things build.

  Author: Thoren Paulson <thoren@google.com>

  [ Merge of http://go/wvgerrit/29941 ]

  Added a path to make_cast_libwvlevel3 for Android Things. Added the new
  system id to the preprocessor guards in android_keybox.cpp. Guarded the
  references to stderr in page_allocator.cpp because for some reason they
  don't get resolved when we link against the resulting library.

  BUG: 63443584

* Resolve memory leaks in use of OpenSSL.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/32700 ]

  Use of EVP_CIPHER_CTX requires a call to EVP_CIPHER_CTX_cleanup().

* Memory leak in OpenSSL RSA key handling.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/32621 ]

  This fixes a range of tests. --gtest_filter="CdmDecrypt*" runs
  five tests and still loses 5 objects totalling 1320 bytes (down
  from 6200 bytes).

* Unit test and mock OEMCrypto memory leaks.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/32640 ]

  More memory leak cleanup. All remaining leaks are due
  to calls to CRYPTO_malloc() without the matching free
  (i.e., calls into openssl).

* Clean up memory leaks in tests.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/32600 ]

  This is the first pass at cleaning up memory leaks. These leaks
  were affecting a lot of tests, making it hard to identify more
  serious leaks.

  Switch to unique_ptr<> pointers for CdmEngine in
  generic_crypto_unittest tests for FileSystem object in
  mock OEMCrypto's CryptoEngine object.

* Fix broken tests - linux-only & address sanitizer failures.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/32460 ]

  Fix broken test:
    WvCdmEnginePreProvTestStaging.ServiceCertificateInitialNoneTest

  Fix failures found by address sanitizer:
    DeviceFilesUsageInfoTest.RetrieveByProviderSessionToken
    DeviceFilesUsageInfoTest.UpdateUsageInfo

  NOTE: address sanitizer cannot handle EXPECT_CALL macros containing
  a call with a Contains matcher as an argument, e.g.:

  EXPECT_CALL(file,
              Write(Contains(certificate, wrapped_private_key, 0),
                    Gt(certificate.size() + wrapped_private_key.size())))

  The address sanitizer reports a crash, issues a report, and stops. A
  temporary fix is to replace the "Contains()" argument with "_".

* Usage license handling corrections

  Author: Rahul Frias <rfrias@google.com>

  [ Merge of http://go/wvgerrit/28540 ]

  Validate that offline licenses that do not contain a provider session
  token are not handled by the TEE.

  BUG: 38490468

  Test: WV Unit/integration tests, GtsMediaTestCases,
        WvCdmRequestLicenseTest.ReleaseRetryL3OfflineKeySessionUsageDisabledTest

* UsageTableEntry::CopyOldUsageEntry memcpy read out of range.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/32220 ]

  The function copies the pst from a variable length input vector
  into a 256 byte character array. But the length argument was a
  fixed value - MAC_KEY_SIZE. Depending on the actual PST length this
  can lead to memcpy reading out of bounds or the PST getting truncated.

BUG: 71650075
Test: Not currently passing. Will be addressed in a subsequent
  commit in the chain.

Change-Id: I81a4593d7d04d0ef6069ce48d0601b6fbdd85de9
This commit is contained in:
Rahul Frias
2018-01-09 22:56:21 -08:00
parent b7c9ad57c9
commit 00da44bb68
63 changed files with 977 additions and 582 deletions

View File

@@ -18,7 +18,7 @@
#include "lock.h"
#include "distribution.h"
#include "metric_publisher.h"
#include "metric_serialization.h"
namespace wvcdm {
namespace metrics {
@@ -27,11 +27,11 @@ class EventMetricTest;
// This base class provides the common defintion used by all templated
// instances of EventMetric.
class BaseEventMetric : public MetricPublisher {
class BaseEventMetric : public MetricSerializable {
public:
// Publish metric values to the MetricNotification. |subscriber| must
// Send metric values to the MetricSerializer. |serializer| must
// not be null and is owned by the caller.
virtual void Publish(MetricNotification* subscriber);
virtual void Serialize(MetricSerializer* serializer);
protected:
// Instantiates a BaseEventMetric.
@@ -238,20 +238,57 @@ inline void AppendFieldNames(std::vector<std::string>* field_name_vector,
va_end(field_names);
}
// These helper methods and FirstUnusedType assure that there is no mismatch
// between the specified types for EventMetrics and the constructors and
// methods used for the specializations.
template <bool>
struct CompileAssert {};
#define COMPILE_ASSERT(expr, msg) \
typedef impl::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
template <typename T> struct is_unused { static const bool value = false; };
template <> struct is_unused<Unused> { static const bool value = true; };
template <typename F1, typename F2, typename F3, typename F4>
class FirstUnusedType {
static const bool a = is_unused<F1>::value;
static const bool b = is_unused<F2>::value;
static const bool c = is_unused<F3>::value;
static const bool d = is_unused<F4>::value;
// Check that all types after the first Unused are also Unused.
COMPILE_ASSERT(a <= b, Invalid_Unused_At_Position_2);
COMPILE_ASSERT(b <= c, Invalid_Unused_At_Position_3);
COMPILE_ASSERT(c <= d, Invalid_Unused_At_Position_4);
public:
static const int value = 5 - (a + b + c + d);
};
// Asserts that no Unused types exist before N; after N, are all Unused types.
#define ASSERT_METRIC_UNUSED_START_FROM(N) \
COMPILE_ASSERT((\
impl::FirstUnusedType<F1, F2, F3, F4>::value) == N, \
Unused_Start_From_##N)
} // namespace impl
// Overloaded template constructor implementations for EventMetric.
template<typename F1, typename F2, typename F3, typename F4>
EventMetric<F1, F2, F3, F4>::EventMetric(
const std::string& metric_name)
: BaseEventMetric(metric_name) {}
: BaseEventMetric(metric_name) {
ASSERT_METRIC_UNUSED_START_FROM(1);
}
template<typename F1, typename F2, typename F3, typename F4>
EventMetric<F1, F2, F3, F4>::EventMetric(
const std::string& metric_name,
const char* field_name)
: BaseEventMetric(metric_name) {
impl::AppendFieldNames(&field_names_, 1, field_name);
ASSERT_METRIC_UNUSED_START_FROM(2);
impl::AppendFieldNames(&field_names_,
impl::FirstUnusedType<F1, F2, F3, F4>::value - 1,
field_name);
}
template<typename F1, typename F2, typename F3, typename F4>
EventMetric<F1, F2, F3, F4>::EventMetric(
@@ -259,7 +296,10 @@ EventMetric<F1, F2, F3, F4>::EventMetric(
const char* field_name1,
const char* field_name2)
: BaseEventMetric(metric_name) {
impl::AppendFieldNames(&field_names_, 2, field_name1, field_name2);
ASSERT_METRIC_UNUSED_START_FROM(3);
impl::AppendFieldNames(&field_names_,
impl::FirstUnusedType<F1, F2, F3, F4>::value - 1,
field_name1, field_name2);
}
template<typename F1, typename F2, typename F3, typename F4>
EventMetric<F1, F2, F3, F4>::EventMetric(
@@ -268,8 +308,10 @@ EventMetric<F1, F2, F3, F4>::EventMetric(
const char* field_name2,
const char* field_name3)
: BaseEventMetric(metric_name) {
ASSERT_METRIC_UNUSED_START_FROM(4);
impl::AppendFieldNames(&field_names_,
3, field_name1, field_name2, field_name3);
impl::FirstUnusedType<F1, F2, F3, F4>::value - 1,
field_name1, field_name2, field_name3);
}
template<typename F1, typename F2, typename F3, typename F4>
EventMetric<F1, F2, F3, F4>::EventMetric(
@@ -279,8 +321,10 @@ EventMetric<F1, F2, F3, F4>::EventMetric(
const char* field_name3,
const char* field_name4)
: BaseEventMetric(metric_name) {
ASSERT_METRIC_UNUSED_START_FROM(5);
impl::AppendFieldNames(&field_names_,
4, field_name1, field_name2,
impl::FirstUnusedType<F1, F2, F3, F4>::value - 1,
field_name1, field_name2,
field_name3, field_name4);
}