Commit 6eb8564b authored by Marek Vasut's avatar Marek Vasut

mxssb: Always return uint32_t from sb_token_to_long()

The values used in the SB configuration file must always be 32-bit
due to the MXS limitation. Make sure the input values are properly
sanitized.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 6b35460c
......@@ -474,10 +474,10 @@ static uint8_t sb_command_checksum(struct sb_command *inst)
return csum;
}
static int sb_token_to_long(char *tok, long *rid)
static int sb_token_to_long(char *tok, uint32_t *rid)
{
char *endptr;
long id;
unsigned long id;
if (tok[0] != '0' || tok[1] != 'x') {
fprintf(stderr, "ERR: Invalid hexadecimal number!\n");
......@@ -486,19 +486,24 @@ static int sb_token_to_long(char *tok, long *rid)
tok += 2;
id = strtol(tok, &endptr, 16);
if ((errno == ERANGE && (id == LONG_MAX || id == LONG_MIN)) ||
(errno != 0 && id == 0)) {
fprintf(stderr, "ERR: Section number can't be decoded!\n");
id = strtoul(tok, &endptr, 16);
if ((errno == ERANGE && id == ULONG_MAX) || (errno != 0 && id == 0)) {
fprintf(stderr, "ERR: Value can't be decoded!\n");
return -EINVAL;
}
/* Check for 32-bit overflow. */
if (id > 0xffffffff) {
fprintf(stderr, "ERR: Value too big!\n");
return -EINVAL;
}
if (endptr == tok) {
fprintf(stderr, "ERR: Deformed section ID!\n");
fprintf(stderr, "ERR: Deformed value!\n");
return -EINVAL;
}
*rid = id;
*rid = (uint32_t)id;
return 0;
}
......@@ -508,7 +513,7 @@ static int sb_build_section(struct sb_image_ctx *ictx, struct sb_cmd_list *cmd)
struct sb_sections_header *shdr;
char *tok;
uint32_t bootable = 0;
long id;
uint32_t id;
int ret;
sctx = calloc(1, sizeof(*sctx));
......@@ -660,7 +665,7 @@ static int sb_build_command_load(struct sb_image_ctx *ictx, struct sb_cmd_list *
struct sb_command *ccmd;
char *tok;
int ret, is_ivt = 0;
long dest;
uint32_t dest;
cctx = calloc(1, sizeof(*cctx));
if (!cctx)
......@@ -711,7 +716,7 @@ static int sb_build_command_load(struct sb_image_ctx *ictx, struct sb_cmd_list *
if (is_ivt) {
/* Handle IVT. */
struct sb_ivt_header *ivt;
long ivtep;
uint32_t ivtep;
ret = sb_token_to_long(tok, &ivtep);
if (ret) {
......@@ -783,7 +788,7 @@ static int sb_build_command_fill(struct sb_image_ctx *ictx, struct sb_cmd_list *
struct sb_cmd_ctx *cctx;
struct sb_command *ccmd;
char *tok;
long address, pattern, length;
uint32_t address, pattern, length;
int ret;
cctx = calloc(1, sizeof(*cctx));
......@@ -881,7 +886,7 @@ static int sb_build_command_jump_call(struct sb_image_ctx *ictx,
struct sb_cmd_ctx *cctx;
struct sb_command *ccmd;
char *tok;
long dest, arg = 0x0;
uint32_t dest, arg = 0x0;
uint32_t hab = 0;
int ret;
const char *cmdname = is_call ? "CALL" : "JUMP";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment