trpc fixes (vandebo) - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 886a6f6c535f081e5d845db7ba79b16f2b68ef97
parent e77222a4ecdf427c2eed2eb44251b8841ef81b3c
Author: rsc 
Date:   Thu,  4 May 2006 18:02:48 +0000

rpc fixes (vandebo)

Diffstat:
  M src/libsunrpc/nfs3.c                |       8 +++++++-
  M src/libsunrpc/rpc.c                 |       3 ++-
  M src/libsunrpc/server.c              |      16 +++++++++++-----

3 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/src/libsunrpc/nfs3.c b/src/libsunrpc/nfs3.c
t@@ -2938,6 +2938,11 @@ nfs3entrysize(Nfs3Entry *x)
         a = 0 + 4 + 8 + sunstringsize(x->name) + 8;
         return a;
 }
+static int
+sunstringvpack(uchar *a, uchar *ea, uchar **pa, char **s, u32int n)
+{
+        return sunvaropaquepack(a, ea, pa, (uchar**)&s, &n, -1);
+}
 int
 nfs3entrypack(uchar *a, uchar *ea, uchar **pa, Nfs3Entry *x)
 {
t@@ -2946,7 +2951,7 @@ nfs3entrypack(uchar *a, uchar *ea, uchar **pa, Nfs3Entry *x)
         one = 1;
         if(sunuint1pack(a, ea, &a, &one) < 0) goto Err;
         if(sunuint64pack(a, ea, &a, &x->fileid) < 0) goto Err;
-        if(sunstringpack(a, ea, &a, &x->name, -1) < 0) goto Err;
+        if(sunstringvpack(a, ea, &a, &x->name, x->namelen) < 0) goto Err;
         if(sunuint64pack(a, ea, &a, &x->cookie) < 0) goto Err;
         *pa = a;
         return 0;
t@@ -2963,6 +2968,7 @@ nfs3entryunpack(uchar *a, uchar *ea, uchar **pa, Nfs3Entry *x)
         if(sunuint1unpack(a, ea, &a, &one) < 0 || one != 1) goto Err;
         if(sunuint64unpack(a, ea, &a, &x->fileid) < 0) goto Err;
         if(sunstringunpack(a, ea, &a, &x->name, -1) < 0) goto Err;
+        x->namelen = strlen(x->name);
         if(sunuint64unpack(a, ea, &a, &x->cookie) < 0) goto Err;
         *pa = a;
         return 0;
diff --git a/src/libsunrpc/rpc.c b/src/libsunrpc/rpc.c
t@@ -140,6 +140,7 @@ sunrpcsize(SunRpc *rpc)
                 case SunRpcMismatch:
                 case SunProgMismatch:
                         a += 3*4;
+                        break;
                 default:
                         a += 4;
                 }
t@@ -439,7 +440,7 @@ sunstringunpack(uchar *a, uchar *ea, uchar **pa, char **s, u32int max)
                 goto Err;
         /* slide string down over length to make room for NUL */
         memmove(dat-1, dat, n);
-        dat[-1+n] = 0;
+        dat[n-1] = 0;
         *s = (char*)(dat-1);
         return 0;
 Err:
diff --git a/src/libsunrpc/server.c b/src/libsunrpc/server.c
t@@ -144,11 +144,12 @@ if(srv->chatty) fprint(2, "sun msg %p count %d\n", m, m->count);
 static SunProg*
 sunfindprog(SunSrv *srv, SunMsg *m, SunRpc *rpc, Channel **pc)
 {
-        int i, vlo, vhi;
+        int i, vlo, vhi, any;
         SunProg *pg;
 
-        vlo = 0x7fffffff;
-        vhi = -1;
+        vlo = 0;
+        vhi = 0;
+        any = 0;
 
         for(i=0; inprog; i++){
                 pg = srv->prog[i];
t@@ -159,10 +160,15 @@ sunfindprog(SunSrv *srv, SunMsg *m, SunRpc *rpc, Channel **pc)
                         return pg;
                 }
                 /* right program, wrong version: record range */
-                if(pg->vers < vlo)
+                if(!any++){
                         vlo = pg->vers;
-                if(pg->vers > vhi)
                         vhi = pg->vers;
+                }else{
+                        if(pg->vers < vlo)
+                                vlo = pg->vers;
+                        if(pg->vers > vhi)
+                                vhi = pg->vers;
+                }
         }
         if(vhi == -1){
                 if(srv->chatty)