summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorMatt Kraai2001-01-03 16:15:15 +0000
committerMatt Kraai2001-01-03 16:15:15 +0000
commita9711a59695d0c0591e8786a2ea811940ef8735a (patch)
treed18c561b9ab63ff7c458cbeb10a9bcaeffc45567 /networking
parent59c09d06e34df81f55e463fc61e69d5081eb5161 (diff)
downloadbusybox-a9711a59695d0c0591e8786a2ea811940ef8735a.zip
busybox-a9711a59695d0c0591e8786a2ea811940ef8735a.tar.gz
Prevent / doubling and shrink parse_url.
Diffstat (limited to 'networking')
-rw-r--r--networking/wget.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/networking/wget.c b/networking/wget.c
index dbc2836..77577d9 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -241,31 +241,28 @@ int wget_main(int argc, char **argv)
void parse_url(char *url, char **uri_host, int *uri_port, char **uri_path)
{
- char *s, *h;
- static char *defaultpath = "/";
+ char *cp, *sp;
*uri_port = 80;
if (strncmp(url, "http://", 7) != 0)
error_msg_and_die("not an http url: %s\n", url);
- /* pull the host portion to the front of the buffer */
- for (s = url, h = url+7 ; *h != '/' && *h != 0; ++h) {
- if (*h == ':') {
- *uri_port = atoi(h+1);
- *h = '\0';
- }
- *s++ = *h;
- }
- *s = '\0';
+ *uri_host = url + 7;
- if (*h == 0) h = defaultpath;
+ cp = strchr(*uri_host, ':');
+ sp = strchr(*uri_host, '/');
- *uri_host = url;
- *uri_path = h;
+ if (cp != NULL && (sp == NULL || cp < sp)) {
+ *cp++ = '\0';
+ *uri_port = atoi(cp);
+ }
- if (!strcmp( *uri_host, *uri_path))
- *uri_path = defaultpath;
+ if (sp != NULL) {
+ *sp++ = '\0';
+ *uri_path = sp;
+ } else
+ *uri_path = "";
}
@@ -514,7 +511,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.14 2000/12/18 03:08:29 kraai Exp $
+ * $Id: wget.c,v 1.15 2001/01/03 16:15:15 kraai Exp $
*/