]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Fix incorrect sizeof() arguments in allocations
authorSimon Wilkinson <sxw@your-file-system.com>
Fri, 15 Feb 2013 11:55:37 +0000 (11:55 +0000)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 21 Feb 2013 17:00:26 +0000 (09:00 -0800)
In a number of places we have

struct X *val;
val = malloc(sizeof(struct Y));

If sizeof(struct Y) < sizeof(struct X) this is obviously dangerous,
but it is incorrect regardless of the relative sizes of the
structures. Fix all of the occurences of this that clang points out
to us.

Caught by clang-analyzer

Change-Id: Iad32b4ae460d3f40a45cf33624973bf52fd167d4
Reviewed-on: http://gerrit.openafs.org/9156
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
src/budb/procs.c
src/libadmin/vos/vosutils.c
src/libafscp/afscp_server.c
src/lwp/iomgr.c
src/rx/rx_multi.c
src/viced/afsfileprocs.c

index 868aea4bfb024c210c027ca85e04cd69962ee010..0338f4566b956d7021edfc6faf410b274c68018b 100644 (file)
@@ -346,7 +346,7 @@ FreeReturnList(struct returnList *list)
 static afs_int32
 AddToReturnList(struct returnList *list, dbadr a, afs_int32 *to_skipP)
 {
-    char *tmp;
+    dbadr *tmp;
     afs_int32 size;
 
     if (a == 0)
@@ -372,7 +372,7 @@ AddToReturnList(struct returnList *list, dbadr a, afs_int32 *to_skipP)
        }
        if (!tmp)
            return BUDB_NOMEM;
-       list->elements = (dbadr *) tmp;
+       list->elements = tmp;
        list->allocSize = size;
     }
 
index b00cc4ad84d1dbc933b855cb8298d02adf6546d0..b4ee7d44ae3e7a1532a1d16a18869f8e0aa5c849 100644 (file)
@@ -279,7 +279,7 @@ VLDB_ListAttributes(afs_cell_handle_p cellHandle,
 
                if (*entriesp > 0) {
                    blkentriesp->nbulkentries_val =
-                       calloc(*entriesp, sizeof(*blkentriesp));
+                       calloc(*entriesp, sizeof(struct nvldbentry));
                    if (blkentriesp->nbulkentries_val != NULL) {
                        for (i = 0; i < *entriesp; i++) {
                            OldVLDB_to_NewVLDB((struct vldbentry *)&arrayEntries.
index 57e1107895a4280fd3f16b403e49e79e8c9c5820..c8b3fd7d810b9bb9e923842b452baae2bab3a715 100644 (file)
@@ -369,7 +369,8 @@ afscp_ServerByAddr(struct afscp_cell *thecell, afs_uint32 addr)
        else
            thecell->srvsalloced = 4;
        newlist = realloc(thecell->fsservers,
-                         thecell->srvsalloced * sizeof(struct afscp_server));
+                         thecell->srvsalloced
+                             * sizeof(struct afscp_server *));
        if (newlist == NULL) {
            return NULL;
        }
index b7dd1c2b58b025b01f40b51db9bf94464a3a9392..dcd94d15815bec5573f4298b68d80f20f65d0202 100644 (file)
@@ -152,19 +152,19 @@ void IOMGR_FreeFDSet(fd_set *s)
  */
 fd_set *IOMGR_AllocFDSet(void)
 {
-    struct IOMGR_fd_set *t;
+    fd_set *t;
     if (iomgrFreeFDSets) {
-       t =  iomgrFreeFDSets;
+       t = (fd_set *) iomgrFreeFDSets;
        iomgrFreeFDSets = iomgrFreeFDSets->next;
     }
     else {
        t = malloc(sizeof(fd_set));
     }
     if (!t)
-       return (fd_set*)0;
+       return NULL;
     else {
-       FD_ZERO((fd_set*)t);
-       return (fd_set*)t;
+       FD_ZERO(t);
+       return t;
     }
 }
 
index 65a347ed48bb0d2e6daa54ebdf68d243136a45c1..3362755c80d221f1420d1217afef8f91c02076e4 100644 (file)
@@ -39,7 +39,7 @@ multi_Init(struct rx_connection **conns, int nConns)
      */
 
     calls = osi_Alloc(sizeof(struct rx_call *) * nConns);
-    ready = osi_Alloc(sizeof(short *) * nConns);
+    ready = osi_Alloc(sizeof(short) * nConns);
     mh = osi_Alloc(sizeof(struct multi_handle));
     if (!calls || !ready || !mh)
        osi_Panic("multi_Rx: no mem\n");
index b400c99cc6cfa4c3193c36b4c2aa8905c99e63db..d1376f72c62ace9051a3141769f17894d46f32d6 100644 (file)
@@ -5098,7 +5098,7 @@ SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatis
 
     ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
     Statistics->ViceStatistics64_val =
-       malloc(statsVersion*sizeof(afs_int64));
+       malloc(statsVersion*sizeof(afs_uint64));
     Statistics->ViceStatistics64_len = statsVersion;
     FS_LOCK;
     AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;