Bug 13972 - gcj's URL() does not handle ContextURL + "/redir?http://domain2.com/index.html" correctly.
Summary: gcj's URL() does not handle ContextURL + "/redir?http://domain2.com/index.htm...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: patch
Depends on:
Blocks: 16229
  Show dependency treegraph
 
Reported: 2004-02-02 01:22 UTC by Ken Allan
Modified: 2005-01-11 20:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-01-05 01:48:26


Attachments
Patch against gcc/libjava/java/net/URL.java (432 bytes, patch)
2004-02-02 01:25 UTC, Ken Allan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ken Allan 2004-02-02 01:22:12 UTC
Hi,

I noticed that the URL function in libgcj's java.net.URL does not properly
process requests like:
  URL("http://domain.com", "/redir?http://domain2.com/index.html");

This is because at the start of the function, context is set to null if spec
contains a :// anywhere, but even in the comment at the top of that function it
is mentioned that:
    /* A protocol is defined by the doc as the substring before a ':'
     * as long as the ':' occurs before any '/'.
 
Hence I submit the following diff against CVS:

--- URL.java    31 Dec 2003 10:55:40 -0000      1.34
+++ URL.java    2 Feb 2004 01:18:04 -0000
@@ -379,12 +379,12 @@
     // An absolute URL must have chars prior to "://" but cannot have a colon
     // right after the "://".  The second colon is for an optional port value
     // and implies that the host from the context is used if available.
-    int colon;
+    int colon, slash;
     if ((colon = spec.indexOf("://", 1)) > 0 &&
+       ((colon < (slash = spec.indexOf('/')) || slash < 0)) &&
        ! spec.regionMatches(colon, "://:", 0, 4))
       context = null;
  
-    int slash;
     if ((colon = spec.indexOf(':')) > 0 &&
        (colon < (slash = spec.indexOf('/')) || slash < 0))
       {


My gcc version information:
  Configured with: ../gcc/configure --enable-threads=posix --prefix=/opt/gcc
--enable-shared --enable-languages=c++,java
  Thread model: posix
  gcc version 3.5.0 20040121 (experimental)
Comment 1 Ken Allan 2004-02-02 01:25:32 UTC
Created attachment 5641 [details]
Patch against gcc/libjava/java/net/URL.java

This patch will rectify the problem mentioned in the bug report... it's
probably not as efficient as it could be.
Comment 2 Andrew Pinski 2004-02-02 04:27:52 UTC
Confirmed, gcj patches should be sent to gcc-patches and java-patches.
Comment 3 GCC Commits 2005-01-11 20:40:17 UTC
Subject: Bug 13972

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mkoch@gcc.gnu.org	2005-01-11 20:40:11

Modified files:
	libjava        : ChangeLog 
	libjava/java/net: URL.java 

Log message:
	2005-01-11  Michael Koch  <konqueror@gmx.de>
	
	PR libgcj/13972
	* java/net/URL.java (URL): Handle specs like
	"/redir?http://domain2.com/index.html" which start with a slash.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3284&r2=1.3285
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/net/URL.java.diff?cvsroot=gcc&r1=1.44&r2=1.45

Comment 4 Andrew Pinski 2005-01-11 20:43:05 UTC
Fixed on the mainline for 4.0.0.