From e9a3a807d0e1d047482d107cb18f9dcdfa6300b6 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 8 Jul 2017 19:52:54 +0000 Subject: [PATCH] * Fix overflows in intstrtodate (bug ID 32098) git-svn-id: trunk@36687 - --- rtl/objpas/sysutils/dati.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtl/objpas/sysutils/dati.inc b/rtl/objpas/sysutils/dati.inc index bdb5b8f575..32cb2bab01 100644 --- a/rtl/objpas/sysutils/dati.inc +++ b/rtl/objpas/sysutils/dati.inc @@ -368,11 +368,11 @@ end; var df:string; - d,m,y,ly:word; + d,m,y,ly:integer; n,i:longint; c:word; dp,mp,yp,which : Byte; - s1:string[4]; + s1:string; values:array[0..3] of longint; LocalTime:tsystemtime; YearMoreThenTwoDigits : boolean; @@ -446,6 +446,7 @@ begin // Check if the year has more then two digits (if n=yp, then we are evaluating the year.) if (n=yp) and (length(s1)>2) then YearMoreThenTwoDigits := True; val(s1, values[n], c); +// Writeln(s1,'->',values[n]); if c<>0 then begin FixErrorMsg(SInvalidDateFormat,s); @@ -467,6 +468,12 @@ begin // Fill in values. getLocalTime(LocalTime); ly := LocalTime.Year; + for I:=1 to 3 do + if values[i]>high(Word) then + begin + errormsg:='Invalid date'; + exit; + end; If N=3 then begin y:=values[yp]; @@ -500,6 +507,7 @@ begin if (defs.TwoDigitYearCenturyWindow > 0) and (Y < ly) then Inc(Y, 100); end; + if not TryEncodeDate(y, m, d, result) then errormsg:='Invalid date'; end;