volser-handle-malloc-failure-20080317
authorDerrick Brashear <shadow@dementia.org>
Mon, 17 Mar 2008 17:14:01 +0000 (17:14 +0000)
committerDerrick Brashear <shadow@dementia.org>
Mon, 17 Mar 2008 17:14:01 +0000 (17:14 +0000)
LICENSE IPL10

allocate memory for all rx OUT parameters in stubs to avoid crashes.

src/volser/volprocs.c

index 20e22b2..9162a05 100644 (file)
@@ -214,6 +214,8 @@ ViceCreateRoot(Volume *vp)
     afs_fsize_t length;
 
     vnode = (struct VnodeDiskObject *)malloc(SIZEOF_LARGEDISKVNODE);
+    if (!vnode)
+       return ENOMEM;
     memset(vnode, 0, SIZEOF_LARGEDISKVNODE);
 
     V_pref(vp, nearInode);
@@ -1198,8 +1200,14 @@ SAFSVolForwardMultiple(struct rx_call *acid, afs_int32 fromTrans, afs_int32
     struct Volume *vp;
     int i, is_incremental;
 
-    if (results)
+    if (results) {
        memset(results, 0, sizeof(manyResults));
+       i = results->manyResults_len = destinations->manyDests_len;
+       results->manyResults_val = codes =
+         (afs_int32 *) malloc(i * sizeof(afs_int32));
+    }  
+    if (!results || !results->manyResults_val)
+       return ENOMEM;
 
     if (!afsconf_SuperUser(tdir, acid, caller))
        return VOLSERBAD_ACCESS;        /*not a super user */
@@ -1217,12 +1225,16 @@ SAFSVolForwardMultiple(struct rx_call *acid, afs_int32 fromTrans, afs_int32
     /* (fromDate == 0) ==> full dump */
     is_incremental = (fromDate ? 1 : 0);
 
-    i = results->manyResults_len = destinations->manyDests_len;
-    results->manyResults_val = codes =
-       (afs_int32 *) malloc(i * sizeof(afs_int32));
     tcons =
        (struct rx_connection **)malloc(i * sizeof(struct rx_connection *));
+    if (!tcons) {
+       return ENOMEM;
+    }
     tcalls = (struct rx_call **)malloc(i * sizeof(struct rx_call *));
+    if (!tcalls) {
+       free(tcons);
+       return ENOMEM;
+    }
 
     /* get auth info for this connection (uses afs from ticket file) */
     code = afsconf_ClientAuth(tdir, &securityObject, &securityIndex);
@@ -1600,7 +1612,10 @@ VolGetName(struct rx_call *acid, afs_int32 atrans, char **aname)
     struct volser_trans *tt;
     register int len;
 
-    *aname = NULL;
+    /* We need to at least fill it in */
+    *aname = (char *)malloc(1);
+    if (!*aname)
+       return ENOMEM;
     tt = FindTrans(atrans);
     if (!tt)
        return ENOENT;
@@ -1625,7 +1640,7 @@ VolGetName(struct rx_call *acid, afs_int32 atrans, char **aname)
        TRELE(tt);
        return E2BIG;
     }
-    *aname = (char *)malloc(len);
+    *aname = (char *)realloc(*aname, len);
     strcpy(*aname, td->name);
     tt->rxCallPtr = (struct rx_call *)0;
     if (TRELE(tt))
@@ -1717,6 +1732,8 @@ XVolListPartitions(struct rx_call *acid, struct partEntries *pEntries)
            partList.partId[j++] = i;
     }
     pEntries->partEntries_val = (afs_int32 *) malloc(j * sizeof(int));
+    if (!pEntries->partEntries_val)
+       return ENOMEM;
     memcpy((char *)pEntries->partEntries_val, (char *)&partList,
           j * sizeof(int));
     pEntries->partEntries_len = j;
@@ -2090,6 +2107,8 @@ VolListOneVolume(struct rx_call *acid, afs_int32 partid, afs_int32
     volint_info_handle_t handle;
 
     volumeInfo->volEntries_val = (volintInfo *) malloc(sizeof(volintInfo));
+    if (!volumeInfo->volEntries_val)
+       return ENOMEM;
     pntr = volumeInfo->volEntries_val;
     volumeInfo->volEntries_len = 1;
     if (GetPartName(partid, pname))
@@ -2193,6 +2212,8 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
      */
     a_volumeXInfoP->volXEntries_val =
        (volintXInfo *) malloc(sizeof(volintXInfo));
+    if (!a_volumeXInfoP->volXEntries_val)
+       return ENOMEM;
     xInfoP = a_volumeXInfoP->volXEntries_val;
     a_volumeXInfoP->volXEntries_len = 1;
     code = ENODEV;
@@ -2298,6 +2319,8 @@ VolListVolumes(struct rx_call *acid, afs_int32 partid, afs_int32 flags,
 
     volumeInfo->volEntries_val =
        (volintInfo *) malloc(allocSize * sizeof(volintInfo));
+    if (!volumeInfo->volEntries_val)
+       return ENOMEM;
     pntr = volumeInfo->volEntries_val;
     volumeInfo->volEntries_len = 0;
     if (GetPartName(partid, pname))
@@ -2427,6 +2450,8 @@ VolXListVolumes(struct rx_call *a_rxCidP, afs_int32 a_partID,
      */
     a_volumeXInfoP->volXEntries_val =
        (volintXInfo *) malloc(allocSize * sizeof(volintXInfo));
+    if (!a_volumeXInfoP->volXEntries_val)
+       return ENOMEM;
     xInfoP = a_volumeXInfoP->volXEntries_val;
     a_volumeXInfoP->volXEntries_len = 0;
 
@@ -2558,6 +2583,8 @@ VolMonitor(struct rx_call *acid, transDebugEntries *transInfo)
 
     transInfo->transDebugEntries_val =
        (transDebugInfo *) malloc(allocSize * sizeof(transDebugInfo));
+    if (!transInfo->transDebugEntries_val)
+       return ENOMEM;
     pntr = transInfo->transDebugEntries_val;
     transInfo->transDebugEntries_len = 0;
     allTrans = TransList();