hola,

I think I fixed some of the bugs in the cookie's code, I'm not sure
my changes are fixes or hacks, that's why this is not patch.
I'd really like someone to review them and submit the appropriate
patch. thanks.



found a bug in my changes, good that I didn't submit it as a patch :)
here is the corrected one:

g% diff -c /n/sources/plan9/sys/src/cmd/webfs /sys/src/cmd/webfs
diff -c /n/sources/plan9/sys/src/cmd/webfs/cookies.c
/sys/src/cmd/webfs/cookies.c
/n/sources/plan9/sys/src/cmd/webfs/cookies.c:533,545 -
/sys/src/cmd/webfs/cookies.c:533,548
 {
        int lname, lpattern;

-       if(cistrcmp(name, pattern)==0)
+        if(pattern[0] != '.')
+               return 0;
+
+       if(cistrcmp(name, pattern+1) == 0)
                return 1;

        if(strcmp(ipattr(name), "dom")==0 && pattern[0]=='.'){
                lname = strlen(name);
                lpattern = strlen(pattern);
-               if(lname >= lpattern && cistrcmp(name+lname-lpattern, 
pattern)==0)
+               if(lname>=lpattern && cistrcmp(name+lname-lpattern, pattern)==0)
                        return 1;
        }

/n/sources/plan9/sys/src/cmd/webfs/cookies.c:557,563 -
/sys/src/cmd/webfs/cookies.c:560,566
 {
        return isdomainmatch(dom, c->dom)
                && strncmp(c->path, path, strlen(c->path))==0
-               && c->expire >= now;
+               && (c->expire==0 || c->expire>=now);
 }

 /*
/n/sources/plan9/sys/src/cmd/webfs/cookies.c:578,584 -
/sys/src/cmd/webfs/cookies.c:581,587
        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) && iscookiematch(&jar->c[i],
dom, path, now)){
+               if(/*(issecure || !jar->c[i].secure) &&*/
iscookiematch(&jar->c[i], dom, path, now)){
                        if(cookiedebug)
                                fprint(2, "\tmatched\n");
                        addcookie(j, &jar->c[i]);
/n/sources/plan9/sys/src/cmd/webfs/cookies.c:612,618 -
/sys/src/cmd/webfs/cookies.c:615,622
                return "request host does not match cookie domain";

        if(strcmp(ipattr(dom), "dom")==0
-       && memchr(dom, '.', strlen(dom)-strlen(c->dom)) != nil)
+       && strlen(c->dom)-strlen(dom) > 0
+       && memchr(dom, '.', strlen(c->dom)-strlen(dom)) != nil)
                return "request host contains dots before cookie domain";

        return 0;
--
Federico G. Benavento

Reply via email to