* proper range checking for TryStrToDWord, should resolve all issues in

This commit is contained in:
florian 2022-01-02 21:46:14 +01:00
parent 435f3a9fe2
commit 983fbff871
2 changed files with 21 additions and 3 deletions
rtl/objpas/sysutils
tests/webtbs

View File

@ -1007,10 +1007,14 @@ begin
end;
function TryStrToDWord(const s: string; Out D: DWord): boolean;
var Error : word;
var
Error : word;
lq : QWord;
begin
Val(s, D, Error);
TryStrToDWord:=Error=0
Val(s, lq, Error);
TryStrToDWord:=(Error=0) and (lq<=High(DWord));
if TryStrToDWord then
D:=lq;
end;
function StrToUInt(const s: string): Cardinal;

14
tests/webtbs/tw39406.pp Normal file
View File

@ -0,0 +1,14 @@
{$mode objfpc}
program fpbug;
uses
SysUtils;
var
Value: Cardinal;
Success: Boolean;
begin
Success := TryStrToDword('7795000000', Value);
if Success then
halt(1);
end.