Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3265)

Unified Diff: base/pickle.cc

Issue 1619363002: Add compile time checks against longs being used in IPC structs on 32 bit Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more per Dmitry Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/pickle.cc
diff --git a/base/pickle.cc b/base/pickle.cc
index d83391bb524194b212a1f86ea0da26c1befd84ea..9447c806fac0a988b66d023626c4cf3714901d98 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -11,6 +11,7 @@
#include "base/bits.h"
#include "base/macros.h"
+#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
namespace base {
@@ -89,7 +90,15 @@ bool PickleIterator::ReadInt(int* result) {
}
bool PickleIterator::ReadLong(long* result) {
- return ReadBuiltinType(result);
+ // Always read long as a 64-bit value to ensure compatibility between 32-bit
+ // and 64-bit processes.
+ int64_t result_int64 = 0;
+ if (!ReadBuiltinType(&result_int64))
+ return false;
+ // CHECK if the cast truncates the value so that we know to change this IPC
+ // parameter to use int64_t.
+ *result = base::checked_cast<long>(result_int64);
Tom Sepez 2016/01/27 18:23:20 Maybe we return FALSE if the value is too big to f
jam 2016/01/27 18:42:55 good question: i wanted to avoid this because it l
+ return true;
}
bool PickleIterator::ReadUInt16(uint16_t* result) {
@@ -112,10 +121,12 @@ bool PickleIterator::ReadSizeT(size_t* result) {
// Always read size_t as a 64-bit value to ensure compatibility between 32-bit
// and 64-bit processes.
uint64_t result_uint64 = 0;
- bool success = ReadBuiltinType(&result_uint64);
- *result = static_cast<size_t>(result_uint64);
- // Fail if the cast above truncates the value.
- return success && (*result == result_uint64);
+ if (!ReadBuiltinType(&result_uint64))
+ return false;
+ // CHECK if the cast truncates the value so that we know to change this IPC
+ // parameter to use uint64_t.
Tom Sepez 2016/01/27 18:23:20 Same here.
+ *result = base::checked_cast<size_t>(result_uint64);
+ return true;
}
bool PickleIterator::ReadFloat(float* result) {
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698