Fix multiple issues reported by Coverity Scan

This commit is contained in:
hexkyz
2018-07-26 18:45:18 +01:00
parent fd88bd1d2c
commit 7836609839
10 changed files with 30 additions and 14 deletions

View File

@@ -643,7 +643,7 @@ static int sdmmc_sd_switch(sdmmc_device_t *device, uint32_t mode, uint32_t group
static int sdmmc_sd_set_current_limit(sdmmc_device_t *device, uint8_t *status)
{
/* Start with the highest possible limit. */
uint32_t current_limit = SD_SET_CURRENT_LIMIT_800;
int32_t current_limit = SD_SET_CURRENT_LIMIT_800;
/* Try each limit. */
while (current_limit > SD_SET_CURRENT_NO_CHANGE)

View File

@@ -110,5 +110,6 @@ void load_stage2(const char *bct0) {
g_chainloader_entries[0].num = 0;
g_chainloader_entrypoint = config.entrypoint;
strncpy(g_stage2_path, config.path, sizeof(g_stage2_path));
strncpy(g_stage2_path, config.path, sizeof(g_stage2_path) - 1);
g_stage2_path[sizeof(g_stage2_path) - 1] = '\0';
}

View File

@@ -359,6 +359,8 @@ static void fsdev_filinfo_to_st(struct stat *st, const FILINFO *info) {
date.tm_sec = (info->ftime << 1) & 63;
date.tm_min = (info->ftime >> 5) & 63;
date.tm_hour = (info->ftime >> 11) & 31;
date.tm_isdst = 0;
st->st_atime = st->st_mtime = st->st_ctime = mktime(&date);
st->st_size = (off_t)info->fsize;
@@ -459,7 +461,7 @@ static off_t fsdev_seek(struct _reent *r, void *fd, off_t pos, int whence) {
return -1;
}
if(pos < 0 && pos + off < 0) {
if ((FSIZE_t)pos < 0 && (FSIZE_t)pos + off < 0) {
/* don't allow seek to before the beginning of the file */
r->_errno = EINVAL;
return -1;

View File

@@ -79,7 +79,7 @@ int gpt_iterate_through_entries(FILE *disk, size_t sector_size, gpt_entry_iterat
/* Iterate through the entries. */
for (uint32_t i = 0; i < hdr.entry_count; i++) {
if (fread(&entry, sizeof(efi_entry_t), 1, disk) == 0) {
if (!fread(&entry, sizeof(efi_entry_t), 1, disk)) {
return -1;
}

View File

@@ -45,7 +45,7 @@ static int get_tsec_key(void *dst, const void *tsec_fw, size_t tsec_fw_size, uin
static int get_keyblob(nx_keyblob_t *dst, uint32_t revision, const nx_keyblob_t *keyblobs, uint32_t available_revision) {
if (revision >= 0x20) {
return -1;
generic_panic();
/* TODO: what should we do? */
}
if (keyblobs != NULL) {
@@ -80,7 +80,7 @@ static int decrypt_keyblob(const nx_keyblob_t *keyblobs, uint32_t revision, uint
decrypt_data_into_keyslot(0xB, keyslot, keyblob_mac_seed, 0x10);
/* Validate keyblob. */
se_compute_aes_128_cmac(0xB, work_buffer, 0x10, keyblob.mac + sizeof(keyblob.mac), sizeof(keyblob) - sizeof(keyblob.mac));
se_compute_aes_128_cmac(0xB, work_buffer, 0x10, &keyblob + sizeof(keyblob.mac), sizeof(keyblob) - sizeof(keyblob.mac));
if (safe_memcmp(keyblob.mac, work_buffer, 0x10)) {
return -1;
}

View File

@@ -157,7 +157,7 @@ static int nxfs_mount_partition_gpt_callback(const efi_entry_t *entry, void *par
(void)disk;
device_partition_t *parent = (device_partition_t *)param;
device_partition_t devpart = *parent;
char name_buffer[64];
char name_buffer[128];
const uint16_t *utf16name = entry->name;
uint32_t name_len;
int rc;
@@ -307,6 +307,11 @@ int nxfs_mount_all(void) {
}
rawnand = fopen("rawnand:/", "rb");
if (rawnand == NULL) {
return -1;
}
rc = gpt_iterate_through_entries(rawnand, model.sector_size, nxfs_mount_partition_gpt_callback, &model);
fclose(rawnand);

View File

@@ -65,7 +65,7 @@ int package1_read_and_parse_boot0(void **package1loader, size_t *package1loader_
/* Read the full keyblob area.*/
for (size_t i = 0; i < 32; i++) {
if (fread(d.sector, 0x200, 1, boot0) == 0) {
if (!fread(d.sector, 0x200, 1, boot0)) {
return -1;
}
keyblobs[i] = d.keyblob;

View File

@@ -643,7 +643,7 @@ static int sdmmc_sd_switch(sdmmc_device_t *device, uint32_t mode, uint32_t group
static int sdmmc_sd_set_current_limit(sdmmc_device_t *device, uint8_t *status)
{
/* Start with the highest possible limit. */
uint32_t current_limit = SD_SET_CURRENT_LIMIT_800;
int32_t current_limit = SD_SET_CURRENT_LIMIT_800;
/* Try each limit. */
while (current_limit > SD_SET_CURRENT_NO_CHANGE)