Fossil SCM
In http_exchange(), check a redirect target in a local URL before it replaces g.url. A refused redirect now leaves g.url unchanged, so a later pass of sync --all and the remote named by sync -v use the original URL, and the connection is closed by its own kind.
Commit
71f60497bb35b29ca66b248ce22aa0c57bdef0e18eaac5cf24824284327428ea
Parent
9b13c41f07e313b…
1 file changed
+7
-3
+7
-3
| --- src/http.c | ||
| +++ src/http.c | ||
| @@ -727,10 +727,11 @@ | ||
| 727 | 727 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 728 | 728 | int i, j; |
| 729 | 729 | int wasHttps; |
| 730 | 730 | int wasProxy; |
| 731 | 731 | int priorUrlFlags; |
| 732 | + UrlData target; | |
| 732 | 733 | |
| 733 | 734 | if ( --maxRedirect == 0){ |
| 734 | 735 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 735 | 736 | fossil_warning("redirect limit exceeded"); |
| 736 | 737 | } |
| @@ -757,24 +758,27 @@ | ||
| 757 | 758 | goto write_err; |
| 758 | 759 | } |
| 759 | 760 | wasHttps = g.url.isHttps; |
| 760 | 761 | wasProxy = g.url.useProxy; |
| 761 | 762 | priorUrlFlags = g.url.flags; |
| 762 | - url_parse(&zLine[i], 0); | |
| 763 | - if( wasHttps && !g.url.isHttps ){ | |
| 763 | + url_parse_local(&zLine[i], 0, &target); | |
| 764 | + if( wasHttps && !target.isHttps ){ | |
| 764 | 765 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 765 | 766 | fossil_warning("cannot redirect from HTTPS to HTTP"); |
| 766 | 767 | } |
| 768 | + url_unparse(&target); | |
| 767 | 769 | goto write_err; |
| 768 | 770 | } |
| 769 | - if( g.url.isSsh || g.url.isFile ){ | |
| 771 | + if( target.isSsh || target.isFile ){ | |
| 770 | 772 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 771 | 773 | fossil_warning("cannot redirect to %s", &zLine[i]); |
| 772 | 774 | } |
| 775 | + url_unparse(&target); | |
| 773 | 776 | goto write_err; |
| 774 | 777 | } |
| 775 | 778 | transport_close(&g.url); |
| 779 | + g.url = target; | |
| 776 | 780 | transport_global_shutdown(&g.url); |
| 777 | 781 | fSeenHttpAuth = 0; |
| 778 | 782 | if( g.zHttpAuth ) free(g.zHttpAuth); |
| 779 | 783 | g.zHttpAuth = get_httpauth(); |
| 780 | 784 | if( (rc==301 || rc==308) && (priorUrlFlags & URL_REMEMBER)!=0 ){ |
| 781 | 785 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -727,10 +727,11 @@ | |
| 727 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 728 | int i, j; |
| 729 | int wasHttps; |
| 730 | int wasProxy; |
| 731 | int priorUrlFlags; |
| 732 | |
| 733 | if ( --maxRedirect == 0){ |
| 734 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 735 | fossil_warning("redirect limit exceeded"); |
| 736 | } |
| @@ -757,24 +758,27 @@ | |
| 757 | goto write_err; |
| 758 | } |
| 759 | wasHttps = g.url.isHttps; |
| 760 | wasProxy = g.url.useProxy; |
| 761 | priorUrlFlags = g.url.flags; |
| 762 | url_parse(&zLine[i], 0); |
| 763 | if( wasHttps && !g.url.isHttps ){ |
| 764 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 765 | fossil_warning("cannot redirect from HTTPS to HTTP"); |
| 766 | } |
| 767 | goto write_err; |
| 768 | } |
| 769 | if( g.url.isSsh || g.url.isFile ){ |
| 770 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 771 | fossil_warning("cannot redirect to %s", &zLine[i]); |
| 772 | } |
| 773 | goto write_err; |
| 774 | } |
| 775 | transport_close(&g.url); |
| 776 | transport_global_shutdown(&g.url); |
| 777 | fSeenHttpAuth = 0; |
| 778 | if( g.zHttpAuth ) free(g.zHttpAuth); |
| 779 | g.zHttpAuth = get_httpauth(); |
| 780 | if( (rc==301 || rc==308) && (priorUrlFlags & URL_REMEMBER)!=0 ){ |
| 781 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -727,10 +727,11 @@ | |
| 727 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 728 | int i, j; |
| 729 | int wasHttps; |
| 730 | int wasProxy; |
| 731 | int priorUrlFlags; |
| 732 | UrlData target; |
| 733 | |
| 734 | if ( --maxRedirect == 0){ |
| 735 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 736 | fossil_warning("redirect limit exceeded"); |
| 737 | } |
| @@ -757,24 +758,27 @@ | |
| 758 | goto write_err; |
| 759 | } |
| 760 | wasHttps = g.url.isHttps; |
| 761 | wasProxy = g.url.useProxy; |
| 762 | priorUrlFlags = g.url.flags; |
| 763 | url_parse_local(&zLine[i], 0, &target); |
| 764 | if( wasHttps && !target.isHttps ){ |
| 765 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 766 | fossil_warning("cannot redirect from HTTPS to HTTP"); |
| 767 | } |
| 768 | url_unparse(&target); |
| 769 | goto write_err; |
| 770 | } |
| 771 | if( target.isSsh || target.isFile ){ |
| 772 | if( (mHttpFlags & HTTP_QUIET)==0 ){ |
| 773 | fossil_warning("cannot redirect to %s", &zLine[i]); |
| 774 | } |
| 775 | url_unparse(&target); |
| 776 | goto write_err; |
| 777 | } |
| 778 | transport_close(&g.url); |
| 779 | g.url = target; |
| 780 | transport_global_shutdown(&g.url); |
| 781 | fSeenHttpAuth = 0; |
| 782 | if( g.zHttpAuth ) free(g.zHttpAuth); |
| 783 | g.zHttpAuth = get_httpauth(); |
| 784 | if( (rc==301 || rc==308) && (priorUrlFlags & URL_REMEMBER)!=0 ){ |
| 785 |