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

Side by Side Diff: cgpt/cmd_create.c

Issue 3594010: Address some security concerns in the cgpt tool. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git
Patch Set: A little more cleanup. Take one more look, please. Created 10 years, 2 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 | « cgpt/cmd_boot.c ('k') | cgpt/cmd_find.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 #include "cgpt.h" 5 #include "cgpt.h"
6 6
7 #include <getopt.h> 7 #include <getopt.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 #include <uuid/uuid.h> 11 #include <uuid/uuid.h>
12 12
13 #include "cgptlib_internal.h" 13 #include "cgptlib_internal.h"
14 14
15 static void Usage(void) 15 static void Usage(void)
16 { 16 {
17 printf("\nUsage: %s create [OPTIONS] DRIVE\n\n" 17 printf("\nUsage: %s create [OPTIONS] DRIVE\n\n"
18 "Create or reset an empty GPT.\n\n" 18 "Create or reset an empty GPT.\n\n"
19 "Options:\n" 19 "Options:\n"
20 " -z Zero the sectors of the GPT table and entries\n" 20 " -z Zero the sectors of the GPT table and entries\n"
21 "\n", progname); 21 "\n", progname);
22 } 22 }
23 23
24 int cmd_create(int argc, char *argv[]) { 24 int cmd_create(int argc, char *argv[]) {
25 struct drive drive; 25 struct drive drive;
26 int zap = 0; 26 int zap = 0;
27 27
28 int c; 28 int c;
29 int errorcnt = 0; 29 int errorcnt = 0;
30 30
31 opterr = 0; // quiet, you 31 opterr = 0; // quiet, you
32 while ((c=getopt(argc, argv, ":hz")) != -1) 32 while ((c=getopt(argc, argv, ":hz")) != -1)
33 { 33 {
34 switch (c) 34 switch (c)
35 { 35 {
36 case 'z': 36 case 'z':
37 zap = 1; 37 zap = 1;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 // Erase the data 70 // Erase the data
71 memset(drive.gpt.primary_header, 0, 71 memset(drive.gpt.primary_header, 0,
72 drive.gpt.sector_bytes * GPT_HEADER_SECTOR); 72 drive.gpt.sector_bytes * GPT_HEADER_SECTOR);
73 memset(drive.gpt.secondary_header, 0, 73 memset(drive.gpt.secondary_header, 0,
74 drive.gpt.sector_bytes * GPT_HEADER_SECTOR); 74 drive.gpt.sector_bytes * GPT_HEADER_SECTOR);
75 memset(drive.gpt.primary_entries, 0, 75 memset(drive.gpt.primary_entries, 0,
76 drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS); 76 drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS);
77 memset(drive.gpt.secondary_entries, 0, 77 memset(drive.gpt.secondary_entries, 0,
78 drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS); 78 drive.gpt.sector_bytes * GPT_ENTRIES_SECTORS);
79 79
80 drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 | 80 drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
81 GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2); 81 GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2);
82 82
83 // Initialize a blank set 83 // Initialize a blank set
84 if (!zap) 84 if (!zap)
85 { 85 {
86 GptHeader *h = (GptHeader *)drive.gpt.primary_header; 86 GptHeader *h = (GptHeader *)drive.gpt.primary_header;
87 memcpy(h->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE); 87 memcpy(h->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
88 h->revision = GPT_HEADER_REVISION; 88 h->revision = GPT_HEADER_REVISION;
89 h->size = sizeof(GptHeader); 89 h->size = sizeof(GptHeader);
90 h->my_lba = 1; 90 h->my_lba = 1;
91 h->alternate_lba = drive.gpt.drive_sectors - 1; 91 h->alternate_lba = drive.gpt.drive_sectors - 1;
92 h->first_usable_lba = 1 + 1 + GPT_ENTRIES_SECTORS; 92 h->first_usable_lba = 1 + 1 + GPT_ENTRIES_SECTORS;
93 h->last_usable_lba = drive.gpt.drive_sectors - 1 - GPT_ENTRIES_SECTORS - 1; 93 h->last_usable_lba = drive.gpt.drive_sectors - 1 - GPT_ENTRIES_SECTORS - 1;
94 uuid_generate((uint8_t *)&h->disk_uuid); 94 uuid_generate((uint8_t *)&h->disk_uuid);
95 h->entries_lba = 2; 95 h->entries_lba = 2;
96 h->number_of_entries = 128; 96 h->number_of_entries = 128;
97 h->size_of_entry = sizeof(GptEntry); 97 h->size_of_entry = sizeof(GptEntry);
98 98
99 // Copy to secondary 99 // Copy to secondary
100 RepairHeader(&drive.gpt, MASK_PRIMARY); 100 RepairHeader(&drive.gpt, MASK_PRIMARY);
101 101
102 UpdateCrc(&drive.gpt); 102 UpdateCrc(&drive.gpt);
103 } 103 }
104 104
105 // Write it all out 105 // Write it all out
106 return DriveClose(&drive, 1); 106 return DriveClose(&drive, 1);
107 } 107 }
OLDNEW
« no previous file with comments | « cgpt/cmd_boot.c ('k') | cgpt/cmd_find.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698