webfs: fix cookie path bug, more memory leaks

front
cinap_lenrek 2011-11-16 21:20:13 +01:00
parent ceae4e464d
commit 9e9d694fbd
3 changed files with 32 additions and 23 deletions

View File

@ -209,7 +209,7 @@ copycookie(Cookie *c)
for(i=0; i<nelem(stab); i++){ for(i=0; i<nelem(stab); i++){
ps = (char**)((uintptr)c+stab[i].offset); ps = (char**)((uintptr)c+stab[i].offset);
if(*ps) if(*ps)
*ps = estrdup9p(*ps); *ps = estrdup(*ps);
} }
} }
@ -323,7 +323,7 @@ newjar(void)
{ {
Jar *jar; Jar *jar;
jar = emalloc9p(sizeof(Jar)); jar = emalloc(sizeof(Jar));
return jar; return jar;
} }
@ -466,7 +466,7 @@ readjar(char *file)
Jar *jar; Jar *jar;
jar = newjar(); jar = newjar();
lock = emalloc9p(strlen(file)+10); lock = emalloc(strlen(file)+10);
strcpy(lock, file); strcpy(lock, file);
if((p = strrchr(lock, '/')) != nil) if((p = strrchr(lock, '/')) != nil)
p++; p++;
@ -496,6 +496,7 @@ closejar(Jar *jar)
if(jar == nil) if(jar == nil)
return; return;
expirejar(jar, 0); expirejar(jar, 0);
if(syncjar(jar) < 0) if(syncjar(jar) < 0)
fprint(2, "warning: cannot rewrite cookie jar: %r\n"); fprint(2, "warning: cannot rewrite cookie jar: %r\n");
@ -503,6 +504,7 @@ closejar(Jar *jar)
freecookie(&jar->c[i]); freecookie(&jar->c[i]);
free(jar->file); free(jar->file);
free(jar->c);
free(jar); free(jar);
} }
@ -580,14 +582,14 @@ cookiesearch(Jar *jar, char *dom, char *path, int issecure)
now = time(0); now = time(0);
j = newjar(); j = newjar();
for(i=0; i<jar->nc; i++){ for(i=0; i<jar->nc; i++){
if(cookiedebug)
fprint(2, "\ttry %s %s %d %s\n", jar->c[i].dom,
jar->c[i].path, jar->c[i].secure,
jar->c[i].name);
if((issecure || !jar->c[i].secure) && if((issecure || !jar->c[i].secure) &&
iscookiematch(&jar->c[i], dom, path, now)){ iscookiematch(&jar->c[i], dom, path, now)){
if(cookiedebug) if(cookiedebug){
fprint(2, "\t%s %s %d %s\n", jar->c[i].dom,
jar->c[i].path, jar->c[i].secure,
jar->c[i].name);
fprint(2, "\tmatched\n"); fprint(2, "\tmatched\n");
}
addcookie(j, &jar->c[i]); addcookie(j, &jar->c[i]);
} }
} }
@ -810,7 +812,7 @@ isnetscape(char *hdr)
/* /*
* Parse HTTP response headers, adding cookies to jar. * Parse HTTP response headers, adding cookies to jar.
* Overwrites the headers. May overwrite path. * Overwrites the headers.
*/ */
static char* parsecookie(Cookie*, char*, char**, int, char*, char*); static char* parsecookie(Cookie*, char*, char**, int, char*, char*);
static int static int
@ -843,13 +845,14 @@ parsehttp(Jar *jar, char *hdr, char *dom, char *path)
} }
if((e = isbadcookie(&c, dom, path)) != nil){ if((e = isbadcookie(&c, dom, path)) != nil){
if(cookiedebug) if(cookiedebug)
fprint(2, "reject cookie; %s\n", e); fprint(2, "reject cookie: %s\n", e);
continue; continue;
} }
addcookie(jar, &c); addcookie(jar, &c);
n++; n++;
} }
} }
return n; return n;
} }
@ -997,6 +1000,7 @@ parsecookie(Cookie *c, char *p, char **e, int isns, char *dom, char *path)
if(cistrcmp(attr, "secure") == 0) if(cistrcmp(attr, "secure") == 0)
c->secure = 1; c->secure = 1;
} }
*e = p;
if(c->dom) if(c->dom)
c->explicitdom = 1; c->explicitdom = 1;
@ -1004,15 +1008,9 @@ parsecookie(Cookie *c, char *p, char **e, int isns, char *dom, char *path)
c->dom = dom; c->dom = dom;
if(c->path) if(c->path)
c->explicitpath = 1; c->explicitpath = 1;
else{ else
c->path = path; c->path = path;
if((t = strchr(c->path, '?')) != 0)
*t = '\0';
if((t = strrchr(c->path, '/')) != 0)
*t = '\0';
}
c->netscapestyle = isns; c->netscapestyle = isns;
*e = p;
return nil; return nil;
} }
@ -1042,14 +1040,14 @@ cookieopen(Req *r)
Aux *a; Aux *a;
syncjar(jar); syncjar(jar);
a = emalloc9p(sizeof(Aux)); a = emalloc(sizeof(Aux));
r->fid->aux = a; r->fid->aux = a;
if(r->ifcall.mode&OTRUNC){ if(r->ifcall.mode&OTRUNC){
a->ctext = emalloc9p(1); a->ctext = emalloc(1);
a->ctext[0] = '\0'; a->ctext[0] = '\0';
}else{ }else{
sz = 256*jar->nc+1024; /* BUG should do better */ sz = 256*jar->nc+1024; /* BUG should do better */
a->ctext = emalloc9p(sz); a->ctext = emalloc(sz);
a->ctext[0] = '\0'; a->ctext[0] = '\0';
s = a->ctext; s = a->ctext;
es = s+sz; es = s+sz;
@ -1139,9 +1137,10 @@ initcookies(char *file)
home = getenv("home"); home = getenv("home");
if(home == nil) if(home == nil)
sysfatal("no cookie file specified and no $home"); sysfatal("no cookie file specified and no $home");
file = emalloc9p(strlen(home)+30); file = emalloc(strlen(home)+30);
strcpy(file, home); strcpy(file, home);
strcat(file, "/lib/webcookies"); strcat(file, "/lib/webcookies");
free(home);
} }
jar = readjar(file); jar = readjar(file);
if(jar == nil) if(jar == nil)
@ -1151,11 +1150,17 @@ initcookies(char *file)
void void
httpsetcookie(char *hdr, char *dom, char *path) httpsetcookie(char *hdr, char *dom, char *path)
{ {
if(path == nil) char *t;
path = "/";
path = estrdup(path && path[0] ? path : "/");
if((t = strchr(path, '?')) != 0)
*t = '\0';
t = strrchr(path, '/');
if(t && t != path)
*t = '\0';
parsehttp(jar, hdr, dom, path); parsehttp(jar, hdr, dom, path);
syncjar(jar); syncjar(jar);
free(path);
} }
char* char*

View File

@ -73,6 +73,8 @@ _iotlsdial(va_list *arg)
/* BUG: check cert here? */ /* BUG: check cert here? */
if(conn.cert) if(conn.cert)
free(conn.cert); free(conn.cert);
if(conn.sessionID)
free(conn.sessionID);
} }
return tfd; return tfd;
} }

View File

@ -886,6 +886,7 @@ freeurl(Url *u)
free(u->fragment); free(u->fragment);
switch(u->ischeme){ switch(u->ischeme){
case UShttp: case UShttp:
case UShttps:
free(u->http.page_spec); free(u->http.page_spec);
break; break;
case USftp: case USftp:
@ -960,6 +961,7 @@ copyurl(Url *u)
switch(v->ischeme){ switch(v->ischeme){
case UShttp: case UShttp:
case UShttps:
dupp(&v->http.page_spec); dupp(&v->http.page_spec);
break; break;
case USftp: case USftp: