Enabled log formatting warnings.

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

Clang and GCC allow for warnings against the arguments for printf-like
functions (e.i. LOGx).  These validate that the format type specified
in the format string match the corresponding argument type.

Most of the time, format specifer errors are benign; hence why they
haven't been seen as an error so far.  However, with the enabling of
specifier warnings and the enabling of warnings as errors on certain
platforms, these existing errors need to be addressed.

This CL enables format specifier warnings for most of the Widevine
code, with the OEMCrypto L3 implementation which has a single error
which requires a fix in the haystack code before being fixed in the
Widevine branch.

Strict format string warnings are not enabled for non-LP64 systems.

Bug: 137583127
Test: Compiled for Linux and Android
Change-Id: I051398332d31a20457b86563a90ad8f6d428445f
This commit is contained in:
Alex Dale
2020-08-21 18:23:44 -07:00
parent 315bf42c4f
commit f22cd20466
15 changed files with 105 additions and 91 deletions

View File

@@ -23,7 +23,6 @@
#include "wv_cdm_constants.h"
namespace {
const uint32_t kFourCcCbc1 = 0x63626331;
const uint32_t kFourCcCbcs = 0x63626373;
const uint32_t kFourCcLittleEndianCbc1 = 0x31636263;
@@ -32,10 +31,11 @@ const uint32_t kFourCcCenc = 0x63656e63;
const std::string kEmptyString;
// MAC key in the license are two separate MAC keys (client and server).
constexpr size_t kLicenseMacKeySize = wvcdm::MAC_KEY_SIZE * 2;
} // namespace
namespace wvcdm {
// Protobuf generated classes.
using video_widevine::EncryptedClientIdentification;
using video_widevine::License;
@@ -596,17 +596,17 @@ CdmResponseType CdmLicense::HandleKeyResponse(
mac_key_iv.assign(license.key(i).iv());
// Strip off PKCS#5 padding
mac_keys.assign(license.key(i).key().data(), 2 * MAC_KEY_SIZE);
mac_keys.assign(license.key(i).key().data(), kLicenseMacKeySize);
}
}
if (license.policy().can_renew() ||
(mac_key_iv.size() != 0 || mac_keys.size() != 0)) {
if (mac_key_iv.size() != KEY_IV_SIZE ||
mac_keys.size() != 2 * MAC_KEY_SIZE) {
mac_keys.size() != kLicenseMacKeySize) {
LOGE(
"MAC key/IV size error: expected = %lu/%lu, "
"MAC key/IV size error: expected = %zu/%zu, "
"actual = %zu/%zu (key/iv)",
2 * MAC_KEY_SIZE, KEY_IV_SIZE, mac_keys.size(), mac_key_iv.size());
kLicenseMacKeySize, KEY_IV_SIZE, mac_keys.size(), mac_key_iv.size());
return KEY_SIZE_ERROR_1;
}
}
@@ -1177,7 +1177,7 @@ CdmResponseType CdmLicense::HandleNewEntitledKeys(
if (content_key.size() < CONTENT_KEY_SIZE) {
LOGE(
"Entitled content key too small: "
"expected = %lu, actual = %zu (bytes)",
"expected = %zu, actual = %zu (bytes)",
CONTENT_KEY_SIZE, content_key.size());
return KEY_SIZE_ERROR_2;
} else if (content_key.size() > CONTENT_KEY_SIZE) {

View File

@@ -507,10 +507,10 @@ class WatchDog {
ssize_t size = sizeof(flag);
ssize_t size_written = file->Write(reinterpret_cast<char*>(&flag), size);
if (size != size_written) {
LOGE("Wrote %d bytes, not %d, to file %s", size_written, size,
LOGE("Wrote %zd bytes, not %zd, to file %s", size_written, size,
filename.c_str());
} else {
LOGE("I wrote %d to %s", size_written, filename.c_str());
LOGE("I wrote %zd to %s", size_written, filename.c_str());
}
}

View File

@@ -1055,7 +1055,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() {
bad_license_file_entries.push_back(usage_entry_number);
continue;
default: {
LOGW("Unknown usage entry storage type: %d, usage_entry_number = %u",
LOGW("Unknown usage entry storage type: %d, usage_entry_number = %zu",
static_cast<int>(usage_entry_info.storage_type),
usage_entry_number);
bad_license_file_entries.push_back(usage_entry_number);
@@ -1063,7 +1063,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() {
}
}
if (!retrieve_response) {
LOGW("Could not retrieve license message: usage_entry_number = %u",
LOGW("Could not retrieve license message: usage_entry_number = %zu",
usage_entry_number);
bad_license_file_entries.push_back(usage_entry_number);
continue;
@@ -1071,7 +1071,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() {
if (retrieved_entry_number != usage_entry_number) {
LOGW(
"Usage entry number mismatched: usage_entry_number = %u, "
"Usage entry number mismatched: usage_entry_number = %zu, "
"retrieved_entry_number = %u",
usage_entry_number, retrieved_entry_number);
bad_license_file_entries.push_back(usage_entry_number);
@@ -1080,7 +1080,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() {
video_widevine::License license;
if (!ParseLicenseFromLicenseMessage(license_message, &license)) {
LOGW("Could not parse license: usage_entry_number = %u",
LOGW("Could not parse license: usage_entry_number = %zu",
usage_entry_number);
bad_license_file_entries.push_back(usage_entry_number);
continue;

View File

@@ -109,7 +109,7 @@ class WvCdmEnginePreProvTest : public WvCdmTestBase {
LicenseRequest license_request;
license_request.GetDrmMessage(http_response, *response);
LOGV("response: size=%u, string:\n%s\n", response->size(),
LOGV("response: size = %zu, string =\n%s\n", response->size(),
Base64SafeEncode(
std::vector<uint8_t>(response->begin(), response->end()))
.c_str());
@@ -239,7 +239,7 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
std::string drm_msg;
LicenseRequest lic_request;
lic_request.GetDrmMessage(response, drm_msg);
LOGV("drm msg: %u bytes\r\n%s", drm_msg.size(),
LOGV("drm msg: %zu bytes\r\n%s", drm_msg.size(),
HexEncode(reinterpret_cast<const uint8_t*>(drm_msg.data()),
drm_msg.size())
.c_str());

View File

@@ -41,7 +41,7 @@ void ConcatenateChunkedResponse(const std::string http_response,
sscanf(&http_response[chunk_size_pos], "%zx", &chunk_size);
if (chunk_size > http_response.size()) {
// precaution, in case we misread chunk size
LOGE("invalid chunk size %u", chunk_size);
LOGE("Invalid chunk size %zu", chunk_size);
return;
}
@@ -64,7 +64,7 @@ void ConcatenateChunkedResponse(const std::string http_response,
sscanf(&http_response[chunk_size_pos], "%zx", &chunk_size);
if (chunk_size > http_response.size()) {
// precaution, in case we misread chunk size
LOGE("invalid chunk size %u", chunk_size);
LOGE("Invalid chunk size %zu", chunk_size);
break;
}
chunk_pos = http_response.find(kCrLf, chunk_size_pos);
@@ -104,11 +104,12 @@ bool UrlRequest::GetResponse(std::string* message) {
// non-blocking mode.
while (true) {
char read_buffer[kReadBufferSize];
int bytes = socket_.Read(read_buffer, sizeof(read_buffer), kReadTimeoutMs);
const int bytes =
socket_.Read(read_buffer, sizeof(read_buffer), kReadTimeoutMs);
if (bytes > 0) {
response.append(read_buffer, bytes);
} else if (bytes < 0) {
LOGE("read error, errno = %d", errno);
LOGE("Read error, errno = %d", errno);
return false;
} else {
// end of stream.
@@ -117,7 +118,7 @@ bool UrlRequest::GetResponse(std::string* message) {
}
ConcatenateChunkedResponse(response, message);
LOGV("HTTP response from %s://%s:%d%s: (%zd): %s", socket_.scheme().c_str(),
LOGV("HTTP response from %s://%s:%d%s: (%zu): %s", socket_.scheme().c_str(),
socket_.domain_name().c_str(), socket_.port(),
socket_.resource_path().c_str(), message->size(), message->c_str());
return true;
@@ -204,7 +205,7 @@ bool UrlRequest::PostRequestWithPath(const std::string& path,
const int ret =
socket_.Write(request.c_str(), request.size(), kWriteTimeoutMs);
LOGV("HTTP request: (%d): %s", request.size(), b2a_hex(request).c_str());
LOGV("HTTP request: (%zu): %s", request.size(), b2a_hex(request).c_str());
return ret != -1;
}

View File

@@ -327,8 +327,8 @@ EngineMetrics::~EngineMetrics() {
std::unique_lock<std::mutex> lock(session_metrics_lock_);
if (!active_session_metrics_list_.empty()
|| !completed_session_metrics_list_.empty()) {
LOGV("EngineMetrics::~EngineMetrics. Session counts: "
"active %d. completed %d.", active_session_metrics_list_.size(),
LOGV("Session counts: active = %zu, completed = %zu.",
active_session_metrics_list_.size(),
completed_session_metrics_list_.size());
}
}

View File

@@ -336,7 +336,7 @@ class WvCdmExtendedDurationTest : public WvCdmTestBase {
void LogResponseError(const std::string& message, int http_status_code) {
LOGD("HTTP Status code = %d", http_status_code);
LOGD("HTTP response(%d): %s", message.size(), b2a_hex(message).c_str());
LOGD("HTTP response(%zu): %s", message.size(), b2a_hex(message).c_str());
}
// Post a request and extract the drm message from the response
@@ -360,7 +360,7 @@ class WvCdmExtendedDurationTest : public WvCdmTestBase {
if (kHttpOk == http_status_code) {
LicenseRequest lic_request;
lic_request.GetDrmMessage(message, drm_msg);
LOGV("HTTP response body: (%u bytes)", drm_msg.size());
LOGV("HTTP response body: (%zu bytes)", drm_msg.size());
}
key_response_ = drm_msg;
return drm_msg;
@@ -408,7 +408,7 @@ class WvCdmExtendedDurationTest : public WvCdmTestBase {
if (kHttpOk == http_status_code) {
LicenseRequest license;
license.GetDrmMessage(message, usage_info);
LOGV("HTTP response body: (%u bytes)", usage_info.size());
LOGV("HTTP response body: (%zu bytes)", usage_info.size());
}
return usage_info;
}

View File

@@ -242,7 +242,7 @@ class WvCdmFeatureTest : public WvCdmTestBase {
void LogResponseError(const std::string& message, int http_status_code) {
LOGD("HTTP Status code = %d", http_status_code);
LOGD("HTTP response(%d): %s", message.size(), b2a_hex(message).c_str());
LOGD("HTTP response(%zu): %s", message.size(), b2a_hex(message).c_str());
}
// Post a request and extract the signed provisioning message from
@@ -268,13 +268,13 @@ class WvCdmFeatureTest : public WvCdmTestBase {
bool ExtractTokenType(const std::string& b64_provisioning_request_no_pad,
ClientIdentification_TokenType* token_type) {
std::string b64_provisioning_request = b64_provisioning_request_no_pad;
size_t binary_size = b64_provisioning_request.size() * 3 / 4;
const size_t binary_size = b64_provisioning_request.size() * 3 / 4;
// base64 message with pad = 4*ceil[n/3]
size_t pad_size =
const size_t pad_size =
((binary_size + 2) / 3) * 4 - b64_provisioning_request.size();
if (pad_size >= 3) return false;
b64_provisioning_request.append(pad_size, '=');
LOGW("ExtractTokenType: pad_size: %d", pad_size);
LOGW("ExtractTokenType: pad_size: %zu", pad_size);
std::vector<uint8_t> bin_provisioning_request =
Base64SafeDecode(b64_provisioning_request);
@@ -360,7 +360,7 @@ class WvCdmFeatureTest : public WvCdmTestBase {
if (kHttpOk == http_status_code) {
LicenseRequest lic_request;
lic_request.GetDrmMessage(message, drm_msg);
LOGV("HTTP response body: (%u bytes)", drm_msg.size());
LOGV("HTTP response body: (%zu bytes)", drm_msg.size());
}
return drm_msg;
}

View File

@@ -1865,7 +1865,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase {
void LogResponseError(const std::string& message, int http_status_code) {
LOGD("HTTP Status code = %d", http_status_code);
LOGD("HTTP response(%d): %s", message.size(), b2a_hex(message).c_str());
LOGD("HTTP response(%zu): %s", message.size(), b2a_hex(message).c_str());
}
// Post a request and extract the drm message from the response
@@ -1879,7 +1879,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase {
std::string message;
EXPECT_TRUE(url_request.GetResponse(&message));
int http_status_code = url_request.GetStatusCode(message);
const int http_status_code = url_request.GetStatusCode(message);
if (kHttpOk != http_status_code) {
LogResponseError(message, http_status_code);
}
@@ -1890,7 +1890,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase {
if (kHttpOk == http_status_code) {
LicenseRequest lic_request;
lic_request.GetDrmMessage(message, drm_msg);
LOGV("HTTP response body: (%u bytes)", drm_msg.size());
LOGV("HTTP response body: (%zu bytes)", drm_msg.size());
}
return drm_msg;
}
@@ -1927,7 +1927,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase {
std::string message;
EXPECT_TRUE(url_request.GetResponse(&message));
int http_status_code = url_request.GetStatusCode(message);
const int http_status_code = url_request.GetStatusCode(message);
if (kHttpOk != http_status_code) {
LogResponseError(message, http_status_code);
}
@@ -1937,7 +1937,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase {
if (kHttpOk == http_status_code) {
LicenseRequest license;
license.GetDrmMessage(message, usage_info);
LOGV("HTTP response body: (%u bytes)", usage_info.size());
LOGV("HTTP response body: (%zu bytes)", usage_info.size());
}
return usage_info;
}
@@ -6167,7 +6167,7 @@ class WvCdmRequestLicenseRollbackTest
protected:
void RollbackSystemTime(time_t rollback_time_ms) {
if (!in_rollback_state_) {
LOGW("Rolling back system time %d ms.", rollback_time_ms);
LOGW("Rolling back system time %ld ms.", rollback_time_ms);
wall_time_before_rollback_ = std::chrono::system_clock::now();
monotonic_time_before_rollback_ = std::chrono::steady_clock::now();
auto modified_wall_time = wall_time_before_rollback_ -

View File

@@ -33,8 +33,18 @@ extern LogPriority g_cutoff;
// unit tests.
CORE_UTIL_EXPORT void InitLogging();
// Only enable format specifier warnings on LP64 systems. There is
// no easy portable method to handle format specifiers for int64_t.
#if (defined(__gnuc__) || defined(__clang__)) && defined(__LP64__)
[[gnu::format(printf, 5, 6)]] CORE_UTIL_EXPORT void Log(const char* file,
const char* function,
int line,
LogPriority level,
const char* fmt, ...);
#else
CORE_UTIL_EXPORT void Log(const char* file, const char* function, int line,
LogPriority level, const char* fmt, ...);
#endif
// Log APIs
#ifndef LOGE