Skip to content

Commit d2dc958

Browse files
committed
ESDK-1749 perform malloc error checks that veracode indicated are likely problems
1 parent 66acd2c commit d2dc958

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Cpp-C/Eta/Impl/Transport/rsslImpl.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,13 @@ RsslRet rsslInitChannel(RsslChannel *chnl, RsslInProgInfo *inProg, RsslError *er
12161216
/* build it first */
12171217
size_t rsslLinkTypeLen = strlen(rsslLinkType);
12181218

1219-
rsslChnlImpl->componentVer.componentVersion.data = _rsslMalloc(length + RSSL_ComponentVersionEnd_Len + Rssl_ComponentVersionPlatform_Len + Rssl_Bits_Len + rsslLinkTypeLen);
1219+
if ((rsslChnlImpl->componentVer.componentVersion.data = _rsslMalloc(length + RSSL_ComponentVersionEnd_Len + Rssl_ComponentVersionPlatform_Len + Rssl_Bits_Len + rsslLinkTypeLen)) == NULL)
1220+
{
1221+
_rsslSetError(error, chnl, RSSL_RET_FAILURE, 0);
1222+
snprintf(error->text, MAX_RSSL_ERROR_TEXT, "<%s:%d> rsslInitChannel() Error: 0005 Memory allocation failed", __FILE__, __LINE__);
1223+
rsslChnlImpl->Channel.state = RSSL_CH_STATE_CLOSED;
1224+
return RSSL_RET_FAILURE;
1225+
}
12201226
MemCopyByInt(rsslChnlImpl->componentVer.componentVersion.data, rsslComponentVersionStart, RSSL_ComponentVersionStart_Len);
12211227
MemCopyByInt((rsslChnlImpl->componentVer.componentVersion.data + length), rsslComponentVersionPlatform, Rssl_ComponentVersionPlatform_Len);
12221228
length += (rtrUInt32)Rssl_ComponentVersionPlatform_Len;
@@ -1247,7 +1253,13 @@ RsslRet rsslInitChannel(RsslChannel *chnl, RsslInProgInfo *inProg, RsslError *er
12471253
userInfoLength = rsslChnlImpl->connOptsCompVer.componentVersion.length;
12481254
}
12491255

1250-
rsslChnlImpl->componentVer.componentVersion.data = _rsslMalloc(totalLength);
1256+
if ((rsslChnlImpl->componentVer.componentVersion.data = _rsslMalloc(totalLength)) == NULL)
1257+
{
1258+
_rsslSetError(error, chnl, RSSL_RET_FAILURE, 0);
1259+
snprintf(error->text, MAX_RSSL_ERROR_TEXT, "<%s:%d> rsslInitChannel() Error: 0005 Memory allocation failed", __FILE__, __LINE__);
1260+
rsslChnlImpl->Channel.state = RSSL_CH_STATE_CLOSED;
1261+
return RSSL_RET_FAILURE;
1262+
}
12511263
MemCopyByInt(rsslChnlImpl->componentVer.componentVersion.data, rsslComponentVersionStart, RSSL_ComponentVersionStart_Len);
12521264
length = (rtrUInt32)RSSL_ComponentVersionStart_Len;
12531265
/* see explanation above the declaration of defaultLength to understand the pointer arithmetic below */

0 commit comments

Comments
 (0)