mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 02:05:01 +00:00
Fix SafeMemcmp by removing any potential data-dependent branches.
Credit: Nate Lawson of Root Labs Review URL: http://codereview.chromium.org/2957014
This commit is contained in:
@@ -60,14 +60,18 @@ void* Memset(void* d, const uint8_t c, uint64_t n) {
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
int SafeMemcmp(const void* s1, const void* s2, size_t n) {
|
||||
int match = 0;
|
||||
int result = 0;
|
||||
if (0 == n)
|
||||
return 1;
|
||||
|
||||
const unsigned char* us1 = s1;
|
||||
const unsigned char* us2 = s2;
|
||||
while (n--) {
|
||||
if (*us1++ != *us2++)
|
||||
match = 1;
|
||||
}
|
||||
/* Code snippet without data-dependent branch due to
|
||||
* Nate Lawson (nate@root.org) of Root Labs. */
|
||||
while (n--)
|
||||
result |= *us1++ ^ *us2++;
|
||||
|
||||
return match;
|
||||
return result != 0;
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
char* VbootVersion = "VBOOv=43853f81";
|
||||
char* VbootVersion = "VBOOv=de3135df";
|
||||
|
||||
Reference in New Issue
Block a user