directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r944941 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControl.java
Date Sun, 16 May 2010 23:50:47 GMT
Author: elecharny
Date: Sun May 16 23:50:47 2010
New Revision: 944941

URL: http://svn.apache.org/viewvc?rev=944941&view=rev
Log:
Fixed the way was computed the cookie, if the value is shorter than 4 bytes, to avoid an AIOOBE.

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControl.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControl.java?rev=944941&r1=944940&r2=944941&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsControl.java
Sun May 16 23:50:47 2010
@@ -85,6 +85,7 @@ public class PagedResultsControl extends
     {
         super( CONTROL_OID );
         
+        cookie = StringTools.EMPTY_BYTES;
         decoder = new PagedResultsControlDecoder();
     }
 
@@ -233,7 +234,27 @@ public class PagedResultsControl extends
      */
     public int getCookieValue()
     {
-        int value = ((cookie[0]&0x00FF)<<24) + ((cookie[1]&0x00FF)<<16)
+ ((cookie[2]&0x00FF)<<8) + (cookie[3]&0x00FF);
+        int value = 0;
+        
+        switch ( cookie.length )
+        {
+            case 1 :
+                value = cookie[0]&0x00FF;
+                break;
+                
+            case 2 :
+                value = ((cookie[0]&0x00FF)<<8) + (cookie[1]&0x00FF);
+                break;
+                
+            case 3 :
+                value = ((cookie[0]&0x00FF)<<16) + ((cookie[1]&0x00FF)<<8)
+ (cookie[2]&0x00FF);
+                break;
+                
+            case 4 :
+                value = ((cookie[0]&0x00FF)<<24) + ((cookie[1]&0x00FF)<<16)
+ ((cookie[2]&0x00FF)<<8) + (cookie[3]&0x00FF);
+                break;
+                
+        }
         
         return value;
     }



Mime
View raw message