On Thu, Oct 1, 2009 at 11:22, erik quanstrom <[email protected]> wrote:
>> Every time I do so, either with touch or  chmod for example, I get
>> errors like this:
>>
>> Oct  1 08:52:39.288 read bad packet from 5
>
> add some debugging to 9pserve.c around 'read bad packet'.
> i'm gonna guess (since i don't have time to get p9p auth
> working) that this test has failed src/lib9/convM2S.c:216,217
>
> - erik

I instrumented the code as you suggested.

/usr/local/plan9/src/cmd/9pserve.c:
Msg*
mread9p(Ioproc *io, int fd, int dotu)
{
        int n, nn;
        uchar *pkt;
        Msg *m;

        if((pkt = read9ppkt(io, fd)) == nil)
                return nil;

        m = msgnew(0);
        m->tpkt = pkt;
        n = GBIT32(pkt);
        nn = convM2Su(pkt, n, &m->tx, dotu);
        if(nn != n){
                fprint(2, "%T read bad packet from %d\n", fd);
                fprint(2, "n=%d nn=%d\n", n, nn);
                return nil;
        }
        return m;
}

/usr/local/plan9/src/lib9/convM2S.c:
uint
convM2Su(uchar *ap, uint nap, Fcall *f, int dotu)
{
/* snip */
        case Twstat:
                if(p+BIT32SZ+BIT16SZ > ep)
                        return 0;
                f->fid = GBIT32(p);
                p += BIT32SZ;
                f->nstat = GBIT16(p);
                p += BIT16SZ;
                if(p+f->nstat > ep) {
                        fprint(2, "erik is the man! p(%x)+f->nstat(%x) > 
ep(%x)", p, f->nstat, ep);
                        return 0;
                }
                f->stat = p;
                p += f->nstat;
                break;
/* snip */
}

My test case tries to copy a file over top of one that already exists.
 In this case, the bug decided to flit right by the check at
convM2S.c:216,217.

j...@jdc-desktop:~$ 9 factotum
j...@jdc-desktop:~$ srv -a sources.cs.bell-labs.com

!adding key: role=client proto=p9sk1 dom=outside.plan9.bell-labs.com
user[jdc]: catenate
password:
!
j...@jdc-desktop:~$ sudo 9mount -i
'unix!/tmp/ns.jdc.192.168.1.101:0/sources.cs.bell-labs.com' /n/sources
[sudo] password for jdc:
9mount: mount: Not a directory
j...@jdc-desktop:~$ ls /n/sources
/n/sources
j...@jdc-desktop:~$ sudo 9umount /n/sources
j...@jdc-desktop:~$ sudo 9mount -i
'unix!/tmp/ns.jdc.192.168.1.101:0/sources.cs.bell-labs.com' /n/sources
j...@jdc-desktop:~$ ps ax|grep 9ps
10426 pts/3    Sl     0:00 9pserve -u unix!/tmp/ns.jdc.192.168.1.101:0/factotum
10586 pts/3    Sl     0:00 9pserve -u -M 8192 -A  0
unix!/tmp/ns.jdc.192.168.1.101:0/sources.cs.bell-labs.com
10603 pts/3    R+     0:00 grep 9ps
j...@jdc-desktop:~$ cd /n/sources/contrib/catenate
j...@jdc-desktop:/n/sources/contrib/catenate$ cd times
j...@jdc-desktop:/n/sources/contrib/catenate/times$ ls
latin1.7a.font
j...@jdc-desktop:/n/sources/contrib/catenate/times$ ls ~/contrib
acme  guide  latin1.7a.font
j...@jdc-desktop:/n/sources/contrib/catenate/times$ sudo cp
/home/jdc/contrib/latin1.7a.font .
Oct  1 21:52:45.219 read bad packet from 6
n=62 nn=0
cp: cannot create regular file `./latin1.7a.font': Connection reset by peer

Jason Catena

Reply via email to