From ccff1bc205722a94e386c3cfe44852ab55430886 Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Wed, 31 Dec 2008 13:55:37 +0000
Subject: [PATCH] - [Issue 3694]  ASN.1 package does incorrect BER encoding/decoding for negative integers.

---
 opends/src/server/org/opends/server/protocols/asn1/ASN1Integer.java |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/protocols/asn1/ASN1Integer.java b/opends/src/server/org/opends/server/protocols/asn1/ASN1Integer.java
index 02d6392..43c3f60 100644
--- a/opends/src/server/org/opends/server/protocols/asn1/ASN1Integer.java
+++ b/opends/src/server/org/opends/server/protocols/asn1/ASN1Integer.java
@@ -146,6 +146,7 @@
    * @throws  ASN1Exception  If the provided array is null or is not between one
    *                         and four bytes in length.
    */
+  @Override
   public void setValue(byte[] value)
          throws ASN1Exception
   {
@@ -201,6 +202,12 @@
     }
 
     int intValue = 0;
+
+    if (value[0] < 0)
+    {
+      intValue = 0xFFFFFFFF;
+    }
+
     for (byte b : value)
     {
       intValue = (intValue << 8) | (b & 0xFF);
@@ -293,6 +300,12 @@
     System.arraycopy(encodedElement, valueStartPos, value, 0, length);
 
     int intValue = 0;
+
+    if (value[0] < 0)
+    {
+      intValue = 0xFFFFFFFF;
+    }
+
     for (byte b : value)
     {
       intValue = (intValue << 8) | (b & 0xFF);
@@ -309,6 +322,7 @@
    *
    * @param  buffer  The buffer to which the information should be appended.
    */
+  @Override
   public void toString(StringBuilder buffer)
   {
     buffer.append("ASN1Integer(type=");
@@ -329,6 +343,7 @@
    * @param  indent  The number of spaces that should be used to indent the
    *                 resulting string representation.
    */
+  @Override
   public void toString(StringBuilder buffer, int indent)
   {
     StringBuilder indentBuf = new StringBuilder(indent);

--
Gitblit v1.10.0