ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Get.java
Date Fri, 06 May 2005 18:36:10 GMT
mbenson     2005/05/06 11:36:10

  Modified:    src/main/org/apache/tools/ant/taskdefs Get.java
  Log:
  Base64 conversion of userid:password was (always) broken.  The length of
  the result was calculated correctly, but was translating two bytes to four instead of three.
 This would obviously cause buffer overruns.
  PR: 34734
  
  Revision  Changes    Path
  1.51      +16 -13    ant/src/main/org/apache/tools/ant/taskdefs/Get.java
  
  Index: Get.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Get.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- Get.java	4 May 2005 17:00:01 -0000	1.50
  +++ Get.java	6 May 2005 18:36:10 -0000	1.51
  @@ -363,48 +363,51 @@
               int bits24;
               int bits6;
   
  -            StringBuffer buf = new StringBuffer();
  +            char[] out = new char[((octetString.length - 1) / 3 + 1) * 4];
  +            int outIndex = 0;
               int i = 0;
   
               while ((i + 3) <= octetString.length) {
                   // store the octets
                   bits24 = (octetString[i++] & 0xFF) << 16;
                   bits24 |= (octetString[i++] & 0xFF) << 8;
  +                bits24 |= octetString[i++];
   
                   bits6 = (bits24 & 0x00FC0000) >> 18;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
                   bits6 = (bits24 & 0x0003F000) >> 12;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
                   bits6  = (bits24 & 0x00000FC0) >> 6;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
                   bits6 = (bits24 & 0x0000003F);
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
               }
               if (octetString.length - i == 2) {
                   // store the octets
                   bits24 = (octetString[i] & 0xFF) << 16;
                   bits24 |= (octetString[i + 1] & 0xFF) << 8;
                   bits6 = (bits24 & 0x00FC0000) >> 18;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
                   bits6 = (bits24 & 0x0003F000) >> 12;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
                   bits6 = (bits24 & 0x00000FC0) >> 6;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
   
                   // padding
  -                buf.append('=');
  +                out[outIndex++] = '=';
               } else if (octetString.length - i == 1) {
                   // store the octets
                   bits24 = (octetString[i] & 0xFF) << 16;
                   bits6 = (bits24 & 0x00FC0000) >> 18;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
                   bits6 = (bits24 & 0x0003F000) >> 12;
  -                buf.append(alphabet[bits6]);
  +                out[outIndex++] = alphabet[bits6];
   
                   // padding
  -                buf.append("==");
  +                out[outIndex++] = '=';
  +                out[outIndex++] = '=';
               }
  -            return buf.toString();
  +            return new String(out);
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message