marcsaeg    2003/06/04 07:25:51

  Modified:    src/share/org/apache/tomcat/util Tag: tomcat_32
                        CookieTools.java DateTool.java MimeHeaderField.java
  Log:
  Fixed a thread synchronization bug that appears in MimeHeaderField.parseDate().
  The SimpleDateFormats in DateTool where exposed as public members that parseDate()
  reference directly with no synchronization.  The SimpleDateFormat methods are
  not thread safe.
  
  Tomcat 3.2.x is no longer being officially maintained.  There will be no
  more official releases of Tomcat 3.2.x.  To get these fixes you will need
  to build Tomcat from source.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.3   +5 -9      
jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/CookieTools.java
  
  Index: CookieTools.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/CookieTools.java,v
  retrieving revision 1.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- CookieTools.java  10 Nov 2000 23:37:25 -0000      1.7.2.2
  +++ CookieTools.java  4 Jun 2003 14:25:50 -0000       1.7.2.3
  @@ -135,13 +135,9 @@
            if (version == 0) {
                buf.append (";Expires=");
                   if (cookie.getMaxAge() == 0)
  -                    DateTool.oldCookieFormat.format(new Date(10000), buf,
  -                                                    new FieldPosition(0));
  +                    DateTool.formatOldCookie(new Date(10000), buf);
                   else
  -                    DateTool.oldCookieFormat.format
  -                        (new Date( System.currentTimeMillis() +
  -                                   cookie.getMaxAge() *1000L), buf,
  -                         new FieldPosition(0));
  +                    DateTool.formatOldCookie(new Date( System.currentTimeMillis() + 
cookie.getMaxAge() *1000L), buf);
            } else {
                buf.append (";Max-Age=");
                buf.append (cookie.getMaxAge());
  
  
  
  1.2.2.2   +46 -17    
jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/DateTool.java
  
  Index: DateTool.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/DateTool.java,v
  retrieving revision 1.2.2.1
  retrieving revision 1.2.2.2
  diff -u -r1.2.2.1 -r1.2.2.2
  --- DateTool.java     30 Jul 2001 00:57:34 -0000      1.2.2.1
  +++ DateTool.java     4 Jun 2003 14:25:50 -0000       1.2.2.2
  @@ -110,38 +110,67 @@
   
       /** DateFormat to be used to format dates
        */
  -    public final static SimpleDateFormat rfc1123Format =
  -     new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
  +    private final static SimpleDateFormat rfc1123Format = new 
SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
       
       /** DateFormat to be used to format old netscape cookies
        */
  -    public final static SimpleDateFormat oldCookieFormat =
  -     new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
  +    private final static SimpleDateFormat oldCookieFormat = new 
SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
       
  -    public final static SimpleDateFormat rfc1036Format =
  -     new SimpleDateFormat(rfc1036Pattern, LOCALE_US);
  +    private final static SimpleDateFormat rfc1036Format = new 
SimpleDateFormat(rfc1036Pattern, LOCALE_US);
       
  -    public final static SimpleDateFormat asctimeFormat =
  -     new SimpleDateFormat(asctimePattern, LOCALE_US);
  +    private final static SimpleDateFormat asctimeFormat = new 
SimpleDateFormat(asctimePattern, LOCALE_US);
       
       static {
  -     rfc1123Format.setTimeZone(GMT_ZONE);
  -     oldCookieFormat.setTimeZone(GMT_ZONE);
  -     rfc1036Format.setTimeZone(GMT_ZONE);
  -     asctimeFormat.setTimeZone(GMT_ZONE);
  +        rfc1123Format.setTimeZone(GMT_ZONE);
  +        oldCookieFormat.setTimeZone(GMT_ZONE);
  +        rfc1036Format.setTimeZone(GMT_ZONE);
  +        asctimeFormat.setTimeZone(GMT_ZONE);
       }
       
       private static String rfc1123DS;
       private static long   rfc1123Sec;
   
  +
  +    public static Date rfc1123Parse(String dateString) throws ParseException
  +    {
  +        synchronized(rfc1123Format){
  +            return rfc1123Format.parse(dateString);
  +        }
  +    }
  +
  +    public static Date rfc1036Parse(String dateString) throws ParseException
  +    {
  +        synchronized(rfc1036Format){
  +            return rfc1036Format.parse(dateString);
  +        }
  +    }
  +
  +    public static Date asctimeParse(String dateString) throws ParseException
  +    {
  +        synchronized(asctimeFormat){
  +            return asctimeFormat.parse(dateString);
  +        }
  +    }
  +
  +    public static void formatOldCookie(Date d, StringBuffer buf)
  +    {
  +        synchronized(oldCookieFormat){
  +            oldCookieFormat.format(d, buf, new FieldPosition(0));
  +        }
  +    }
  +
       /**
        */
  -    public static String format1123( Date d ) {
  +    public static String format1123( Date d )
  +    {
           long dt = d.getTime() % 1000;
           if ((rfc1123DS != null) && (dt == rfc1123Sec))
                   return rfc1123DS;
   
  -        rfc1123DS  = rfc1123Format.format( d );
  +        synchronized(rfc1123Format){
  +            rfc1123DS  = rfc1123Format.format( d );
  +        }
  +
           rfc1123Sec = dt;
           return rfc1123DS;
       }
  
  
  
  1.10.2.4  +22 -19    
jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/MimeHeaderField.java
  
  Index: MimeHeaderField.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/MimeHeaderField.java,v
  retrieving revision 1.10.2.3
  retrieving revision 1.10.2.4
  diff -u -r1.10.2.3 -r1.10.2.4
  --- MimeHeaderField.java      30 Jul 2001 00:57:34 -0000      1.10.2.3
  +++ MimeHeaderField.java      4 Jun 2003 14:25:50 -0000       1.10.2.4
  @@ -336,26 +336,29 @@
        return parseDate( value );
       }
   
  -    long parseDate( MessageString value ) {
  -     String dateString=value.toString();
  -     Date date=null;
  +    long parseDate( MessageString value )
  +    {
  +        String dateString=value.toString();
  +        Date date=null;
           try {
  -            date = DateTool.rfc1123Format.parse(dateString);
  -         return date.getTime();
  -     } catch (ParseException e) { }
  -
  +            date = DateTool.rfc1123Parse(dateString);
  +            return date.getTime();
  +        } catch (ParseException e){
  +        }
           try {
  -         date = DateTool.rfc1036Format.parse(dateString);
  -         return date.getTime();
  -     } catch (ParseException e) { }
  -     
  +            date = DateTool.rfc1036Parse(dateString);
  +            return date.getTime();
  +        } catch (ParseException e)
  +        {
  +        }
           try {
  -            date = DateTool.asctimeFormat.parse(dateString);
  -         return date.getTime();
  -        } catch (ParseException pe) {
  +            date = DateTool.asctimeParse(dateString);
  +            return date.getTime();
  +        } catch (ParseException pe){
           }
  -     String msg = sm.getString("httpDate.pe", dateString);
  -     throw new IllegalArgumentException(msg);
  +
  +        String msg = sm.getString("httpDate.pe", dateString);
  +        throw new IllegalArgumentException(msg);
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to