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

Unified Diff: firmware/stub/utility_stub.c

Issue 2957014: Fix SafeMemcmp by removing any potential data-dependent branches. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git
Patch Set: . Created 10 years, 5 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 | « no previous file | firmware/version.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: firmware/stub/utility_stub.c
diff --git a/firmware/stub/utility_stub.c b/firmware/stub/utility_stub.c
index 1445008ce1ffd5cf0b8188f5ff96d34e6e8bb701..3e17f77347c11a2712647bec007d1a949d89d149 100644
--- a/firmware/stub/utility_stub.c
+++ b/firmware/stub/utility_stub.c
@@ -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;
}
« no previous file with comments | « no previous file | firmware/version.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698