sizeof(struct) is usually wrong in 64-bits if the structure is used for marshalling. this was found by cinap. need to write a tool for this. Reference: /n/atom/patch/applied/chap64 Date: Sun Feb 16 12:53:48 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/auth/authsrv.c Sun Feb 16 12:52:12 2014 +++ /sys/src/cmd/auth/authsrv.c Sun Feb 16 12:52:13 2014 @@ -577,7 +577,7 @@ /* * get chap reply */ - if(readn(0, &reply, sizeof(reply)) < 0) + if(readn(0, &reply, OCHAPREPLYLEN) < 0) exits(0); safecpy(tr->uid, reply.uid, sizeof(tr->uid)); @@ -654,7 +654,7 @@ /* * get chap reply */ - if(readn(0, &reply, sizeof(reply)) < 0) + if(readn(0, &reply, OMSCHAPREPLYLEN) < 0) exits(0); safecpy(tr->uid, reply.uid, sizeof(tr->uid)); --- /sys/include/authsrv.h Sun Feb 16 12:52:14 2014 +++ /sys/include/authsrv.h Sun Feb 16 12:52:14 2014 @@ -100,6 +100,7 @@ char uid[ANAMELEN]; char resp[OMD5LEN]; }; +#define OCHAPREPLYLEN (1+ANAMELEN+OMD5LEN) struct OMSchapreply { @@ -107,6 +108,7 @@ char LMresp[24]; /* Lan Manager response */ char NTresp[24]; /* NT response */ }; +#define OMSCHAPREPLYLEN (ANAMELEN+24+24) /* * convert to/from wire format --- /sys/src/cmd/auth/factotum/chap.c Sun Feb 16 12:52:15 2014 +++ /sys/src/cmd/auth/factotum/chap.c Sun Feb 16 12:52:16 2014 @@ -33,7 +33,10 @@ MShashlen = 16, MSchallen = 8, - MSresplen = 24 + MSresplen = 24, + + Chapreplylen = MD5LEN+1, + MSchapreplylen = 24+24, }; static int @@ -169,7 +172,7 @@ ds = md5(&cr.id, 1, 0, 0); md5((uchar*)pw, npw, 0, ds); md5(chal, nchal, (uchar*)cr.resp, ds); - if(convwrite(c, &cr, sizeof cr) < 0) + if(convwrite(c, &cr, Chapreplylen) < 0) goto out; }else{ uchar hash[MShashlen]; @@ -182,7 +185,7 @@ nthash(hash, pw); mschalresp((uchar*)mscr.NTresp, hash, chal); } - if(convwrite(c, &mscr, sizeof mscr) < 0) + if(convwrite(c, &mscr, MSchapreplylen) < 0) goto out; }