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

Side by Side Diff: src/platform/vboot_reference/utils/firmware_image.c

Issue 744002: Vboot Reference: Make length types explicitly sized. (Closed)
Patch Set: Created 10 years, 9 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
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 * Functions for generating and manipulating a verified boot firmware image. 5 * Functions for generating and manipulating a verified boot firmware image.
6 */ 6 */
7 7
8 #include "firmware_image.h" 8 #include "firmware_image.h"
9 9
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 29 matching lines...) Expand all
40 if (image) { 40 if (image) {
41 Free(image->firmware_sign_key); 41 Free(image->firmware_sign_key);
42 Free(image->preamble_signature); 42 Free(image->preamble_signature);
43 Free(image->firmware_signature); 43 Free(image->firmware_signature);
44 Free(image->firmware_data); 44 Free(image->firmware_data);
45 Free(image); 45 Free(image);
46 } 46 }
47 } 47 }
48 48
49 FirmwareImage* ReadFirmwareImage(const char* input_file) { 49 FirmwareImage* ReadFirmwareImage(const char* input_file) {
50 uint32_t file_size; 50 uint64_t file_size;
51 int image_len = 0; /* Total size of the firmware image. */ 51 int image_len = 0; /* Total size of the firmware image. */
52 int header_len = 0; 52 int header_len = 0;
53 int firmware_sign_key_len; 53 int firmware_sign_key_len;
54 int signature_len; 54 int signature_len;
Chris Masone 2010/03/11 02:30:46 what about the above? Are they all ok to be < 64
gauravsh 2010/03/11 02:33:39 Yes, these are always going to be bounded.
55 uint8_t* firmware_buf; 55 uint8_t* firmware_buf;
56 MemcpyState st; 56 MemcpyState st;
57 FirmwareImage* image = FirmwareImageNew(); 57 FirmwareImage* image = FirmwareImageNew();
58 58
59 if (!image) 59 if (!image)
60 return NULL; 60 return NULL;
61 61
62 firmware_buf = BufferFromFile(input_file, &file_size); 62 firmware_buf = BufferFromFile(input_file, &file_size);
63 image_len = file_size; 63 image_len = file_size;
64 64
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 StatefulMemcpy_r(&st, image->preamble, FIELD_LEN(preamble)); 181 StatefulMemcpy_r(&st, image->preamble, FIELD_LEN(preamble));
182 182
183 if (st.remaining_len != 0 ) { /* Underrun or Overrun. */ 183 if (st.remaining_len != 0 ) { /* Underrun or Overrun. */
184 Free(preamble_blob); 184 Free(preamble_blob);
185 return NULL; 185 return NULL;
186 } 186 }
187 return preamble_blob; 187 return preamble_blob;
188 } 188 }
189 189
190 190
191 uint8_t* GetFirmwareBlob(const FirmwareImage* image, int* blob_len) { 191 uint8_t* GetFirmwareBlob(const FirmwareImage* image, uint64_t* blob_len) {
192 int firmware_signature_len; 192 int firmware_signature_len;
193 uint8_t* firmware_blob = NULL; 193 uint8_t* firmware_blob = NULL;
194 uint8_t* header_blob = NULL; 194 uint8_t* header_blob = NULL;
195 uint8_t* preamble_blob = NULL; 195 uint8_t* preamble_blob = NULL;
196 MemcpyState st; 196 MemcpyState st;
197 197
198 if (!image) 198 if (!image)
199 return NULL; 199 return NULL;
200 200
201 firmware_signature_len = siglen_map[image->firmware_sign_algorithm]; 201 firmware_signature_len = siglen_map[image->firmware_sign_algorithm];
(...skipping 26 matching lines...) Expand all
228 Free(firmware_blob); 228 Free(firmware_blob);
229 return NULL; 229 return NULL;
230 } 230 }
231 return firmware_blob; 231 return firmware_blob;
232 } 232 }
233 233
234 int WriteFirmwareImage(const char* input_file, 234 int WriteFirmwareImage(const char* input_file,
235 const FirmwareImage* image) { 235 const FirmwareImage* image) {
236 int fd; 236 int fd;
237 uint8_t* firmware_blob; 237 uint8_t* firmware_blob;
238 int blob_len; 238 uint64_t blob_len;
239 239
240 if (!image) 240 if (!image)
241 return 0; 241 return 0;
242 if (-1 == (fd = creat(input_file, S_IRWXU))) { 242 if (-1 == (fd = creat(input_file, S_IRWXU))) {
243 fprintf(stderr, "Couldn't open file for writing.\n"); 243 fprintf(stderr, "Couldn't open file for writing.\n");
244 return 0; 244 return 0;
245 } 245 }
246 246
247 firmware_blob = GetFirmwareBlob(image, &blob_len); 247 firmware_blob = GetFirmwareBlob(image, &blob_len);
248 if (!firmware_blob) { 248 if (!firmware_blob) {
(...skipping 20 matching lines...) Expand all
269 "Algorithm Id = %d\n" 269 "Algorithm Id = %d\n"
270 "Signature Algorithm = %s\n" 270 "Signature Algorithm = %s\n"
271 "Key Version = %d\n\n", 271 "Key Version = %d\n\n",
272 image->header_len, 272 image->header_len,
273 image->firmware_sign_algorithm, 273 image->firmware_sign_algorithm,
274 algo_strings[image->firmware_sign_algorithm], 274 algo_strings[image->firmware_sign_algorithm],
275 image->firmware_key_version); 275 image->firmware_key_version);
276 /* TODO(gauravsh): Output hash and key signature here? */ 276 /* TODO(gauravsh): Output hash and key signature here? */
277 /* Print preamble. */ 277 /* Print preamble. */
278 printf("Firmware Version = %d\n" 278 printf("Firmware Version = %d\n"
279 "Firmware Length = %d\n\n", 279 "Firmware Length = %" PRIu64 "\n\n",
280 image->firmware_version, 280 image->firmware_version,
281 image->firmware_len); 281 image->firmware_len);
282 /* Output key signature here? */ 282 /* Output key signature here? */
283 } 283 }
284 284
285 char* kVerifyFirmwareErrors[VERIFY_FIRMWARE_MAX] = { 285 char* kVerifyFirmwareErrors[VERIFY_FIRMWARE_MAX] = {
286 "Success.", 286 "Success.",
287 "Invalid Image.", 287 "Invalid Image.",
288 "Root Key Signature Failed.", 288 "Root Key Signature Failed.",
289 "Invalid Verification Algorithm.", 289 "Invalid Verification Algorithm.",
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if (!(firmware_signature = SignatureBuf(image->firmware_data, 579 if (!(firmware_signature = SignatureBuf(image->firmware_data,
580 image->firmware_len, 580 image->firmware_len,
581 signing_key_file, 581 signing_key_file,
582 image->firmware_sign_algorithm))) 582 image->firmware_sign_algorithm)))
583 return 0; 583 return 0;
584 image->firmware_signature = (uint8_t*) Malloc(signature_len); 584 image->firmware_signature = (uint8_t*) Malloc(signature_len);
585 Memcpy(image->firmware_signature, firmware_signature, signature_len); 585 Memcpy(image->firmware_signature, firmware_signature, signature_len);
586 Free(firmware_signature); 586 Free(firmware_signature);
587 return 1; 587 return 1;
588 } 588 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698