Don't search for ':' port in ?# params part
Require to correctly parse http://...cgi?http://...
This commit is contained in:
parent
1f886000f4
commit
387b4eb4a3
@ -26,7 +26,7 @@
|
|||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: http.c,v 1.11 1997/08/05 20:18:38 ache Exp $
|
* $Id: http.c,v 1.12 1997/09/28 11:25:59 cracauer Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -125,22 +125,31 @@ static time_t parse_http_date(char *datestring);
|
|||||||
static void setup_http_auth(void);
|
static void setup_http_auth(void);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
http_parse(struct fetch_state *fs, const char *uri)
|
http_parse(struct fetch_state *fs, const char *u)
|
||||||
{
|
{
|
||||||
const char *p, *colon, *slash, *ques, *q;
|
const char *p, *colon, *slash, *q;
|
||||||
char *hostname, *hosthdr, *trimmed_name;
|
char *hostname, *hosthdr, *trimmed_name, *uri, *ques, saveq = 0;
|
||||||
unsigned port;
|
unsigned port;
|
||||||
struct http_state *https;
|
struct http_state *https;
|
||||||
|
|
||||||
|
uri = alloca(strlen(u) + 1);
|
||||||
|
strcpy(uri, u);
|
||||||
|
|
||||||
p = uri + 5;
|
p = uri + 5;
|
||||||
port = 0;
|
port = 0;
|
||||||
|
|
||||||
if (p[0] != '/' || p[1] != '/') {
|
if (p[0] != '/' || p[1] != '/') {
|
||||||
warnx("`%s': malformed `http' URL", uri);
|
warnx("`%s': malformed `http' URL", u);
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
|
if ((ques = strpbrk(p, "?#")) != NULL) {
|
||||||
|
saveq = *ques;
|
||||||
|
*ques = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
colon = strchr(p, ':');
|
colon = strchr(p, ':');
|
||||||
slash = strchr(p, '/');
|
slash = strchr(p, '/');
|
||||||
if (colon && slash && colon < slash)
|
if (colon && slash && colon < slash)
|
||||||
@ -148,7 +157,7 @@ http_parse(struct fetch_state *fs, const char *uri)
|
|||||||
else
|
else
|
||||||
q = slash;
|
q = slash;
|
||||||
if (q == 0) {
|
if (q == 0) {
|
||||||
warnx("`%s': malformed `http' URL", uri);
|
warnx("`%s': malformed `http' URL", u);
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
hostname = alloca(q - p + 1);
|
hostname = alloca(q - p + 1);
|
||||||
@ -164,7 +173,7 @@ http_parse(struct fetch_state *fs, const char *uri)
|
|||||||
ul = strtoul(colon + 1, &ep, 10);
|
ul = strtoul(colon + 1, &ep, 10);
|
||||||
if (ep != slash || ep == colon + 1 || errno != 0
|
if (ep != slash || ep == colon + 1 || errno != 0
|
||||||
|| ul < 1 || ul > 65534) {
|
|| ul < 1 || ul > 65534) {
|
||||||
warn("`%s': invalid port in URL", uri);
|
warn("`%s': invalid port in URL", u);
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +184,10 @@ http_parse(struct fetch_state *fs, const char *uri)
|
|||||||
|
|
||||||
p = slash;
|
p = slash;
|
||||||
|
|
||||||
|
/* parsing finished, restore parm part */
|
||||||
|
if (ques != NULL)
|
||||||
|
*ques = saveq;
|
||||||
|
|
||||||
https = safe_malloc(sizeof *https);
|
https = safe_malloc(sizeof *https);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -194,7 +207,6 @@ http_parse(struct fetch_state *fs, const char *uri)
|
|||||||
*/
|
*/
|
||||||
https->http_remote_request = safe_strdup(p);
|
https->http_remote_request = safe_strdup(p);
|
||||||
p++;
|
p++;
|
||||||
ques = strpbrk(p, "?#");
|
|
||||||
if (ques) {
|
if (ques) {
|
||||||
trimmed_name = safe_strndup(p, ques - p);
|
trimmed_name = safe_strndup(p, ques - p);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user