From: beware Date: Fri, 28 Mar 2014 04:25:51 +0000 (+0000) Subject: check upper bound limit on FD set operations X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/79c6fc9d53e925de06072a9ee0abe794955fb52e check upper bound limit on FD set operations git-svn-id: file:///svnroot/lcore/trunk@137 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/fd_utils.pas b/fd_utils.pas index 290eb05..86b6d3a 100644 --- a/fd_utils.pas +++ b/fd_utils.pas @@ -48,7 +48,7 @@ uses sysutils; Procedure FD_Clr(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif} { Remove fd from the set of filedescriptors} begin - if (fd < 0) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd)); + if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd)); fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] and (not (1 shl (fd and fdwordmaxbit))); end; @@ -61,14 +61,14 @@ end; Procedure FD_Set(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif} { Add fd to the set of filedescriptors } begin - if (fd < 0) then raise exception.create('FD_set fd out of range: '+inttostr(fd)); + if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then raise exception.create('FD_set fd out of range: '+inttostr(fd)); fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] or (1 shl (fd and fdwordmaxbit)); end; Function FD_IsSet(fd:longint;var fds:fdSet):boolean;{$ifdef useinline}inline;{$endif} { Test if fd is part of the set of filedescriptors } begin - if (fd < 0) then begin + if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then begin result := false; exit; end;