Skip to content

Commit

Permalink
Protect against int overflow in cmd_int.
Browse files Browse the repository at this point in the history
Fix compiler const warning.
  • Loading branch information
gwsw committed Jan 1, 2022
1 parent c7b8c78 commit 88c0486
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,10 @@ cmd_int(frac)
int err;

for (p = cmdbuf; *p >= '0' && *p <= '9'; p++)
n = (n * 10) + (*p - '0');
{
int digit = *p - '0';
n = (n > (INT_MAX-digit) / 10) ? INT_MAX : (n * 10) + digit;
}
*frac = 0;
if (*p++ == '.')
{
Expand Down Expand Up @@ -1557,7 +1560,7 @@ addhist_init(uparam, ml, string)
if (ml != NULL)
cmd_addhist(ml, string, 0);
else if (string != NULL)
restore_mark(string);
restore_mark((char*)string); /* stupid const cast */
}
#endif /* CMD_HISTORY */

Expand Down

0 comments on commit 88c0486

Please sign in to comment.