Skip to content

Commit 59f9cc3

Browse files
committed
ATRONIX: Check integer overflow before arithmetic operation
Because overflowing is undefined.
1 parent 690dffa commit 59f9cc3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/core/t-string.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "sys-core.h"
3131
#include "sys-scan.h"
3232
#include "sys-deci-funcs.h"
33+
#include "sys-int-funcs.h"
3334

3435
/***********************************************************************
3536
**
@@ -541,9 +542,10 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
541542
case A_PICK:
542543
case A_POKE:
543544
len = Get_Num_Arg(arg); // Position
544-
index += len - 1;
545545
//if (len > 0) index--;
546-
if (index < 0 || index >= tail) {
546+
if (REB_I32_SUB_OF(len, 1, &len)
547+
|| REB_I32_ADD_OF(index, len, &index)
548+
|| index < 0 || index >= tail) {
547549
if (action == A_PICK) goto is_none;
548550
Trap_Range(arg);
549551
}

0 commit comments

Comments
 (0)