Skip to content

Commit

Permalink
FIX: prevent too many refinements in now function
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 11, 2020
1 parent 5d5bf7f commit cd46752
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/core/f-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@
return result;
}

/***********************************************************************
**
*/ void Assert_Max_Refines(REBVAL *ds, REBCNT limit)
/*
** Scans the stack for function refinements
** and throw an error if exeeds given limit
**
***********************************************************************/
{
REBINT n;
REBCNT count=0;
REBINT len = DS_ARGC;

for (n = 1; n <= len; n++) {
if (D_REF(n))
if(count++ == limit) Trap0(RE_BAD_REFINES);
}
}


/***********************************************************************
**
Expand Down
2 changes: 2 additions & 0 deletions src/core/n-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ static REBSER *Read_All_File(char *fname)
REBINT n = -1;
REBVAL *ret = D_RET;

Assert_Max_Refines(ds, D_REF(9) ? 2 : 1); // prevent too many refines like: now/year/month

OS_GET_TIME(&dat);
if (!D_REF(9)) dat.nano = 0; // Not /precise
Set_Date(ret, &dat);
Expand Down
27 changes: 27 additions & 0 deletions src/tests/units/date-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,31 @@ Rebol [

===end-group===


===start-group=== "NOW"
--test-- "now"
--assert integer? now/year
--assert integer? now/month
--assert integer? now/day
--assert time? now/time
--assert time? now/zone
--assert date? now/date
--assert integer? now/weekday
--assert integer? now/yearday
--assert date? now/utc

--test-- "now/precise"
--assert time? now/time/precise
--assert date? now/utc/precise
--assert date? now/precise
--assert integer? now/year/precise ; precise ignored

--test-- "now with too many refines"
;@@ https://github.com/Oldes/Rebol-issues/issues/2286
--assert error? try [now/time/day]
--assert error? try [now/time/day/precise]
--assert error? try [now/utc/month]

===end-group===

~~~end-file~~~

0 comments on commit cd46752

Please sign in to comment.