DM: Fix potential overflow and return value issues

Fix by a fixed string length and correcting return value

Signed-off-by: Huang Yang <yang.huang@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
This commit is contained in:
Huang, Yang 2018-05-27 15:35:07 -04:00 committed by lijinxia
parent c50db02881
commit c7d1460dfb
2 changed files with 10 additions and 9 deletions

View File

@ -42,13 +42,15 @@ static int virtio_rpmb_debug = 1;
#define DPRINTF(params) do { if (virtio_rpmb_debug) printf params; } while (0) #define DPRINTF(params) do { if (virtio_rpmb_debug) printf params; } while (0)
#define WPRINTF(params) (printf params) #define WPRINTF(params) (printf params)
#define READ_STR_LEN 10
#define WRITE_STR_LEN 11
static uint32_t phy_counter = 0; static uint32_t phy_counter = 0;
static uint32_t virt_counter = 0; static uint32_t virt_counter = 0;
static uint8_t rpmb_key[RPMB_KEY_32_LEN] = {0}; static uint8_t rpmb_key[RPMB_KEY_32_LEN] = {0};
static uint8_t virt_rpmb_key[RPMB_KEY_32_LEN] = {0}; static uint8_t virt_rpmb_key[RPMB_KEY_32_LEN] = {0};
static uint16_t g_rpmb_mode = RPMB_SIM_MODE; static uint16_t g_rpmb_mode = RPMB_SIM_MODE;
static const char READ_DATA_STR[] = "read data"; static const char READ_DATA_STR[READ_STR_LEN] = "read data";
static const char WRITE_DATA_STR[] = "write data"; static const char WRITE_DATA_STR[WRITE_STR_LEN] = "write data";
//TODO: will be read from config file. //TODO: will be read from config file.
static uint16_t get_uos_count(void) static uint16_t get_uos_count(void)

View File

@ -133,7 +133,7 @@ static void rpmb_sim_close(void)
rpmb_fd = NULL; rpmb_fd = NULL;
} }
static size_t file_write(FILE *fp, const void *buf, size_t size, off_t offset) static int file_write(FILE *fp, const void *buf, size_t size, off_t offset)
{ {
size_t rc = 0; size_t rc = 0;
@ -147,15 +147,14 @@ static size_t file_write(FILE *fp, const void *buf, size_t size, off_t offset)
return -1; return -1;
} }
rc = fflush(fp); if (fflush(fp) < 0) {
if (rc < 0) { return -1;
return -1;
} else {
return 0;
} }
return rc;
} }
static size_t file_read(FILE *fp, void *buf, size_t size, off_t offset) static int file_read(FILE *fp, void *buf, size_t size, off_t offset)
{ {
size_t rc = 0; size_t rc = 0;