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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | firmware/version.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Stub implementations of utility functions which call their linux-specific 5 * Stub implementations of utility functions which call their linux-specific
6 * equivalents. 6 * equivalents.
7 */ 7 */
8 8
9 #define _STUB_IMPLEMENTATION_ 9 #define _STUB_IMPLEMENTATION_
10 #include "utility.h" 10 #include "utility.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 void* Memset(void* d, const uint8_t c, uint64_t n) { 55 void* Memset(void* d, const uint8_t c, uint64_t n) {
56 uint8_t *dest = d; /* the only way to keep both cl and gcc happy */ 56 uint8_t *dest = d; /* the only way to keep both cl and gcc happy */
57 while (n--) { 57 while (n--) {
58 *dest++ = c; 58 *dest++ = c;
59 } 59 }
60 return dest; 60 return dest;
61 } 61 }
62 62
63
63 int SafeMemcmp(const void* s1, const void* s2, size_t n) { 64 int SafeMemcmp(const void* s1, const void* s2, size_t n) {
64 int match = 0; 65 int result = 0;
66 if (0 == n)
67 return 1;
68
65 const unsigned char* us1 = s1; 69 const unsigned char* us1 = s1;
66 const unsigned char* us2 = s2; 70 const unsigned char* us2 = s2;
67 while (n--) { 71 /* Code snippet without data-dependent branch due to
68 if (*us1++ != *us2++) 72 * Nate Lawson (nate@root.org) of Root Labs. */
69 match = 1; 73 while (n--)
70 } 74 result |= *us1++ ^ *us2++;
71 75
72 return match; 76 return result != 0;
73 } 77 }
OLDNEW
« 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