mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 18:25:10 +00:00
Fix more coverity warnings
Assorted minor code issues, which we should fix so any new errors stand out more. BUG=chromium:643769 BRANCH=none TEST=make runtests Change-Id: I82ece2de948ef224115c408bdfc09445d3da119b Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/390337 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
fefc682bb7
commit
770202f0c7
@@ -184,7 +184,10 @@ static int vb2_make_keypair()
|
|||||||
|
|
||||||
if (!rsa_key) {
|
if (!rsa_key) {
|
||||||
/* Check if the PEM contains only a public key */
|
/* Check if the PEM contains only a public key */
|
||||||
fseek(fp, 0, SEEK_SET);
|
if (0 != fseek(fp, 0, SEEK_SET)) {
|
||||||
|
fprintf(stderr, "Error seeking in %s\n", infile);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
rsa_key = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
|
rsa_key = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ static int do_pack(const char *infile, const char *outfile, uint32_t algorithm,
|
|||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
if (0 != vb2_write_packed_key(outfile, pubkey)) {
|
if (0 != vb2_write_packed_key(outfile, pubkey)) {
|
||||||
fprintf(stderr, "vbutil_key: Error writing key.\n");
|
fprintf(stderr, "vbutil_key: Error writing key.\n");
|
||||||
|
free(pubkey);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
free(pubkey);
|
free(pubkey);
|
||||||
|
|||||||
@@ -747,20 +747,24 @@ int VbSetSystemPropertyString(const char* name, const char* value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int InAndroid() {
|
static int InAndroid(void)
|
||||||
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
int retval = 0;
|
||||||
|
|
||||||
/* In Android, mosys utility located in /system/bin
|
/*
|
||||||
check if file exists. Using fstat because for some
|
* In Android, mosys utility located in /system/bin check if file
|
||||||
reason, stat() was seg faulting in Android */
|
* exists. Using fstat because for some reason, stat() was seg
|
||||||
|
* faulting in Android
|
||||||
|
*/
|
||||||
fd = open(MOSYS_ANDROID_PATH, O_RDONLY);
|
fd = open(MOSYS_ANDROID_PATH, O_RDONLY);
|
||||||
if (fd != -1 && fstat(fd, &s) == 0) {
|
if (fd != -1) {
|
||||||
|
if (fstat(fd, &s) == 0)
|
||||||
|
retval = 1;
|
||||||
close(fd);
|
close(fd);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
close(fd);
|
return retval;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -202,8 +202,8 @@ int vb2_copy_packed_key(struct vb2_packed_key *dest,
|
|||||||
|
|
||||||
struct vb2_packed_key *vb2_read_packed_key(const char *filename)
|
struct vb2_packed_key *vb2_read_packed_key(const char *filename)
|
||||||
{
|
{
|
||||||
struct vb2_packed_key *key;
|
struct vb2_packed_key *key = NULL;
|
||||||
uint32_t file_size;
|
uint32_t file_size = 0;
|
||||||
|
|
||||||
if (VB2_SUCCESS !=
|
if (VB2_SUCCESS !=
|
||||||
vb2_read_file(filename, (uint8_t **)&key, &file_size)) {
|
vb2_read_file(filename, (uint8_t **)&key, &file_size)) {
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ uint8_t* ReadFile(const char* filename, uint64_t* sizeptr) {
|
|||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size = ftell(f);
|
size = ftell(f);
|
||||||
if (size < 0)
|
if (size < 0) {
|
||||||
|
fclose(f);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
rewind(f);
|
rewind(f);
|
||||||
|
|
||||||
buf = malloc(size);
|
buf = malloc(size);
|
||||||
|
|||||||
@@ -224,8 +224,11 @@ static void test_verify_fw_preamble(struct vb2_packed_key *public_key,
|
|||||||
private_key, 0x5678);
|
private_key, 0x5678);
|
||||||
TEST_PTR_NEQ(hdr, NULL,
|
TEST_PTR_NEQ(hdr, NULL,
|
||||||
"vb2_verify_fw_preamble() prereq test preamble");
|
"vb2_verify_fw_preamble() prereq test preamble");
|
||||||
if (!hdr)
|
if (!hdr) {
|
||||||
|
free(body_sig);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hsize = (uint32_t) hdr->preamble_size;
|
hsize = (uint32_t) hdr->preamble_size;
|
||||||
h = (struct vb2_fw_preamble *)malloc(hsize + 16384);
|
h = (struct vb2_fw_preamble *)malloc(hsize + 16384);
|
||||||
|
|
||||||
@@ -366,8 +369,11 @@ static void test_verify_kernel_preamble(
|
|||||||
private_key);
|
private_key);
|
||||||
TEST_PTR_NEQ(hdr, NULL,
|
TEST_PTR_NEQ(hdr, NULL,
|
||||||
"vb2_verify_kernel_preamble() prereq test preamble");
|
"vb2_verify_kernel_preamble() prereq test preamble");
|
||||||
if (!hdr)
|
if (!hdr) {
|
||||||
|
free(body_sig);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hsize = (uint32_t) hdr->preamble_size;
|
hsize = (uint32_t) hdr->preamble_size;
|
||||||
struct vb2_kernel_preamble *h =
|
struct vb2_kernel_preamble *h =
|
||||||
(struct vb2_kernel_preamble *)malloc(hsize + 16384);
|
(struct vb2_kernel_preamble *)malloc(hsize + 16384);
|
||||||
|
|||||||
@@ -142,8 +142,12 @@ static void VerifyKernelPreambleTest(const VbPublicKey *public_key,
|
|||||||
vb2_create_kernel_preamble(0x1234, 0x100000, 0x300000, 0x4000,
|
vb2_create_kernel_preamble(0x1234, 0x100000, 0x300000, 0x4000,
|
||||||
body_sig, 0, 0, 0, 0, private_key);
|
body_sig, 0, 0, 0, 0, private_key);
|
||||||
TEST_NEQ(hdr && rsa, 0, "VerifyKernelPreamble() prerequisites");
|
TEST_NEQ(hdr && rsa, 0, "VerifyKernelPreamble() prerequisites");
|
||||||
if (!hdr)
|
if (!hdr) {
|
||||||
|
free(body_sig);
|
||||||
|
RSAPublicKeyFree(rsa);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hsize = (unsigned) hdr->preamble_size;
|
hsize = (unsigned) hdr->preamble_size;
|
||||||
h = (VbKernelPreambleHeader *)malloc(hsize + 16384);
|
h = (VbKernelPreambleHeader *)malloc(hsize + 16384);
|
||||||
|
|
||||||
|
|||||||
@@ -165,7 +165,10 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
|
|||||||
int signing_rsa_len = siglen_map[signing_key_algorithm] * 8;
|
int signing_rsa_len = siglen_map[signing_key_algorithm] * 8;
|
||||||
int data_rsa_len = siglen_map[data_key_algorithm] * 8;
|
int data_rsa_len = siglen_map[data_key_algorithm] * 8;
|
||||||
|
|
||||||
|
struct vb2_private_key *signing_private_key = NULL;
|
||||||
|
struct vb2_packed_key *data_public_key = NULL;
|
||||||
VbPublicKey *signing_public_key = NULL;
|
VbPublicKey *signing_public_key = NULL;
|
||||||
|
int retval = 1;
|
||||||
|
|
||||||
printf("***Testing signing algorithm: %s\n",
|
printf("***Testing signing algorithm: %s\n",
|
||||||
algo_strings[signing_key_algorithm]);
|
algo_strings[signing_key_algorithm]);
|
||||||
@@ -174,12 +177,12 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
|
|||||||
|
|
||||||
snprintf(filename, sizeof(filename),
|
snprintf(filename, sizeof(filename),
|
||||||
"%s/key_rsa%d.pem", keys_dir, signing_rsa_len);
|
"%s/key_rsa%d.pem", keys_dir, signing_rsa_len);
|
||||||
struct vb2_private_key *signing_private_key =
|
signing_private_key =
|
||||||
vb2_read_private_key_pem(filename, signing_key_algorithm);
|
vb2_read_private_key_pem(filename, signing_key_algorithm);
|
||||||
if (!signing_private_key) {
|
if (!signing_private_key) {
|
||||||
fprintf(stderr, "Error reading signing_private_key: %s\n",
|
fprintf(stderr, "Error reading signing_private_key: %s\n",
|
||||||
filename);
|
filename);
|
||||||
return 1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(filename, sizeof(filename),
|
snprintf(filename, sizeof(filename),
|
||||||
@@ -189,22 +192,23 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
|
|||||||
if (!signing_public_key) {
|
if (!signing_public_key) {
|
||||||
fprintf(stderr, "Error reading signing_public_key: %s\n",
|
fprintf(stderr, "Error reading signing_public_key: %s\n",
|
||||||
filename);
|
filename);
|
||||||
return 1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(filename, sizeof(filename),
|
snprintf(filename, sizeof(filename),
|
||||||
"%s/key_rsa%d.keyb", keys_dir, data_rsa_len);
|
"%s/key_rsa%d.keyb", keys_dir, data_rsa_len);
|
||||||
struct vb2_packed_key *data_public_key =
|
data_public_key = vb2_read_packed_keyb(filename, data_key_algorithm, 1);
|
||||||
vb2_read_packed_keyb(filename, data_key_algorithm, 1);
|
|
||||||
if (!data_public_key) {
|
if (!data_public_key) {
|
||||||
fprintf(stderr, "Error reading data_public_key: %s\n",
|
fprintf(stderr, "Error reading data_public_key: %s\n",
|
||||||
filename);
|
filename);
|
||||||
return 1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyBlockVerifyTest(signing_public_key, signing_private_key,
|
KeyBlockVerifyTest(signing_public_key, signing_private_key,
|
||||||
data_public_key);
|
data_public_key);
|
||||||
|
retval = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
if (signing_public_key)
|
if (signing_public_key)
|
||||||
free(signing_public_key);
|
free(signing_public_key);
|
||||||
if (signing_private_key)
|
if (signing_private_key)
|
||||||
@@ -212,7 +216,7 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
|
|||||||
if (data_public_key)
|
if (data_public_key)
|
||||||
free(data_public_key);
|
free(data_public_key);
|
||||||
|
|
||||||
return 0;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct test_perm
|
struct test_perm
|
||||||
|
|||||||
Reference in New Issue
Block a user