Skip to content

Commit cd46752

Browse files
committed
FIX: prevent too many refinements in now function
fixes: Oldes/Rebol-issues#2286
1 parent 5d5bf7f commit cd46752

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/core/f-stubs.c

+19
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,25 @@
269269
return result;
270270
}
271271

272+
/***********************************************************************
273+
**
274+
*/ void Assert_Max_Refines(REBVAL *ds, REBCNT limit)
275+
/*
276+
** Scans the stack for function refinements
277+
** and throw an error if exeeds given limit
278+
**
279+
***********************************************************************/
280+
{
281+
REBINT n;
282+
REBCNT count=0;
283+
REBINT len = DS_ARGC;
284+
285+
for (n = 1; n <= len; n++) {
286+
if (D_REF(n))
287+
if(count++ == limit) Trap0(RE_BAD_REFINES);
288+
}
289+
}
290+
272291

273292
/***********************************************************************
274293
**

src/core/n-io.c

+2
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ static REBSER *Read_All_File(char *fname)
237237
REBINT n = -1;
238238
REBVAL *ret = D_RET;
239239

240+
Assert_Max_Refines(ds, D_REF(9) ? 2 : 1); // prevent too many refines like: now/year/month
241+
240242
OS_GET_TIME(&dat);
241243
if (!D_REF(9)) dat.nano = 0; // Not /precise
242244
Set_Date(ret, &dat);

src/tests/units/date-test.r3

+27
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,31 @@ Rebol [
151151

152152
===end-group===
153153

154+
155+
===start-group=== "NOW"
156+
--test-- "now"
157+
--assert integer? now/year
158+
--assert integer? now/month
159+
--assert integer? now/day
160+
--assert time? now/time
161+
--assert time? now/zone
162+
--assert date? now/date
163+
--assert integer? now/weekday
164+
--assert integer? now/yearday
165+
--assert date? now/utc
166+
167+
--test-- "now/precise"
168+
--assert time? now/time/precise
169+
--assert date? now/utc/precise
170+
--assert date? now/precise
171+
--assert integer? now/year/precise ; precise ignored
172+
173+
--test-- "now with too many refines"
174+
;@@ https://github.com/Oldes/Rebol-issues/issues/2286
175+
--assert error? try [now/time/day]
176+
--assert error? try [now/time/day/precise]
177+
--assert error? try [now/utc/month]
178+
179+
===end-group===
180+
154181
~~~end-file~~~

0 commit comments

Comments
 (0)