From 79c6fc9d53e925de06072a9ee0abe794955fb52e Mon Sep 17 00:00:00 2001
From: beware <beware@bircd.org>
Date: Fri, 28 Mar 2014 04:25:51 +0000
Subject: [PATCH 1/1] check upper bound limit on FD set operations

git-svn-id: file:///svnroot/lcore/trunk@137 b1de8a11-f9be-4011-bde0-cc7ace90066a
---
 fd_utils.pas | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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;
-- 
2.30.2