Browse Source

fix some range check errors

Ugochukwu Mmaduekwe 6 years ago
parent
commit
fee8c7d847

+ 7 - 3
CryptoLib/src/Crypto/ClpIESCipher.pas

@@ -103,9 +103,13 @@ implementation
 
 function TIESCipher.Aggregate: TCryptoLibByteArray;
 begin
-  FBuffer.Position := 0;
-  System.SetLength(Result, FBuffer.Size);
-  FBuffer.Read(Result[0], FBuffer.Size);
+  Result := Nil;
+  if FBuffer.Size > 0 then
+  begin
+    FBuffer.Position := 0;
+    System.SetLength(Result, FBuffer.Size);
+    FBuffer.Read(Result[0], FBuffer.Size);
+  end;
 end;
 
 constructor TIESCipher.Create(const Engine: IIESEngine; ivLength: Int32);

+ 11 - 4
CryptoLib/src/Crypto/Signers/ClpEd25519Blake2BSigner.pas

@@ -78,15 +78,22 @@ implementation
 
 function TEd25519Blake2BSigner.Aggregate: TCryptoLibByteArray;
 begin
-  FBuffer.Position := 0;
-  System.SetLength(Result, FBuffer.Size);
-  FBuffer.Read(Result[0], FBuffer.Size);
+  Result := Nil;
+  if FBuffer.Size > 0 then
+  begin
+    FBuffer.Position := 0;
+    System.SetLength(Result, FBuffer.Size);
+    FBuffer.Read(Result[0], FBuffer.Size);
+  end;
 end;
 
 procedure TEd25519Blake2BSigner.BlockUpdate(const buf: TCryptoLibByteArray;
   off, len: Int32);
 begin
-  FBuffer.Write(buf[off], len);
+  if buf <> Nil then
+  begin
+    FBuffer.Write(buf[off], len);
+  end;
 end;
 
 constructor TEd25519Blake2BSigner.Create;

+ 11 - 4
CryptoLib/src/Crypto/Signers/ClpEd25519CtxBlake2BSigner.pas

@@ -79,15 +79,22 @@ implementation
 
 function TEd25519CtxBlake2BSigner.Aggregate: TCryptoLibByteArray;
 begin
-  FBuffer.Position := 0;
-  System.SetLength(Result, FBuffer.Size);
-  FBuffer.Read(Result[0], FBuffer.Size);
+  Result := Nil;
+  if FBuffer.Size > 0 then
+  begin
+    FBuffer.Position := 0;
+    System.SetLength(Result, FBuffer.Size);
+    FBuffer.Read(Result[0], FBuffer.Size);
+  end;
 end;
 
 procedure TEd25519CtxBlake2BSigner.BlockUpdate(const buf: TCryptoLibByteArray;
   off, len: Int32);
 begin
-  FBuffer.Write(buf[off], len);
+  if buf <> Nil then
+  begin
+    FBuffer.Write(buf[off], len);
+  end;
 end;
 
 constructor TEd25519CtxBlake2BSigner.Create(const context: TCryptoLibByteArray);

+ 11 - 4
CryptoLib/src/Crypto/Signers/ClpEd25519CtxSigner.pas

@@ -79,15 +79,22 @@ implementation
 
 function TEd25519CtxSigner.Aggregate: TCryptoLibByteArray;
 begin
-  FBuffer.Position := 0;
-  System.SetLength(Result, FBuffer.Size);
-  FBuffer.Read(Result[0], FBuffer.Size);
+  Result := Nil;
+  if FBuffer.Size > 0 then
+  begin
+    FBuffer.Position := 0;
+    System.SetLength(Result, FBuffer.Size);
+    FBuffer.Read(Result[0], FBuffer.Size);
+  end;
 end;
 
 procedure TEd25519CtxSigner.BlockUpdate(const buf: TCryptoLibByteArray;
   off, len: Int32);
 begin
-  FBuffer.Write(buf[off], len);
+  if buf <> Nil then
+  begin
+    FBuffer.Write(buf[off], len);
+  end;
 end;
 
 constructor TEd25519CtxSigner.Create(const context: TCryptoLibByteArray);

+ 11 - 4
CryptoLib/src/Crypto/Signers/ClpEd25519Signer.pas

@@ -78,15 +78,22 @@ implementation
 
 function TEd25519Signer.Aggregate: TCryptoLibByteArray;
 begin
-  FBuffer.Position := 0;
-  System.SetLength(Result, FBuffer.Size);
-  FBuffer.Read(Result[0], FBuffer.Size);
+  Result := Nil;
+  if FBuffer.Size > 0 then
+  begin
+    FBuffer.Position := 0;
+    System.SetLength(Result, FBuffer.Size);
+    FBuffer.Read(Result[0], FBuffer.Size);
+  end;
 end;
 
 procedure TEd25519Signer.BlockUpdate(const buf: TCryptoLibByteArray;
   off, len: Int32);
 begin
-  FBuffer.Write(buf[off], len);
+  if buf <> Nil then
+  begin
+    FBuffer.Write(buf[off], len);
+  end;
 end;
 
 constructor TEd25519Signer.Create;

+ 11 - 4
CryptoLib/src/Crypto/Signers/ClpSchnorrDigestSigner.pas

@@ -112,15 +112,22 @@ implementation
 
 function TSchnorrDigestSigner.Aggregate: TCryptoLibByteArray;
 begin
-  FBuffer.Position := 0;
-  System.SetLength(Result, FBuffer.Size);
-  FBuffer.Read(Result[0], FBuffer.Size);
+  Result := Nil;
+  if FBuffer.Size > 0 then
+  begin
+    FBuffer.Position := 0;
+    System.SetLength(Result, FBuffer.Size);
+    FBuffer.Read(Result[0], FBuffer.Size);
+  end;
 end;
 
 procedure TSchnorrDigestSigner.BlockUpdate(const input: TCryptoLibByteArray;
   inOff, length: Int32);
 begin
-  FBuffer.Write(input[inOff], length);
+  if input <> Nil then
+  begin
+    FBuffer.Write(input[inOff], length);
+  end;
 end;
 
 // constructor TSchnorrDigestSigner.Create(const Schnorr: ISchnorr;