DEVEL15-ptserver-simple-corrupt-protection-20080612
authorDerrick Brashear <shadow@dementia.org>
Thu, 12 Jun 2008 19:36:49 +0000 (19:36 +0000)
committerDerrick Brashear <shadow@dementia.org>
Thu, 12 Jun 2008 19:36:49 +0000 (19:36 +0000)
LICENSE IPL10

protects against direct loops, which we have seen in the wild, but not more (yet)

(cherry picked from commit e2ce8710efc93f7172b9d4daaf685c6f2669f7c3)

src/ptserver/pt_util.c
src/ptserver/utils.c

index 15694e2..1b276b8 100644 (file)
@@ -321,8 +321,16 @@ CommandProc(register struct cmd_syndesc *a_as, void *arock)
     } else {
        for (i = 0; i < HASHSIZE; i++) {
            upos = nflag ? ntohl(prh.nameHash[i]) : ntohl(prh.idHash[i]);
-           while (upos)
-               upos = display_entry(upos);
+           while (upos) {
+               long newpos;
+               newpos = display_entry(upos);
+               if (newpos == upos) {
+                   fprintf(stderr, "pt_util: hash error in %s chain %d\n", 
+                           nflag ? "name":"id", i);
+                   exit(1);
+               } else
+                   upos = newpos;
+           }
        }
        if (flags & DO_GRP)
            display_groups();
index d67c141..df0c6e8 100644 (file)
@@ -7,6 +7,7 @@
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
+#include <assert.h>
 #include <afsconfig.h>
 #include <afs/param.h>
 
@@ -294,6 +295,7 @@ FindByID(register struct ubik_trans *at, afs_int32 aid)
        return 0;
     if (aid == tentry.id)
        return entry;
+    assert(entry != tentry.nextID);
     entry = tentry.nextID;
     while (entry != 0) {
        memset(&tentry, 0, sizeof(tentry));
@@ -302,6 +304,7 @@ FindByID(register struct ubik_trans *at, afs_int32 aid)
            return 0;
        if (aid == tentry.id)
            return entry;
+       assert(entry != tentry.nextID);
        entry = tentry.nextID;
     }
     return 0;
@@ -325,6 +328,7 @@ FindByName(register struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct pre
        return 0;
     if ((strncmp(aname, tentryp->name, PR_MAXNAMELEN)) == 0)
        return entry;
+    assert(entry != tentryp->nextName);
     entry = tentryp->nextName;
     while (entry != 0) {
        memset(tentryp, 0, sizeof(struct prentry));
@@ -333,6 +337,7 @@ FindByName(register struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct pre
            return 0;
        if ((strncmp(aname, tentryp->name, PR_MAXNAMELEN)) == 0)
            return entry;
+       assert(entry != tentryp->nextName);
        entry = tentryp->nextName;
     }
     return 0;
@@ -462,6 +467,7 @@ RemoveFromIDHash(struct ubik_trans *tt, afs_int32 aid, afs_int32 *loc)              /* ??? i
     if (code)
        return PRDBFAIL;
     while (aid != tentry.id) {
+       assert(trail != current);
        trail = current;
        current = tentry.nextID;
        if (current == 0)
@@ -539,6 +545,7 @@ RemoveFromNameHash(struct ubik_trans *tt, char *aname, afs_int32 *loc)
     if (code)
        return PRDBFAIL;
     while (strcmp(aname, tentry.name)) {
+       assert(trail != current);
        trail = current;
        current = tentry.nextName;
        if (current == 0)