summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvadimt@chromium.org <vadimt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 00:03:33 +0000
committervadimt@chromium.org <vadimt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 00:03:33 +0000
commit1d4b7c7ca38a12faaf5b8878428f57b4896c1496 (patch)
tree0292489017b8ce80fab92daf4dafe2f4a54fbd3e
parent9a07c2959da5398a6dd9176e1bbf31f6ab6dc89a (diff)
downloadchromium_src-1d4b7c7ca38a12faaf5b8878428f57b4896c1496.zip
chromium_src-1d4b7c7ca38a12faaf5b8878428f57b4896c1496.tar.gz
chromium_src-1d4b7c7ca38a12faaf5b8878428f57b4896c1496.tar.bz2
Revert 239759 "The comment in base64.h implies that base::Base64..."
> The comment in base64.h implies that base::Base64Encode() can return false, but > this cannot happen in practice. Fix the comment. > > The implementation of Base64Encode() attempts to check for the return value > MODP_B64_ERROR as a failure, but modp_b64_encode() cannot return this > value. Remove the check. > > Remove unneeded integer cast. > > Change the return type to void. > > BUG=323357 > TEST=base_unittests, compile all > TBR=jochen@chromium.org,miket@chromium.org,joi@chromium.org,akalin@chromium.org,sergeyu@chromium.org > > Review URL: https://codereview.chromium.org/86913002 TBR=ricea@chromium.org Review URL: https://codereview.chromium.org/101113004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239921 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base64.cc10
-rw-r--r--base/base64.h5
-rw-r--r--base/base64_unittest.cc3
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer.cc7
-rw-r--r--chrome/browser/chromeos/settings/device_settings_cache.cc5
-rw-r--r--chrome/browser/devtools/adb/android_rsa.cc7
-rw-r--r--chrome/browser/extensions/api/developer_private/developer_private_api.cc3
-rw-r--r--chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc12
-rw-r--r--chrome/browser/extensions/api/extension_action/extension_action_api.cc3
-rw-r--r--chrome/browser/extensions/api/identity/web_auth_flow.cc3
-rw-r--r--chrome/browser/extensions/api/networking_private/networking_private_service_client.cc5
-rw-r--r--chrome/browser/extensions/api/proxy/proxy_api_helpers.cc3
-rw-r--r--chrome/browser/extensions/extension_protocols.cc17
-rw-r--r--chrome/browser/extensions/install_signer.cc3
-rw-r--r--chrome/browser/internal_auth.cc5
-rw-r--r--chrome/browser/managed_mode/managed_user_registration_utility.cc4
-rw-r--r--chrome/browser/media/desktop_streams_registry.cc6
-rw-r--r--chrome/browser/metrics/metrics_log.cc4
-rw-r--r--chrome/browser/metrics/metrics_log_serializer.cc5
-rw-r--r--chrome/browser/metrics/variations/variations_http_header_provider.cc16
-rw-r--r--chrome/browser/metrics/variations/variations_service.cc6
-rw-r--r--chrome/browser/metrics/variations/variations_service_unittest.cc2
-rw-r--r--chrome/browser/sync/profile_sync_service_harness.cc9
-rw-r--r--chrome/browser/ui/ash/screenshot_taker.cc5
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc3
-rw-r--r--chrome/browser/ui/certificate_dialogs.cc6
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_handler.cc4
-rw-r--r--chrome/common/metrics/caching_permuted_entropy_provider.cc5
-rw-r--r--chrome/test/chromedriver/chrome_launcher.cc3
-rw-r--r--chrome/test/chromedriver/chrome_launcher_unittest.cc3
-rw-r--r--chrome/test/chromedriver/net/websocket.cc8
-rw-r--r--components/policy/core/common/cloud/resource_cache.cc3
-rw-r--r--content/browser/devtools/renderer_overrides_handler.cc26
-rw-r--r--content/common/page_state_serialization_unittest.cc2
-rw-r--r--content/shell/browser/webkit_test_controller.cc3
-rw-r--r--content/shell/renderer/webkit_test_runner.cc3
-rw-r--r--extensions/common/extension.cc5
-rw-r--r--google_apis/cup/client_update_protocol.cc4
-rw-r--r--google_apis/gaia/oauth_request_signer.cc10
-rw-r--r--jingle/notifier/listener/push_notifications_send_update_task.cc12
-rw-r--r--jingle/notifier/listener/push_notifications_send_update_task_unittest.cc2
-rw-r--r--net/base/keygen_handler_win.cc5
-rw-r--r--net/cert/x509_certificate.cc3
-rw-r--r--net/http/http_auth_gssapi_posix.cc6
-rw-r--r--net/http/http_auth_handler_basic.cc10
-rw-r--r--net/http/http_auth_handler_ntlm.cc6
-rw-r--r--net/http/http_auth_sspi_win.cc6
-rw-r--r--net/test/spawned_test_server/base_test_server.cc9
-rw-r--r--net/third_party/mozilla_security_manager/nsKeygenHandler.cpp10
-rw-r--r--net/websockets/websocket_basic_handshake_stream.cc3
-rw-r--r--net/websockets/websocket_handshake_handler.cc6
-rw-r--r--remoting/base/rsa_key_pair.cc4
-rw-r--r--remoting/host/pin_hash.cc4
-rw-r--r--remoting/host/token_validator_factory_impl.cc3
-rw-r--r--remoting/protocol/auth_util.cc4
-rw-r--r--remoting/protocol/authenticator_test_base.cc2
-rw-r--r--remoting/protocol/pairing_registry.cc6
-rw-r--r--remoting/protocol/v2_authenticator.cc9
-rw-r--r--sync/internal_api/public/base/unique_position_unittest.cc2
-rw-r--r--sync/internal_api/sync_encryption_handler_impl.cc3
-rw-r--r--sync/protocol/proto_value_conversions.cc4
-rw-r--r--sync/syncable/syncable_util.cc2
-rw-r--r--sync/tools/null_invalidation_state_tracker.cc2
-rw-r--r--sync/util/cryptographer.cc6
-rw-r--r--sync/util/nigori.cc6
65 files changed, 250 insertions, 121 deletions
diff --git a/base/base64.cc b/base/base64.cc
index 8ed1249..9514b0a 100644
--- a/base/base64.cc
+++ b/base/base64.cc
@@ -8,15 +8,21 @@
namespace base {
-void Base64Encode(const StringPiece& input, std::string* output) {
+bool Base64Encode(const StringPiece& input, std::string* output) {
std::string temp;
temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte
+ // null terminates result since result is base64 text!
+ int input_size = static_cast<int>(input.size());
+
// modp_b64_encode_len() returns at least 1, so temp[0] is safe to use.
- size_t output_size = modp_b64_encode(&(temp[0]), input.data(), input.size());
+ size_t output_size = modp_b64_encode(&(temp[0]), input.data(), input_size);
+ if (output_size == MODP_B64_ERROR)
+ return false;
temp.resize(output_size); // strips off null byte
output->swap(temp);
+ return true;
}
bool Base64Decode(const StringPiece& input, std::string* output) {
diff --git a/base/base64.h b/base/base64.h
index 43d8f76..cc78edc 100644
--- a/base/base64.h
+++ b/base/base64.h
@@ -12,8 +12,9 @@
namespace base {
-// Encodes the input string in base64.
-BASE_EXPORT void Base64Encode(const StringPiece& input, std::string* output);
+// Encodes the input string in base64. Returns true if successful and false
+// otherwise. The output string is only modified if successful.
+BASE_EXPORT bool Base64Encode(const StringPiece& input, std::string* output);
// Decodes the base64 input string. Returns true if successful and false
// otherwise. The output string is only modified if successful.
diff --git a/base/base64_unittest.cc b/base/base64_unittest.cc
index 9b23194..9a5dd81 100644
--- a/base/base64_unittest.cc
+++ b/base/base64_unittest.cc
@@ -16,7 +16,8 @@ TEST(Base64Test, Basic) {
std::string decoded;
bool ok;
- Base64Encode(kText, &encoded);
+ ok = Base64Encode(kText, &encoded);
+ EXPECT_TRUE(ok);
EXPECT_EQ(kBase64Text, encoded);
ok = Base64Decode(encoded, &decoded);
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc
index 6de0259..3096166 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer.cc
+++ b/chrome/browser/bookmarks/bookmark_html_writer.cc
@@ -270,9 +270,10 @@ class Writer : public base::RefCountedThreadSafe<Writer> {
favicon_data.assign(reinterpret_cast<const char*>(data->front()),
data->size());
std::string favicon_base64_encoded;
- base::Base64Encode(favicon_data, &favicon_base64_encoded);
- GURL favicon_url("data:image/png;base64," + favicon_base64_encoded);
- favicon_string = favicon_url.spec();
+ if (base::Base64Encode(favicon_data, &favicon_base64_encoded)) {
+ GURL favicon_url("data:image/png;base64," + favicon_base64_encoded);
+ favicon_string = favicon_url.spec();
+ }
}
if (!WriteIndent() ||
diff --git a/chrome/browser/chromeos/settings/device_settings_cache.cc b/chrome/browser/chromeos/settings/device_settings_cache.cc
index 6ffbb9f..2ccc48b 100644
--- a/chrome/browser/chromeos/settings/device_settings_cache.cc
+++ b/chrome/browser/chromeos/settings/device_settings_cache.cc
@@ -28,7 +28,10 @@ bool Store(const em::PolicyData& policy, PrefService* local_state) {
if (local_state) {
std::string policy_string = policy.SerializeAsString();
std::string encoded;
- base::Base64Encode(policy_string, &encoded);
+ if (!base::Base64Encode(policy_string, &encoded)) {
+ LOG(ERROR) << "Can't encode policy in base64.";
+ return false;
+ }
local_state->SetString(prefs::kDeviceSettingsCache, encoded);
return true;
}
diff --git a/chrome/browser/devtools/adb/android_rsa.cc b/chrome/browser/devtools/adb/android_rsa.cc
index 27a52b4..371c433 100644
--- a/chrome/browser/devtools/adb/android_rsa.cc
+++ b/chrome/browser/devtools/adb/android_rsa.cc
@@ -196,9 +196,10 @@ crypto::RSAPrivateKey* AndroidRSAPrivateKey(Profile* profile) {
return NULL;
std::string key_string(key_info.begin(), key_info.end());
- base::Base64Encode(key_string, &encoded_key);
- profile->GetPrefs()->SetString(prefs::kDevToolsAdbKey,
- encoded_key);
+ if (base::Base64Encode(key_string, &encoded_key)) {
+ profile->GetPrefs()->SetString(prefs::kDevToolsAdbKey,
+ encoded_key);
+ }
}
return key.release();
}
diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
index 4037c53..db64c33 100644
--- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc
+++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
@@ -88,7 +88,8 @@ ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
GURL GetImageURLFromData(std::string contents) {
std::string contents_base64;
- base::Base64Encode(contents, &contents_base64);
+ if (!base::Base64Encode(contents, &contents_base64))
+ return GURL();
// TODO(dvh): make use of chrome::kDataScheme. Filed as crbug/297301.
const char kDataURLPrefix[] = "data:image;base64,";
diff --git a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc
index 0d67501..57f0c7f 100644
--- a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc
+++ b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc
@@ -371,7 +371,11 @@ void EPKPChallengeMachineKey::SignChallengeCallback(
}
std::string encoded_response;
- base::Base64Encode(response, &encoded_response);
+ if (!base::Base64Encode(response, &encoded_response)) {
+ SetError(kResponseBadBase64Error);
+ SendResponse(false);
+ return;
+ }
results_ = api_epkp::ChallengeMachineKey::Results::Create(encoded_response);
SendResponse(true);
@@ -540,7 +544,11 @@ void EPKPChallengeUserKey::RegisterKeyCallback(
}
std::string encoded_response;
- base::Base64Encode(response, &encoded_response);
+ if (!base::Base64Encode(response, &encoded_response)) {
+ SetError(kResponseBadBase64Error);
+ SendResponse(false);
+ return;
+ }
results_ = api_epkp::ChallengeUserKey::Results::Create(encoded_response);
SendResponse(true);
diff --git a/chrome/browser/extensions/api/extension_action/extension_action_api.cc b/chrome/browser/extensions/api/extension_action/extension_action_api.cc
index 08d8c3d..5c7b068 100644
--- a/chrome/browser/extensions/api/extension_action/extension_action_api.cc
+++ b/chrome/browser/extensions/api/extension_action/extension_action_api.cc
@@ -113,7 +113,8 @@ std::string RepresentationToString(const gfx::ImageSkia& image, float scale) {
std::string raw_str(static_cast<const char*>(bitmap_pickle.data()),
bitmap_pickle.size());
std::string base64_str;
- base::Base64Encode(raw_str, &base64_str);
+ if (!base::Base64Encode(raw_str, &base64_str))
+ return std::string();
return base64_str;
}
diff --git a/chrome/browser/extensions/api/identity/web_auth_flow.cc b/chrome/browser/extensions/api/identity/web_auth_flow.cc
index 01a284c..0ade81b 100644
--- a/chrome/browser/extensions/api/identity/web_auth_flow.cc
+++ b/chrome/browser/extensions/api/identity/web_auth_flow.cc
@@ -76,7 +76,8 @@ void WebAuthFlow::Start() {
// in OnShellWindowAdded.
std::string random_bytes;
crypto::RandBytes(WriteInto(&random_bytes, 33), 32);
- base::Base64Encode(random_bytes, &shell_window_key_);
+ bool success = base::Base64Encode(random_bytes, &shell_window_key_);
+ DCHECK(success);
// identityPrivate.onWebFlowRequest(shell_window_key, provider_url_, mode_)
scoped_ptr<base::ListValue> args(new base::ListValue());
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc b/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc
index 1c1eb29..5d94bb3 100644
--- a/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc
+++ b/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc
@@ -79,7 +79,10 @@ class CryptoVerifyImpl : public NetworkingPrivateServiceClient::CryptoVerify {
return;
}
- base::Base64Encode(ciphertext, base64_encoded_ciphertext);
+ if (!base::Base64Encode(ciphertext, base64_encoded_ciphertext)) {
+ *error = "EncodeError";
+ return;
+ }
}
};
diff --git a/chrome/browser/extensions/api/proxy/proxy_api_helpers.cc b/chrome/browser/extensions/api/proxy/proxy_api_helpers.cc
index 69d9ccb..fa88fbd 100644
--- a/chrome/browser/extensions/api/proxy/proxy_api_helpers.cc
+++ b/chrome/browser/extensions/api/proxy/proxy_api_helpers.cc
@@ -35,7 +35,8 @@ bool CreateDataURLFromPACScript(const std::string& pac_script,
std::string* pac_script_url_base64_encoded) {
// Encode pac_script in base64.
std::string pac_script_base64_encoded;
- base::Base64Encode(pac_script, &pac_script_base64_encoded);
+ if (!base::Base64Encode(pac_script, &pac_script_base64_encoded))
+ return false;
// Make it a correct data url.
*pac_script_url_base64_encoded =
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
index ae0a0fb..30a0cf2 100644
--- a/chrome/browser/extensions/extension_protocols.cc
+++ b/chrome/browser/extensions/extension_protocols.cc
@@ -86,14 +86,15 @@ net::HttpResponseHeaders* BuildHttpHeaders(
last_modified_time.ToInternalValue());
hash = base::SHA1HashString(hash);
std::string etag;
- base::Base64Encode(hash, &etag);
- raw_headers.append(1, '\0');
- raw_headers.append("ETag: \"");
- raw_headers.append(etag);
- raw_headers.append("\"");
- // Also force revalidation.
- raw_headers.append(1, '\0');
- raw_headers.append("cache-control: no-cache");
+ if (base::Base64Encode(hash, &etag)) {
+ raw_headers.append(1, '\0');
+ raw_headers.append("ETag: \"");
+ raw_headers.append(etag);
+ raw_headers.append("\"");
+ // Also force revalidation.
+ raw_headers.append(1, '\0');
+ raw_headers.append("cache-control: no-cache");
+ }
}
raw_headers.append(2, '\0');
diff --git a/chrome/browser/extensions/install_signer.cc b/chrome/browser/extensions/install_signer.cc
index eb04fe7..a144b99 100644
--- a/chrome/browser/extensions/install_signer.cc
+++ b/chrome/browser/extensions/install_signer.cc
@@ -115,8 +115,7 @@ bool HashWithMachineId(const std::string& salt, std::string* result) {
std::string result_bytes(crypto::kSHA256Length, 0);
hash->Finish(string_as_array(&result_bytes), result_bytes.size());
- base::Base64Encode(result_bytes, result);
- return true;
+ return base::Base64Encode(result_bytes, result);
}
} // namespace
diff --git a/chrome/browser/internal_auth.cc b/chrome/browser/internal_auth.cc
index 984c954..ed8ff26 100644
--- a/chrome/browser/internal_auth.cc
+++ b/chrome/browser/internal_auth.cc
@@ -166,7 +166,10 @@ void CreatePassport(const std::string& domain,
return;
}
std::string hmac_base64;
- base::Base64Encode(hmac, &hmac_base64);
+ if (!base::Base64Encode(hmac, &hmac_base64)) {
+ NOTREACHED();
+ return;
+ }
if (hmac_base64.size() != BASE64_PER_RAW(kHMACSizeInBytes)) {
NOTREACHED();
return;
diff --git a/chrome/browser/managed_mode/managed_user_registration_utility.cc b/chrome/browser/managed_mode/managed_user_registration_utility.cc
index 9b6d630..fc198ac 100644
--- a/chrome/browser/managed_mode/managed_user_registration_utility.cc
+++ b/chrome/browser/managed_mode/managed_user_registration_utility.cc
@@ -150,7 +150,9 @@ ManagedUserRegistrationUtility::Create(Profile* profile) {
// static
std::string ManagedUserRegistrationUtility::GenerateNewManagedUserId() {
std::string new_managed_user_id;
- base::Base64Encode(base::RandBytesAsString(8), &new_managed_user_id);
+ bool success = base::Base64Encode(base::RandBytesAsString(8),
+ &new_managed_user_id);
+ DCHECK(success);
return new_managed_user_id;
}
diff --git a/chrome/browser/media/desktop_streams_registry.cc b/chrome/browser/media/desktop_streams_registry.cc
index 05c2ba0..64e4160 100644
--- a/chrome/browser/media/desktop_streams_registry.cc
+++ b/chrome/browser/media/desktop_streams_registry.cc
@@ -20,8 +20,10 @@ std::string GenerateRandomStreamId() {
char buffer[kStreamIdLengthBytes];
crypto::RandBytes(buffer, arraysize(buffer));
std::string result;
- base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)),
- &result);
+ if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)),
+ &result)) {
+ LOG(FATAL) << "Base64Encode failed.";
+ }
return result;
}
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index 9ebf3bc..72d738b 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -803,8 +803,8 @@ void MetricsLog::RecordEnvironment(
std::string serialied_system_profile;
std::string base64_system_profile;
- if (system_profile->SerializeToString(&serialied_system_profile)) {
- base::Base64Encode(serialied_system_profile, &base64_system_profile);
+ if (system_profile->SerializeToString(&serialied_system_profile) &&
+ base::Base64Encode(serialied_system_profile, &base64_system_profile)) {
PrefService* local_state = GetPrefService();
local_state->SetString(prefs::kStabilitySavedSystemProfile,
base64_system_profile);
diff --git a/chrome/browser/metrics/metrics_log_serializer.cc b/chrome/browser/metrics/metrics_log_serializer.cc
index e25b379..8283ccd 100644
--- a/chrome/browser/metrics/metrics_log_serializer.cc
+++ b/chrome/browser/metrics/metrics_log_serializer.cc
@@ -141,7 +141,10 @@ void MetricsLogSerializer::WriteLogsToPrefList(
it != local_list.end(); ++it) {
// We encode the compressed log as Value::CreateStringValue() expects to
// take a valid UTF8 string.
- base::Base64Encode(it->log_text(), &encoded_log);
+ if (!base::Base64Encode(it->log_text(), &encoded_log)) {
+ list->Clear();
+ return;
+ }
base::MD5Update(&ctx, encoded_log);
list->Append(Value::CreateStringValue(encoded_log));
}
diff --git a/chrome/browser/metrics/variations/variations_http_header_provider.cc b/chrome/browser/metrics/variations/variations_http_header_provider.cc
index 08907f3..909394a 100644
--- a/chrome/browser/metrics/variations/variations_http_header_provider.cc
+++ b/chrome/browser/metrics/variations/variations_http_header_provider.cc
@@ -163,12 +163,16 @@ void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() {
proto.SerializeToString(&serialized);
std::string hashed;
- base::Base64Encode(serialized, &hashed);
- // If successful, swap the header value with the new one.
- // Note that the list of IDs and the header could be temporarily out of sync
- // if IDs are added as the header is recreated. The receiving servers are OK
- // with such discrepancies.
- variation_ids_header_ = hashed;
+ if (base::Base64Encode(serialized, &hashed)) {
+ // If successful, swap the header value with the new one.
+ // Note that the list of IDs and the header could be temporarily out of sync
+ // if IDs are added as the header is recreated. The receiving servers are OK
+ // with such discrepancies.
+ variation_ids_header_ = hashed;
+ } else {
+ NOTREACHED() << "Failed to base64 encode Variation IDs value: "
+ << serialized;
+ }
}
// static
diff --git a/chrome/browser/metrics/variations/variations_service.cc b/chrome/browser/metrics/variations/variations_service.cc
index d93c2f19..95e9905 100644
--- a/chrome/browser/metrics/variations/variations_service.cc
+++ b/chrome/browser/metrics/variations/variations_service.cc
@@ -481,7 +481,11 @@ bool VariationsService::StoreSeedData(const std::string& seed_data,
}
std::string base64_seed_data;
- base::Base64Encode(seed_data, &base64_seed_data);
+ if (!base::Base64Encode(seed_data, &base64_seed_data)) {
+ VLOG(1) << "Variations Seed data from server fails Base64Encode, rejecting "
+ << "the seed.";
+ return false;
+ }
local_state_->SetString(prefs::kVariationsSeed, base64_seed_data);
local_state_->SetString(prefs::kVariationsSeedHash, HashSeed(seed_data));
diff --git a/chrome/browser/metrics/variations/variations_service_unittest.cc b/chrome/browser/metrics/variations/variations_service_unittest.cc
index f912ebe..bda76ac 100644
--- a/chrome/browser/metrics/variations/variations_service_unittest.cc
+++ b/chrome/browser/metrics/variations/variations_service_unittest.cc
@@ -91,7 +91,7 @@ std::string SerializeSeedBase64(const VariationsSeed& seed, std::string* hash) {
*hash = base::HexEncode(sha1.data(), sha1.size());
}
std::string base64_serialized_seed;
- base::Base64Encode(serialized_seed, &base64_serialized_seed);
+ EXPECT_TRUE(base::Base64Encode(serialized_seed, &base64_serialized_seed));
return base64_serialized_seed;
}
diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc
index 3bb1763..695f277 100644
--- a/chrome/browser/sync/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/profile_sync_service_harness.cc
@@ -929,8 +929,13 @@ bool ProfileSyncServiceHarness::MatchesOtherClient(
if (marker != partner_marker) {
if (VLOG_IS_ON(2)) {
std::string marker_base64, partner_marker_base64;
- base::Base64Encode(marker, &marker_base64);
- base::Base64Encode(partner_marker, &partner_marker_base64);
+ if (!base::Base64Encode(marker, &marker_base64)) {
+ NOTREACHED();
+ }
+ if (!base::Base64Encode(
+ partner_marker, &partner_marker_base64)) {
+ NOTREACHED();
+ }
DVLOG(2) << syncer::ModelTypeToString(i.Get()) << ": "
<< profile_debug_name_ << " progress marker = "
<< marker_base64 << ", "
diff --git a/chrome/browser/ui/ash/screenshot_taker.cc b/chrome/browser/ui/ash/screenshot_taker.cc
index e5f9408..fa63be5 100644
--- a/chrome/browser/ui/ash/screenshot_taker.cc
+++ b/chrome/browser/ui/ash/screenshot_taker.cc
@@ -71,7 +71,10 @@ void CopyScreenshotToClipboard(scoped_refptr<base::RefCountedString> png_data) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
std::string encoded;
- base::Base64Encode(png_data->data(), &encoded);
+ if (!base::Base64Encode(png_data->data(), &encoded)) {
+ LOG(ERROR) << "Failed to encode base64";
+ return;
+ }
// Only cares about HTML because ChromeOS doesn't need other formats.
// TODO(dcheng): Why don't we take advantage of the ability to write bitmaps
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 1cfd4e7..0d70405 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -2611,7 +2611,8 @@ void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData(
std::string proto_data;
fingerprint->SerializeToString(&proto_data);
- base::Base64Encode(proto_data, &risk_data_);
+ bool success = base::Base64Encode(proto_data, &risk_data_);
+ DCHECK(success);
SubmitWithWallet();
}
diff --git a/chrome/browser/ui/certificate_dialogs.cc b/chrome/browser/ui/certificate_dialogs.cc
index cb32713..d200036 100644
--- a/chrome/browser/ui/certificate_dialogs.cc
+++ b/chrome/browser/ui/certificate_dialogs.cc
@@ -49,7 +49,11 @@ std::string WrapAt64(const std::string &str) {
std::string GetBase64String(net::X509Certificate::OSCertHandle cert) {
std::string base64;
- base::Base64Encode(x509_certificate_model::GetDerString(cert), &base64);
+ if (!base::Base64Encode(
+ x509_certificate_model::GetDerString(cert), &base64)) {
+ LOG(ERROR) << "base64 encoding error";
+ return std::string();
+ }
return "-----BEGIN CERTIFICATE-----\r\n" +
WrapAt64(base64) +
"-----END CERTIFICATE-----\r\n";
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
index 5af78f4..3245c69 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -1172,7 +1172,9 @@ void PrintPreviewHandler::SendCloudPrintJob(const base::RefCountedBytes* data) {
std::string raw_data(reinterpret_cast<const char*>(data->front()),
data->size());
std::string base64_data;
- base::Base64Encode(raw_data, &base64_data);
+ if (!base::Base64Encode(raw_data, &base64_data)) {
+ NOTREACHED() << "Base64 encoding PDF data.";
+ }
StringValue data_value(base64_data);
web_ui()->CallJavascriptFunction("printToCloud", data_value);
diff --git a/chrome/common/metrics/caching_permuted_entropy_provider.cc b/chrome/common/metrics/caching_permuted_entropy_provider.cc
index 2432f3f..f58dee8 100644
--- a/chrome/common/metrics/caching_permuted_entropy_provider.cc
+++ b/chrome/common/metrics/caching_permuted_entropy_provider.cc
@@ -66,7 +66,10 @@ void CachingPermutedEntropyProvider::UpdateLocalState() const {
cache_.SerializeToString(&serialized);
std::string base64_encoded;
- base::Base64Encode(serialized, &base64_encoded);
+ if (!base::Base64Encode(serialized, &base64_encoded)) {
+ NOTREACHED();
+ return;
+ }
local_state_->SetString(prefs::kMetricsPermutedEntropyCache, base64_encoded);
}
diff --git a/chrome/test/chromedriver/chrome_launcher.cc b/chrome/test/chromedriver/chrome_launcher.cc
index d293d43..6ef3a57 100644
--- a/chrome/test/chromedriver/chrome_launcher.cc
+++ b/chrome/test/chromedriver/chrome_launcher.cc
@@ -497,7 +497,8 @@ Status ProcessExtension(const std::string& extension,
if (key_len != public_key.size())
return Status(kUnknownError, "invalid public key length");
std::string public_key_base64;
- base::Base64Encode(public_key, &public_key_base64);
+ if (!base::Base64Encode(public_key, &public_key_base64))
+ return Status(kUnknownError, "cannot base64 encode public key");
std::string id = GenerateExtensionId(public_key);
// Unzip the crx file.
diff --git a/chrome/test/chromedriver/chrome_launcher_unittest.cc b/chrome/test/chromedriver/chrome_launcher_unittest.cc
index e75051b..24714d6 100644
--- a/chrome/test/chromedriver/chrome_launcher_unittest.cc
+++ b/chrome/test/chromedriver/chrome_launcher_unittest.cc
@@ -40,7 +40,8 @@ bool AddExtensionForInstall(const std::string& relative_path,
return false;
std::string crx_encoded;
- base::Base64Encode(crx_contents, &crx_encoded);
+ if (!base::Base64Encode(crx_contents, &crx_encoded))
+ return false;
extensions->push_back(crx_encoded);
return true;
}
diff --git a/chrome/test/chromedriver/net/websocket.cc b/chrome/test/chromedriver/net/websocket.cc
index 2c214f9..76d17da 100644
--- a/chrome/test/chromedriver/net/websocket.cc
+++ b/chrome/test/chromedriver/net/websocket.cc
@@ -121,7 +121,7 @@ void WebSocket::OnSocketConnect(int code) {
return;
}
- base::Base64Encode(base::RandBytesAsString(16), &sec_key_);
+ CHECK(base::Base64Encode(base::RandBytesAsString(16), &sec_key_));
std::string handshake = base::StringPrintf(
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
@@ -210,8 +210,8 @@ void WebSocket::OnReadDuringHandshake(const char* data, int len) {
const char kMagicKey[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
std::string websocket_accept;
- base::Base64Encode(base::SHA1HashString(sec_key_ + kMagicKey),
- &websocket_accept);
+ CHECK(base::Base64Encode(base::SHA1HashString(sec_key_ + kMagicKey),
+ &websocket_accept));
scoped_refptr<net::HttpResponseHeaders> headers(
new net::HttpResponseHeaders(
net::HttpUtil::AssembleRawHeaders(
@@ -262,3 +262,5 @@ void WebSocket::Close(int code) {
state_ = CLOSED;
}
+
+
diff --git a/components/policy/core/common/cloud/resource_cache.cc b/components/policy/core/common/cloud/resource_cache.cc
index 7b9e327..e527679 100644
--- a/components/policy/core/common/cloud/resource_cache.cc
+++ b/components/policy/core/common/cloud/resource_cache.cc
@@ -21,9 +21,8 @@ namespace {
// which is safe to use as a file name on all platforms.
bool Base64Encode(const std::string& value, std::string* encoded) {
DCHECK(!value.empty());
- if (value.empty())
+ if (value.empty() || !base::Base64Encode(value, encoded))
return false;
- base::Base64Encode(value, encoded);
base::ReplaceChars(*encoded, "+", "-", encoded);
base::ReplaceChars(*encoded, "/", "_", encoded);
return true;
diff --git a/content/browser/devtools/renderer_overrides_handler.cc b/content/browser/devtools/renderer_overrides_handler.cc
index 4901f34..1bd487f 100644
--- a/content/browser/devtools/renderer_overrides_handler.cc
+++ b/content/browser/devtools/renderer_overrides_handler.cc
@@ -443,13 +443,16 @@ RendererOverridesHandler::PageCaptureScreenshot(
&png,
gfx::Rect(snapshot_size))) {
std::string base64_data;
- base::Base64Encode(
+ bool success = base::Base64Encode(
base::StringPiece(reinterpret_cast<char*>(&*png.begin()), png.size()),
&base64_data);
- base::DictionaryValue* result = new base::DictionaryValue();
- result->SetString(
- devtools::Page::captureScreenshot::kResponseData, base64_data);
- return command->SuccessResponse(result);
+ if (success) {
+ base::DictionaryValue* result = new base::DictionaryValue();
+ result->SetString(
+ devtools::Page::captureScreenshot::kResponseData, base64_data);
+ return command->SuccessResponse(result);
+ }
+ return command->InternalErrorResponse("Unable to base64encode screenshot");
}
// Fallback to copying from compositing surface.
@@ -550,9 +553,16 @@ void RendererOverridesHandler::ScreenshotCaptured(
}
std::string base_64_data;
- base::Base64Encode(
- base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()),
- &base_64_data);
+ if (!base::Base64Encode(base::StringPiece(
+ reinterpret_cast<char*>(&data[0]),
+ data.size()),
+ &base_64_data)) {
+ if (command) {
+ SendAsyncResponse(
+ command->InternalErrorResponse("Unable to base64 encode"));
+ }
+ return;
+ }
base::DictionaryValue* response = new base::DictionaryValue();
response->SetString(devtools::Page::screencastFrame::kParamData,
diff --git a/content/common/page_state_serialization_unittest.cc b/content/common/page_state_serialization_unittest.cc
index b7e5895..c23a2fb 100644
--- a/content/common/page_state_serialization_unittest.cc
+++ b/content/common/page_state_serialization_unittest.cc
@@ -373,7 +373,7 @@ TEST_F(PageStateSerializationTest, DumpExpectedPageStateForBackwardsCompat) {
EXPECT_TRUE(EncodePageState(state, &encoded));
std::string base64;
- base::Base64Encode(encoded, &base64);
+ EXPECT_TRUE(base::Base64Encode(encoded, &base64));
base::FilePath path;
PathService::Get(base::DIR_TEMP, &path);
diff --git a/content/shell/browser/webkit_test_controller.cc b/content/shell/browser/webkit_test_controller.cc
index 3939669..8f458e7 100644
--- a/content/shell/browser/webkit_test_controller.cc
+++ b/content/shell/browser/webkit_test_controller.cc
@@ -170,9 +170,10 @@ void WebKitTestResultPrinter::PrintEncodedBinaryData(
*output_ << "Content-Transfer-Encoding: base64\n";
std::string data_base64;
- base::Base64Encode(
+ const bool success = base::Base64Encode(
base::StringPiece(reinterpret_cast<const char*>(&data[0]), data.size()),
&data_base64);
+ DCHECK(success);
*output_ << "Content-Length: " << data_base64.length() << "\n";
output_->write(data_base64.c_str(), data_base64.length());
diff --git a/content/shell/renderer/webkit_test_runner.cc b/content/shell/renderer/webkit_test_runner.cc
index e9b96ae..91535fd 100644
--- a/content/shell/renderer/webkit_test_runner.cc
+++ b/content/shell/renderer/webkit_test_runner.cc
@@ -292,7 +292,8 @@ WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) {
routing_id(), local_path, &contents));
std::string contents_base64;
- base::Base64Encode(contents, &contents_base64);
+ if (!base::Base64Encode(contents, &contents_base64))
+ return WebURL();
const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,";
return WebURL(GURL(data_url_prefix + contents_base64));
diff --git a/extensions/common/extension.cc b/extensions/common/extension.cc
index 0a67983..10e065b 100644
--- a/extensions/common/extension.cc
+++ b/extensions/common/extension.cc
@@ -248,10 +248,7 @@ bool Extension::ParsePEMKeyBytes(const std::string& input,
// static
bool Extension::ProducePEM(const std::string& input, std::string* output) {
DCHECK(output);
- if (input.empty())
- return false;
- base::Base64Encode(input, output);
- return true;
+ return (input.length() == 0) ? false : base::Base64Encode(input, output);
}
// static
diff --git a/google_apis/cup/client_update_protocol.cc b/google_apis/cup/client_update_protocol.cc
index afde3ab..0ff3d8f 100644
--- a/google_apis/cup/client_update_protocol.cc
+++ b/google_apis/cup/client_update_protocol.cc
@@ -122,7 +122,8 @@ std::vector<uint8> RsaPad(size_t rsa_key_size,
// needed. Call the standard Base64 encoder/decoder and then apply fixups.
std::string UrlSafeB64Encode(const std::vector<uint8>& data) {
std::string result;
- base::Base64Encode(ByteVectorToSP(data), &result);
+ if (!base::Base64Encode(ByteVectorToSP(data), &result))
+ return std::string();
// Do an tr|+/|-_| on the output, and strip any '=' padding.
for (std::string::iterator it = result.begin(); it != result.end(); ++it) {
@@ -301,3 +302,4 @@ bool ClientUpdateProtocol::DeriveSharedKey(const std::vector<uint8>& source) {
return true;
}
+
diff --git a/google_apis/gaia/oauth_request_signer.cc b/google_apis/gaia/oauth_request_signer.cc
index 115c14d..fe65d4f 100644
--- a/google_apis/gaia/oauth_request_signer.cc
+++ b/google_apis/gaia/oauth_request_signer.cc
@@ -204,12 +204,10 @@ bool SignHmacSha1(const std::string& text,
DCHECK(hmac.DigestLength() == kHmacDigestLength);
unsigned char digest[kHmacDigestLength];
bool result = hmac.Init(key) &&
- hmac.Sign(text, digest, kHmacDigestLength);
- if (result) {
- base::Base64Encode(
- std::string(reinterpret_cast<const char*>(digest), kHmacDigestLength),
- signature_return);
- }
+ hmac.Sign(text, digest, kHmacDigestLength) &&
+ base::Base64Encode(std::string(reinterpret_cast<const char*>(digest),
+ kHmacDigestLength),
+ signature_return);
return result;
}
diff --git a/jingle/notifier/listener/push_notifications_send_update_task.cc b/jingle/notifier/listener/push_notifications_send_update_task.cc
index 9b5abb6..4e0c127 100644
--- a/jingle/notifier/listener/push_notifications_send_update_task.cc
+++ b/jingle/notifier/listener/push_notifications_send_update_task.cc
@@ -71,14 +71,20 @@ buzz::XmlElement* PushNotificationsSendUpdateTask::MakeUpdateMessage(
recipient_element->AddAttr(buzz::QN_TO, recipient.to);
if (!recipient.user_specific_data.empty()) {
std::string base64_data;
- base::Base64Encode(recipient.user_specific_data, &base64_data);
- recipient_element->SetBodyText(base64_data);
+ if (!base::Base64Encode(recipient.user_specific_data, &base64_data)) {
+ DLOG(WARNING) << "Could not encode data "
+ << recipient.user_specific_data;
+ } else {
+ recipient_element->SetBodyText(base64_data);
+ }
}
}
buzz::XmlElement* data = new buzz::XmlElement(kQnData, true);
std::string base64_data;
- base::Base64Encode(notification.data, &base64_data);
+ if (!base::Base64Encode(notification.data, &base64_data)) {
+ DLOG(WARNING) << "Could not encode data " << notification.data;
+ }
data->SetBodyText(base64_data);
push->AddElement(data);
diff --git a/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc
index 0395352..c57bd93 100644
--- a/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc
+++ b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc
@@ -36,7 +36,7 @@ TEST_F(PushNotificationsSendUpdateTaskTest, MakeUpdateMessage) {
notification.data = "test_data";
std::string base64_data;
- base::Base64Encode(notification.data, &base64_data);
+ EXPECT_TRUE(base::Base64Encode(notification.data, &base64_data));
scoped_ptr<buzz::XmlElement> message(
PushNotificationsSendUpdateTask::MakeUpdateMessage(
diff --git a/net/base/keygen_handler_win.cc b/net/base/keygen_handler_win.cc
index 59d90e8..e1d432c 100644
--- a/net/base/keygen_handler_win.cc
+++ b/net/base/keygen_handler_win.cc
@@ -211,7 +211,10 @@ std::string KeygenHandler::GenKeyAndSignChallenge() {
}
std::string result;
- base::Base64Encode(spkac, &result);
+ if (!base::Base64Encode(spkac, &result)) {
+ LOG(ERROR) << "Keygen failed: Couldn't convert signed key into base64";
+ return std::string();
+ }
VLOG(1) << "Keygen succeeded";
return result;
diff --git a/net/cert/x509_certificate.cc b/net/cert/x509_certificate.cc
index a095fdf..862a202 100644
--- a/net/cert/x509_certificate.cc
+++ b/net/cert/x509_certificate.cc
@@ -665,7 +665,8 @@ bool X509Certificate::GetPEMEncodedFromDER(const std::string& der_encoded,
if (der_encoded.empty())
return false;
std::string b64_encoded;
- base::Base64Encode(der_encoded, &b64_encoded);
+ if (!base::Base64Encode(der_encoded, &b64_encoded) || b64_encoded.empty())
+ return false;
*pem_encoded = "-----BEGIN CERTIFICATE-----\n";
// Divide the Base-64 encoded data into 64-character chunks, as per
diff --git a/net/http/http_auth_gssapi_posix.cc b/net/http/http_auth_gssapi_posix.cc
index 41cbcdb..4ea4bb9 100644
--- a/net/http/http_auth_gssapi_posix.cc
+++ b/net/http/http_auth_gssapi_posix.cc
@@ -734,7 +734,11 @@ int HttpAuthGSSAPI::GenerateAuthToken(const AuthCredentials* credentials,
std::string encode_input(static_cast<char*>(output_token.value),
output_token.length);
std::string encode_output;
- base::Base64Encode(encode_input, &encode_output);
+ bool base64_rv = base::Base64Encode(encode_input, &encode_output);
+ if (!base64_rv) {
+ LOG(ERROR) << "Base64 encoding of auth token failed.";
+ return ERR_ENCODING_CONVERSION_FAILED;
+ }
*auth_token = scheme_ + " " + encode_output;
return OK;
}
diff --git a/net/http/http_auth_handler_basic.cc b/net/http/http_auth_handler_basic.cc
index e445c93..af5f188 100644
--- a/net/http/http_auth_handler_basic.cc
+++ b/net/http/http_auth_handler_basic.cc
@@ -91,9 +91,13 @@ int HttpAuthHandlerBasic::GenerateAuthTokenImpl(
DCHECK(credentials);
// TODO(eroman): is this the right encoding of username/password?
std::string base64_username_password;
- base::Base64Encode(UTF16ToUTF8(credentials->username()) + ":" +
- UTF16ToUTF8(credentials->password()),
- &base64_username_password);
+ if (!base::Base64Encode(
+ UTF16ToUTF8(credentials->username()) + ":" +
+ UTF16ToUTF8(credentials->password()),
+ &base64_username_password)) {
+ LOG(ERROR) << "Unexpected problem Base64 encoding.";
+ return ERR_UNEXPECTED;
+ }
*auth_token = "Basic " + base64_username_password;
return OK;
}
diff --git a/net/http/http_auth_handler_ntlm.cc b/net/http/http_auth_handler_ntlm.cc
index 922800c..c0387d8 100644
--- a/net/http/http_auth_handler_ntlm.cc
+++ b/net/http/http_auth_handler_ntlm.cc
@@ -89,9 +89,13 @@ int HttpAuthHandlerNTLM::GenerateAuthTokenImpl(
// Base64 encode data in output buffer and prepend "NTLM ".
std::string encode_input(static_cast<char*>(out_buf), out_buf_len);
std::string encode_output;
- base::Base64Encode(encode_input, &encode_output);
+ bool base64_rv = base::Base64Encode(encode_input, &encode_output);
// OK, we are done with |out_buf|
free(out_buf);
+ if (!base64_rv) {
+ LOG(ERROR) << "Unexpected problem Base64 encoding.";
+ return ERR_UNEXPECTED;
+ }
*auth_token = std::string("NTLM ") + encode_output;
return OK;
#endif
diff --git a/net/http/http_auth_sspi_win.cc b/net/http/http_auth_sspi_win.cc
index 5718f9e..11d64dc 100644
--- a/net/http/http_auth_sspi_win.cc
+++ b/net/http/http_auth_sspi_win.cc
@@ -280,9 +280,13 @@ int HttpAuthSSPI::GenerateAuthToken(const AuthCredentials* credentials,
// Base64 encode data in output buffer and prepend the scheme.
std::string encode_input(static_cast<char*>(out_buf), out_buf_len);
std::string encode_output;
- base::Base64Encode(encode_input, &encode_output);
+ bool base64_rv = base::Base64Encode(encode_input, &encode_output);
// OK, we are done with |out_buf|
free(out_buf);
+ if (!base64_rv) {
+ LOG(ERROR) << "Base64 encoding of auth token failed.";
+ return ERR_ENCODING_CONVERSION_FAILED;
+ }
*auth_token = scheme_ + " " + encode_output;
return OK;
}
diff --git a/net/test/spawned_test_server/base_test_server.cc b/net/test/spawned_test_server/base_test_server.cc
index 7ef2aba..775341b 100644
--- a/net/test/spawned_test_server/base_test_server.cc
+++ b/net/test/spawned_test_server/base_test_server.cc
@@ -226,8 +226,10 @@ bool BaseTestServer::GetFilePathWithReplacements(
const std::string& new_text = it->second;
std::string base64_old;
std::string base64_new;
- base::Base64Encode(old_text, &base64_old);
- base::Base64Encode(new_text, &base64_new);
+ if (!base::Base64Encode(old_text, &base64_old))
+ return false;
+ if (!base::Base64Encode(new_text, &base64_new))
+ return false;
if (first_query_parameter) {
new_file_path += "?";
first_query_parameter = false;
@@ -398,7 +400,8 @@ bool BaseTestServer::GenerateArguments(base::DictionaryValue* arguments) const {
}
if (!ssl_options_.signed_cert_timestamps.empty()) {
std::string b64_scts;
- base::Base64Encode(ssl_options_.signed_cert_timestamps, &b64_scts);
+ if (!base::Base64Encode(ssl_options_.signed_cert_timestamps, &b64_scts))
+ return false;
arguments->SetString("signed-cert-timestamps", b64_scts);
}
}
diff --git a/net/third_party/mozilla_security_manager/nsKeygenHandler.cpp b/net/third_party/mozilla_security_manager/nsKeygenHandler.cpp
index f239cc1..4cf47c4 100644
--- a/net/third_party/mozilla_security_manager/nsKeygenHandler.cpp
+++ b/net/third_party/mozilla_security_manager/nsKeygenHandler.cpp
@@ -215,9 +215,13 @@ std::string GenKeyAndSignChallenge(int key_size_in_bits,
}
// Convert the signed public key and challenge into base64/ascii.
- base::Base64Encode(
- std::string(reinterpret_cast<char*>(signedItem.data), signedItem.len),
- &result_blob);
+ if (!base::Base64Encode(std::string(reinterpret_cast<char*>(signedItem.data),
+ signedItem.len),
+ &result_blob)) {
+ LOG(ERROR) << "Couldn't convert signed public key into base64";
+ isSuccess = false;
+ goto failure;
+ }
failure:
if (!isSuccess) {
diff --git a/net/websockets/websocket_basic_handshake_stream.cc b/net/websockets/websocket_basic_handshake_stream.cc
index 8c0e42e..1a8154b 100644
--- a/net/websockets/websocket_basic_handshake_stream.cc
+++ b/net/websockets/websocket_basic_handshake_stream.cc
@@ -33,7 +33,8 @@ std::string GenerateHandshakeChallenge() {
std::string raw_challenge(websockets::kRawChallengeLength, '\0');
crypto::RandBytes(string_as_array(&raw_challenge), raw_challenge.length());
std::string encoded_challenge;
- base::Base64Encode(raw_challenge, &encoded_challenge);
+ bool encode_success = base::Base64Encode(raw_challenge, &encoded_challenge);
+ DCHECK(encode_success);
return encoded_challenge;
}
diff --git a/net/websockets/websocket_handshake_handler.cc b/net/websockets/websocket_handshake_handler.cc
index 787dde6..641b196 100644
--- a/net/websockets/websocket_handshake_handler.cc
+++ b/net/websockets/websocket_handshake_handler.cc
@@ -351,7 +351,8 @@ void ComputeSecWebSocketAccept(const std::string& key,
std::string hash =
base::SHA1HashString(key + websockets::kWebSocketGuid);
- base::Base64Encode(hash, accept);
+ bool encode_success = base::Base64Encode(hash, accept);
+ DCHECK(encode_success);
}
bool WebSocketHandshakeResponseHandler::ParseResponseInfo(
@@ -404,7 +405,8 @@ bool WebSocketHandshakeResponseHandler::ParseResponseHeaderBlock(
std::string hash =
base::SHA1HashString(challenge + websockets::kWebSocketGuid);
std::string websocket_accept;
- base::Base64Encode(hash, &websocket_accept);
+ bool encode_success = base::Base64Encode(hash, &websocket_accept);
+ DCHECK(encode_success);
std::string response_message = base::StringPrintf(
"%s %s\r\n", websockets::kHttpProtocolVersion, status->second.c_str());
diff --git a/remoting/base/rsa_key_pair.cc b/remoting/base/rsa_key_pair.cc
index 28dd2ef..1cea077 100644
--- a/remoting/base/rsa_key_pair.cc
+++ b/remoting/base/rsa_key_pair.cc
@@ -63,7 +63,9 @@ std::string RsaKeyPair::ToString() const {
CHECK(key_->ExportPrivateKey(&key_buf));
std::string key_str(key_buf.begin(), key_buf.end());
std::string key_base64;
- base::Base64Encode(key_str, &key_base64);
+ if (!base::Base64Encode(key_str, &key_base64)) {
+ LOG(FATAL) << "Base64Encode failed";
+ }
return key_base64;
}
diff --git a/remoting/host/pin_hash.cc b/remoting/host/pin_hash.cc
index c9b1ca3c..fe17f38 100644
--- a/remoting/host/pin_hash.cc
+++ b/remoting/host/pin_hash.cc
@@ -16,7 +16,9 @@ std::string MakeHostPinHash(const std::string& host_id,
std::string hash = protocol::AuthenticationMethod::ApplyHashFunction(
protocol::AuthenticationMethod::HMAC_SHA256, host_id, pin);
std::string hash_base64;
- base::Base64Encode(hash, &hash_base64);
+ if (!base::Base64Encode(hash, &hash_base64)) {
+ LOG(FATAL) << "Base64Encode failed";
+ }
return "hmac:" + hash_base64;
}
diff --git a/remoting/host/token_validator_factory_impl.cc b/remoting/host/token_validator_factory_impl.cc
index d93df62..3dd9245 100644
--- a/remoting/host/token_validator_factory_impl.cc
+++ b/remoting/host/token_validator_factory_impl.cc
@@ -107,7 +107,8 @@ class TokenValidatorImpl
std::string nonce_bytes;
crypto::RandBytes(WriteInto(&nonce_bytes, kNonceLength + 1), kNonceLength);
std::string nonce;
- base::Base64Encode(nonce_bytes, &nonce);
+ bool success = base::Base64Encode(nonce_bytes, &nonce);
+ DCHECK(success);
return "client:" + remote_jid + " host:" + local_jid + " nonce:" + nonce;
}
diff --git a/remoting/protocol/auth_util.cc b/remoting/protocol/auth_util.cc
index 17263bf..4559636 100644
--- a/remoting/protocol/auth_util.cc
+++ b/remoting/protocol/auth_util.cc
@@ -26,7 +26,9 @@ std::string GenerateSupportAuthToken(const std::string& jid,
const std::string& access_code) {
std::string sha256 = crypto::SHA256HashString(jid + " " + access_code);
std::string sha256_base64;
- base::Base64Encode(sha256, &sha256_base64);
+ if (!base::Base64Encode(sha256, &sha256_base64)) {
+ LOG(FATAL) << "Failed to encode auth token";
+ }
return sha256_base64;
}
diff --git a/remoting/protocol/authenticator_test_base.cc b/remoting/protocol/authenticator_test_base.cc
index 25b0efe..8311476 100644
--- a/remoting/protocol/authenticator_test_base.cc
+++ b/remoting/protocol/authenticator_test_base.cc
@@ -53,7 +53,7 @@ void AuthenticatorTestBase::SetUp() {
std::string key_string;
ASSERT_TRUE(base::ReadFileToString(key_path, &key_string));
std::string key_base64;
- base::Base64Encode(key_string, &key_base64);
+ ASSERT_TRUE(base::Base64Encode(key_string, &key_base64));
key_pair_ = RsaKeyPair::FromString(key_base64);
ASSERT_TRUE(key_pair_.get());
host_public_key_ = key_pair_->GetPublicKey();
diff --git a/remoting/protocol/pairing_registry.cc b/remoting/protocol/pairing_registry.cc
index f1ce333..c159ce6 100644
--- a/remoting/protocol/pairing_registry.cc
+++ b/remoting/protocol/pairing_registry.cc
@@ -49,8 +49,10 @@ PairingRegistry::Pairing PairingRegistry::Pairing::Create(
std::string shared_secret;
char buffer[kKeySize];
crypto::RandBytes(buffer, arraysize(buffer));
- base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)),
- &shared_secret);
+ if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)),
+ &shared_secret)) {
+ LOG(FATAL) << "Base64Encode failed.";
+ }
return Pairing(created_time, client_name, client_id, shared_secret);
}
diff --git a/remoting/protocol/v2_authenticator.cc b/remoting/protocol/v2_authenticator.cc
index ee5c9d1..80f7af3 100644
--- a/remoting/protocol/v2_authenticator.cc
+++ b/remoting/protocol/v2_authenticator.cc
@@ -156,7 +156,10 @@ scoped_ptr<buzz::XmlElement> V2Authenticator::GetNextMessage() {
while (!pending_messages_.empty()) {
const std::string& spake_message = pending_messages_.front();
std::string base64_message;
- base::Base64Encode(spake_message, &base64_message);
+ if (!base::Base64Encode(spake_message, &base64_message)) {
+ LOG(DFATAL) << "Cannot perform base64 encode on certificate";
+ continue;
+ }
buzz::XmlElement* eke_tag = new buzz::XmlElement(kEkeTag);
eke_tag->SetBodyText(base64_message);
@@ -168,7 +171,9 @@ scoped_ptr<buzz::XmlElement> V2Authenticator::GetNextMessage() {
if (!local_cert_.empty() && !certificate_sent_) {
buzz::XmlElement* certificate_tag = new buzz::XmlElement(kCertificateTag);
std::string base64_cert;
- base::Base64Encode(local_cert_, &base64_cert);
+ if (!base::Base64Encode(local_cert_, &base64_cert)) {
+ LOG(DFATAL) << "Cannot perform base64 encode on certificate";
+ }
certificate_tag->SetBodyText(base64_cert);
message->AddElement(certificate_tag);
certificate_sent_ = true;
diff --git a/sync/internal_api/public/base/unique_position_unittest.cc b/sync/internal_api/public/base/unique_position_unittest.cc
index 4c0a660..371874a 100644
--- a/sync/internal_api/public/base/unique_position_unittest.cc
+++ b/sync/internal_api/public/base/unique_position_unittest.cc
@@ -392,7 +392,7 @@ class SuffixGenerator {
// random anyway.
std::string input = cache_guid_ + base::Int64ToString(next_id_--);
std::string output;
- base::Base64Encode(base::SHA1HashString(input), &output);
+ CHECK(base::Base64Encode(base::SHA1HashString(input), &output));
return output;
}
diff --git a/sync/internal_api/sync_encryption_handler_impl.cc b/sync/internal_api/sync_encryption_handler_impl.cc
index 34bf0335..e468e6c 100644
--- a/sync/internal_api/sync_encryption_handler_impl.cc
+++ b/sync/internal_api/sync_encryption_handler_impl.cc
@@ -692,7 +692,8 @@ bool SyncEncryptionHandlerImpl::SetKeystoreKeys(
// Note: in order to Pack the keys, they must all be base64 encoded (else
// JSON serialization fails).
- base::Base64Encode(raw_keystore_key, &keystore_key_);
+ if (!base::Base64Encode(raw_keystore_key, &keystore_key_))
+ return false;
// Go through and save the old keystore keys. We always persist all keystore
// keys the server sends us.
diff --git a/sync/protocol/proto_value_conversions.cc b/sync/protocol/proto_value_conversions.cc
index cdb999e..0217c5c 100644
--- a/sync/protocol/proto_value_conversions.cc
+++ b/sync/protocol/proto_value_conversions.cc
@@ -54,7 +54,9 @@ base::StringValue* MakeInt64Value(int64 x) {
// that instead of a StringValue.
base::StringValue* MakeBytesValue(const std::string& bytes) {
std::string bytes_base64;
- base::Base64Encode(bytes, &bytes_base64);
+ if (!base::Base64Encode(bytes, &bytes_base64)) {
+ NOTREACHED();
+ }
return new base::StringValue(bytes_base64);
}
diff --git a/sync/syncable/syncable_util.cc b/sync/syncable/syncable_util.cc
index d92aa47..74ae06a 100644
--- a/sync/syncable/syncable_util.cc
+++ b/sync/syncable/syncable_util.cc
@@ -101,7 +101,7 @@ std::string GenerateSyncableHash(
hash_input.append(client_tag);
std::string encode_output;
- base::Base64Encode(base::SHA1HashString(hash_input), &encode_output);
+ CHECK(base::Base64Encode(base::SHA1HashString(hash_input), &encode_output));
return encode_output;
}
diff --git a/sync/tools/null_invalidation_state_tracker.cc b/sync/tools/null_invalidation_state_tracker.cc
index 6823759..ff21a6f 100644
--- a/sync/tools/null_invalidation_state_tracker.cc
+++ b/sync/tools/null_invalidation_state_tracker.cc
@@ -38,7 +38,7 @@ std::string NullInvalidationStateTracker::GetBootstrapData() const {
void NullInvalidationStateTracker::SetBootstrapData(const std::string& data) {
std::string base64_data;
- base::Base64Encode(data, &base64_data);
+ CHECK(base::Base64Encode(data, &base64_data));
LOG(INFO) << "Setting bootstrap data to: " << base64_data;
}
diff --git a/sync/util/cryptographer.cc b/sync/util/cryptographer.cc
index 29f3781..0fed51e 100644
--- a/sync/util/cryptographer.cc
+++ b/sync/util/cryptographer.cc
@@ -261,8 +261,10 @@ bool Cryptographer::GetBootstrapToken(std::string* token) const {
return false;
}
- base::Base64Encode(encrypted_token, token);
-
+ if (!base::Base64Encode(encrypted_token, token)) {
+ NOTREACHED();
+ return false;
+ }
return true;
}
diff --git a/sync/util/nigori.cc b/sync/util/nigori.cc
index e74d81a91..b0158f3 100644
--- a/sync/util/nigori.cc
+++ b/sync/util/nigori.cc
@@ -150,8 +150,7 @@ bool Nigori::Permute(Type type, const std::string& name,
output.assign(ciphertext);
output.append(hash.begin(), hash.end());
- Base64Encode(output, permuted);
- return true;
+ return Base64Encode(output, permuted);
}
// Enc[Kenc,Kmac](value)
@@ -187,8 +186,7 @@ bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const {
output.append(ciphertext);
output.append(hash.begin(), hash.end());
- Base64Encode(output, encrypted);
- return true;
+ return Base64Encode(output, encrypted);
}
bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const {