Skip to content

Commit

Permalink
ATRONIX: Check integer overflow before arithmetic operation
Browse files Browse the repository at this point in the history
Because overflowing is undefined.
  • Loading branch information
Oldes committed Jun 13, 2018
1 parent 690dffa commit 59f9cc3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/t-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "sys-core.h"
#include "sys-scan.h"
#include "sys-deci-funcs.h"
#include "sys-int-funcs.h"

/***********************************************************************
**
Expand Down Expand Up @@ -541,9 +542,10 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
case A_PICK:
case A_POKE:
len = Get_Num_Arg(arg); // Position
index += len - 1;
//if (len > 0) index--;
if (index < 0 || index >= tail) {
if (REB_I32_SUB_OF(len, 1, &len)
|| REB_I32_ADD_OF(index, len, &index)
|| index < 0 || index >= tail) {
if (action == A_PICK) goto is_none;
Trap_Range(arg);
}
Expand Down

0 comments on commit 59f9cc3

Please sign in to comment.