From: Derrick Brashear Date: Mon, 17 Mar 2008 17:14:11 +0000 (+0000) Subject: DEVEL15-volser-handle-malloc-failure-20080317 X-Git-Tag: openafs-devel-1_5_34~22 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=d8d3cee031b6d7b87f9934c1fbb0fcf08b3c79f7;p=packages%2Fo%2Fopenafs.git DEVEL15-volser-handle-malloc-failure-20080317 LICENSE IPL10 allocate memory for all rx OUT parameters in stubs to avoid crashes. (cherry picked from commit 449756f8a26f1b30147851f98ac67b2a2642abf8) --- diff --git a/src/volser/volprocs.c b/src/volser/volprocs.c index c1dc6ba9a..980aa7339 100644 --- a/src/volser/volprocs.c +++ b/src/volser/volprocs.c @@ -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; @@ -2094,6 +2111,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)) @@ -2197,6 +2216,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; @@ -2302,6 +2323,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)) @@ -2431,6 +2454,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; @@ -2562,6 +2587,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();