Don't trust # of entries from ListAttributes
[openafs.git] / src / libadmin / vos / vosutils.c
index 878920d..9f18ab6 100644 (file)
@@ -10,8 +10,7 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
 #include "vosutils.h"
 #include "vsprocs.h"
@@ -29,7 +28,7 @@ static int
 OldVLDB_to_NewVLDB(struct vldbentry *source, struct nvldbentry *dest,
                   afs_status_p st)
 {
-    register int i;
+    int i;
     int rc = 0;
     afs_status_t tst = 0;
 
@@ -64,7 +63,7 @@ static int
 NewVLDB_to_OldVLDB(struct nvldbentry *source, struct vldbentry *dest,
                   afs_status_p st)
 {
-    register int i;
+    int i;
     afs_status_t tst = 0;
     int rc = 0;
 
@@ -127,7 +126,7 @@ VLDB_CreateEntry(afs_cell_handle_p cellHandle, struct nvldbentry *entryp,
 }
 
 int
-aVLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_int32 volid,
+aVLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_uint32 volid,
                  afs_int32 voltype, struct nvldbentry *entryp,
                  afs_status_p st)
 {
@@ -165,7 +164,7 @@ aVLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_int32 volid,
 }
 
 int
-aVLDB_GetEntryByName(afs_cell_handle_p cellHandle, const char *namep,
+aVLDB_GetEntryByName(afs_cell_handle_p cellHandle, char *namep,
                    struct nvldbentry *entryp, afs_status_p st)
 {
     struct vldbentry oentry;
@@ -202,7 +201,7 @@ aVLDB_GetEntryByName(afs_cell_handle_p cellHandle, const char *namep,
 }
 
 int
-VLDB_ReplaceEntry(afs_cell_handle_p cellHandle, afs_int32 volid,
+VLDB_ReplaceEntry(afs_cell_handle_p cellHandle, afs_uint32 volid,
                  afs_int32 voltype, struct nvldbentry *entryp,
                  afs_int32 releasetype, afs_status_p st)
 {
@@ -260,6 +259,10 @@ VLDB_ListAttributes(afs_cell_handle_p cellHandle,
                    cellHandle->vos_new = 0;
                }
            } else {
+               if (*entriesp < 0)
+                   *entriesp = 0;
+               if (*entriesp > blkentriesp->nbulkentries_len)
+                   *entriesp = blkentriesp->nbulkentries_len;
                rc = 1;
            }
        } else {
@@ -268,6 +271,12 @@ VLDB_ListAttributes(afs_cell_handle_p cellHandle,
                ubik_VL_ListAttributes(cellHandle->vos, 0, attrp,
                          entriesp, &arrayEntries);
            if (tst == 0) {
+
+               if (*entriesp < 0)
+                   *entriesp = 0;
+               if (*entriesp > arrayEntries.bulkentries_len)
+                   *entriesp = arrayEntries.bulkentries_len;
+
                blkentriesp->nbulkentries_val =
                    (nvldbentry *) malloc(*entriesp * sizeof(*blkentriesp));
                if (blkentriesp->nbulkentries_val != NULL) {
@@ -283,6 +292,7 @@ VLDB_ListAttributes(afs_cell_handle_p cellHandle,
                if (arrayEntries.bulkentries_val) {
                    free(arrayEntries.bulkentries_val);
                }
+
                rc = 1;
            }
        }
@@ -328,7 +338,8 @@ VLDB_IsSameAddrs(afs_cell_handle_p cellHandle, afs_int32 serv1,
 
     ListAddrByAttributes attrs;
     bulkaddrs addrs;
-    afs_uint32 *addrp, nentries, unique, i;
+    afs_uint32 *addrp;
+    afs_int32 nentries, unique, i;
     afsUUID uuid;
 
     *equal = 0;
@@ -398,7 +409,7 @@ VLDB_IsSameAddrs(afs_cell_handle_p cellHandle, afs_int32 serv1,
  */
 
 int
-GetVolumeInfo(afs_cell_handle_p cellHandle, unsigned int volid,
+GetVolumeInfo(afs_cell_handle_p cellHandle, afs_uint32 volid,
              struct nvldbentry *rentry, afs_int32 * server,
              afs_int32 * partition, afs_int32 * voltype, afs_status_p st)
 {