From 7971d55c6ac67dc7e4b10a2564d6997271a820b0 Mon Sep 17 00:00:00 2001 From: Divya Sampath Kumar Date: Tue, 16 Jan 2024 14:09:20 -0800 Subject: [PATCH] Add snprintf checks --- src/source/Ice/TurnConnection.c | 4 +- .../PeerConnection/SessionDescription.c | 239 +++++++++++------- 2 files changed, 149 insertions(+), 94 deletions(-) diff --git a/src/source/Ice/TurnConnection.c b/src/source/Ice/TurnConnection.c index 3c37da4d5f..7761b757a9 100644 --- a/src/source/Ice/TurnConnection.c +++ b/src/source/Ice/TurnConnection.c @@ -1134,12 +1134,14 @@ STATUS turnConnectionGetLongTermKey(PCHAR username, PCHAR realm, PCHAR password, { STATUS retStatus = STATUS_SUCCESS; CHAR stringBuffer[STUN_MAX_USERNAME_LEN + MAX_ICE_CONFIG_CREDENTIAL_LEN + STUN_MAX_REALM_LEN + 2]; // 2 for two ":" between each value + INT32 amountWritten = 0; CHK(username != NULL && realm != NULL && password != NULL && pBuffer != NULL, STATUS_NULL_ARG); CHK(username[0] != '\0' && realm[0] != '\0' && password[0] != '\0' && bufferLen >= KVS_MD5_DIGEST_LENGTH, STATUS_INVALID_ARG); CHK((STRLEN(username) + STRLEN(realm) + STRLEN(password)) <= ARRAY_SIZE(stringBuffer) - 2, STATUS_INVALID_ARG); - SNPRINTF(stringBuffer, SIZEOF(stringBuffer), "%s:%s:%s", username, realm, password); + amountWritten = SNPRINTF(stringBuffer, SIZEOF(stringBuffer), "%s:%s:%s", username, realm, password); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "SNPRINTF error: Failed to generate the long term key with username, realm and password"); // TODO: Return back the error check KVS_MD5_DIGEST((PBYTE) stringBuffer, STRLEN(stringBuffer), pBuffer); diff --git a/src/source/PeerConnection/SessionDescription.c b/src/source/PeerConnection/SessionDescription.c index a6738b59d1..4b0ab961c7 100644 --- a/src/source/PeerConnection/SessionDescription.c +++ b/src/source/PeerConnection/SessionDescription.c @@ -311,16 +311,21 @@ PCHAR fmtpForPayloadType(UINT64 payloadType, PSessionDescription pSessionDescrip UINT32 currentMedia, currentAttribute; PSdpMediaDescription pMediaDescription = NULL; CHAR payloadStr[MAX_SDP_ATTRIBUTE_VALUE_LENGTH]; + INT32 amountWritten = 0; MEMSET(payloadStr, 0x00, MAX_SDP_ATTRIBUTE_VALUE_LENGTH); - SNPRINTF(payloadStr, SIZEOF(payloadStr), "%" PRId64, payloadType); + amountWritten = SNPRINTF(payloadStr, SIZEOF(payloadStr), "%" PRId64, payloadType); - for (currentMedia = 0; currentMedia < pSessionDescription->mediaCount; currentMedia++) { - pMediaDescription = &(pSessionDescription->mediaDescriptions[currentMedia]); - for (currentAttribute = 0; currentAttribute < pMediaDescription->mediaAttributesCount; currentAttribute++) { - if (STRCMP(pMediaDescription->sdpAttributes[currentAttribute].attributeName, "fmtp") == 0 && - STRNCMP(pMediaDescription->sdpAttributes[currentAttribute].attributeValue, payloadStr, STRLEN(payloadStr)) == 0) { - return pMediaDescription->sdpAttributes[currentAttribute].attributeValue + STRLEN(payloadStr) + 1; + if (amountWritten < 0) { + DLOGE("Internal error: Full payload type for fmtp could not be written"); + } else { + for (currentMedia = 0; currentMedia < pSessionDescription->mediaCount; currentMedia++) { + pMediaDescription = &(pSessionDescription->mediaDescriptions[currentMedia]); + for (currentAttribute = 0; currentAttribute < pMediaDescription->mediaAttributesCount; currentAttribute++) { + if (STRCMP(pMediaDescription->sdpAttributes[currentAttribute].attributeName, "fmtp") == 0 && + STRNCMP(pMediaDescription->sdpAttributes[currentAttribute].attributeValue, payloadStr, STRLEN(payloadStr)) == 0) { + return pMediaDescription->sdpAttributes[currentAttribute].attributeValue + STRLEN(payloadStr) + 1; + } } } } @@ -400,6 +405,7 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp PSdpMediaDescription pSdpMediaDescriptionRemote; PCHAR currentFmtp = NULL, rtpMapValue = NULL; CHAR remoteSdpAttributeValue[MAX_SDP_ATTRIBUTE_VALUE_LENGTH]; + INT32 amountWritten = 0; MEMSET(remoteSdpAttributeValue, 0, MAX_SDP_ATTRIBUTE_VALUE_LENGTH); @@ -423,13 +429,18 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp containRtx = (retStatus == STATUS_SUCCESS); retStatus = STATUS_SUCCESS; if (containRtx) { - SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), "video 9 UDP/TLS/RTP/SAVPF %" PRId64 " %" PRId64, - payloadType, rtxPayloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), + "video 9 UDP/TLS/RTP/SAVPF %" PRId64 " %" PRId64, payloadType, rtxPayloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full video (with rtx) media name attribute could not be written"); } else { - SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), "video 9 UDP/TLS/RTP/SAVPF %" PRId64, payloadType); + amountWritten = + SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), "video 9 UDP/TLS/RTP/SAVPF %" PRId64, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full video media name attribute could not be written"); } } else if (pRtcMediaStreamTrack->kind == MEDIA_STREAM_TRACK_KIND_AUDIO) { - SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), "audio 9 UDP/TLS/RTP/SAVPF %" PRId64, payloadType); + amountWritten = + SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), "audio 9 UDP/TLS/RTP/SAVPF %" PRId64, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full audio media name attribute could not be written"); } CHK_STATUS(iceAgentPopulateSdpMediaDescriptionCandidates(pKvsPeerConnection->pIceAgent, pSdpMediaDescription, MAX_SDP_ATTRIBUTE_VALUE_LENGTH, @@ -437,71 +448,82 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp if (containRtx) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "msid"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%s %sRTX", pRtcMediaStreamTrack->streamId, - pRtcMediaStreamTrack->trackId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%s %sRTX", + pRtcMediaStreamTrack->streamId, pRtcMediaStreamTrack->trackId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full msid value (with rtx) could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc-group"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "FID %u %u", pKvsRtpTransceiver->sender.ssrc, - pKvsRtpTransceiver->sender.rtxSsrc); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "FID %u %u", + pKvsRtpTransceiver->sender.ssrc, pKvsRtpTransceiver->sender.rtxSsrc); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc-grp value (with rtx) could not be written"); attributeCount++; } else { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "msid"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%s %s", pRtcMediaStreamTrack->streamId, - pRtcMediaStreamTrack->trackId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%s %s", pRtcMediaStreamTrack->streamId, + pRtcMediaStreamTrack->trackId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full msid value could not be written"); attributeCount++; } STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u cname:%s", pKvsRtpTransceiver->sender.ssrc, - pKvsPeerConnection->localCNAME); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u cname:%s", + pKvsRtpTransceiver->sender.ssrc, pKvsPeerConnection->localCNAME); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc cname could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u msid:%s %s", pKvsRtpTransceiver->sender.ssrc, - pRtcMediaStreamTrack->streamId, pRtcMediaStreamTrack->trackId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u msid:%s %s", + pKvsRtpTransceiver->sender.ssrc, pRtcMediaStreamTrack->streamId, pRtcMediaStreamTrack->trackId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc msid could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u mslabel:%s", pKvsRtpTransceiver->sender.ssrc, - pRtcMediaStreamTrack->streamId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u mslabel:%s", + pKvsRtpTransceiver->sender.ssrc, pRtcMediaStreamTrack->streamId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc mslabel could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u label:%s", pKvsRtpTransceiver->sender.ssrc, - pRtcMediaStreamTrack->trackId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u label:%s", + pKvsRtpTransceiver->sender.ssrc, pRtcMediaStreamTrack->trackId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc label could not be written"); attributeCount++; if (containRtx) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u cname:%s", pKvsRtpTransceiver->sender.rtxSsrc, - pKvsPeerConnection->localCNAME); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u cname:%s", + pKvsRtpTransceiver->sender.rtxSsrc, pKvsPeerConnection->localCNAME); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc cname (with rtx) could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u msid:%s %sRTX", pKvsRtpTransceiver->sender.rtxSsrc, - pRtcMediaStreamTrack->streamId, pRtcMediaStreamTrack->trackId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u msid:%s %sRTX", + pKvsRtpTransceiver->sender.rtxSsrc, pRtcMediaStreamTrack->streamId, pRtcMediaStreamTrack->trackId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc msid (with rtx) could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u mslabel:%sRTX", pKvsRtpTransceiver->sender.rtxSsrc, - pRtcMediaStreamTrack->streamId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u mslabel:%sRTX", + pKvsRtpTransceiver->sender.rtxSsrc, pRtcMediaStreamTrack->streamId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc mslabel (with rtx) could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u label:%sRTX", pKvsRtpTransceiver->sender.rtxSsrc, - pRtcMediaStreamTrack->trackId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u label:%sRTX", + pKvsRtpTransceiver->sender.rtxSsrc, pRtcMediaStreamTrack->trackId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ssrc label (with rtx) could not be written"); attributeCount++; } @@ -545,11 +567,13 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp // If we don't have it, we loop over, create and add them if (STRLEN(remoteSdpAttributeValue) > 0) { CHK(STRLEN(remoteSdpAttributeValue) < MAX_SDP_ATTRIBUTE_VALUE_LENGTH, STATUS_BUFFER_TOO_SMALL); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%s", remoteSdpAttributeValue); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%s", remoteSdpAttributeValue); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Mid exists, but remote SDP value could not be written"); } else { - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%d", mediaSectionId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%d", mediaSectionId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full media section Id could not be written"); } attributeCount++; @@ -608,35 +632,43 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp currentFmtp = DEFAULT_H264_FMTP; } STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " H264/90000", payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " H264/90000", payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 payload type could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtcp-fb"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack", payloadType); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack pli", payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack", payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 rtcp-fb nack value could not be written"); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack pli", payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 rtcp-fb nack-pli value could not be written"); attributeCount++; // TODO: If level asymmetry is allowed, consider sending back DEFAULT_H264_FMTP instead of the received fmtp value. if (currentFmtp != NULL) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "fmtp"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " %s", payloadType, currentFmtp); + amountWritten = + SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " %s", payloadType, currentFmtp); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 fmtp value could not be written"); attributeCount++; } if (containRtx) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " RTX_VALUE, rtxPayloadType); + amountWritten = + SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " RTX_VALUE, rtxPayloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 rtpmap (with rtx) could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "fmtp"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " apt=%" PRId64 "", rtxPayloadType, - payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " apt=%" PRId64 "", + rtxPayloadType, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 fmtp apt value (with rtx) could not be written"); attributeCount++; } } else if (pRtcMediaStreamTrack->codec == RTC_CODEC_OPUS) { @@ -645,74 +677,90 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp } STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " opus/48000/2", payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " opus/48000/2", payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full Opus rtpmap could not be written"); attributeCount++; if (currentFmtp != NULL) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "fmtp"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " %s", payloadType, currentFmtp); + amountWritten = + SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " %s", payloadType, currentFmtp); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full Opus fmtp could not be written"); attributeCount++; } } else if (pRtcMediaStreamTrack->codec == RTC_CODEC_VP8) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " VP8_VALUE, payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " VP8_VALUE, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full VP8 rtpmap could not be written"); attributeCount++; if (containRtx) { CHK_STATUS(hashTableGet(pKvsPeerConnection->pRtxTable, RTC_RTX_CODEC_VP8, &rtxPayloadType)); STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " RTX_VALUE, rtxPayloadType); + amountWritten = + SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " RTX_VALUE, rtxPayloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full VP8 rtpmap payload type (with rtx) could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "fmtp"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " apt=%" PRId64 "", rtxPayloadType, - payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " apt=%" PRId64 "", + rtxPayloadType, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full VP8 rtpmap fmtp apt value (with rtx) could not be written"); attributeCount++; } } else if (pRtcMediaStreamTrack->codec == RTC_CODEC_MULAW) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " MULAW_VALUE, payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " MULAW_VALUE, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full MULAW rtpmap could not be written"); attributeCount++; } else if (pRtcMediaStreamTrack->codec == RTC_CODEC_ALAW) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " ALAW_VALUE, payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " ALAW_VALUE, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full ALAW rtpmap could not be written"); attributeCount++; } else if (pRtcMediaStreamTrack->codec == RTC_CODEC_UNKNOWN) { CHK_STATUS(hashTableGet(pUnknownCodecRtpmapTable, unknownCodecHashTableKey, (PUINT64) &rtpMapValue)); STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtpmap"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " %s", payloadType, rtpMapValue); + amountWritten = + SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " %s", payloadType, rtpMapValue); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full Unknown rtpmap could not be written"); attributeCount++; } STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u cname:%s", pKvsRtpTransceiver->sender.ssrc, - pKvsPeerConnection->localCNAME); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u cname:%s", + pKvsRtpTransceiver->sender.ssrc, pKvsPeerConnection->localCNAME); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full transceiver ssrc cname could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "ssrc"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u msid:%s %s", pKvsRtpTransceiver->sender.ssrc, - pRtcMediaStreamTrack->streamId, pRtcMediaStreamTrack->trackId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%u msid:%s %s", + pKvsRtpTransceiver->sender.ssrc, pRtcMediaStreamTrack->streamId, pRtcMediaStreamTrack->trackId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full transceiver ssrc msid could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtcp-fb"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " goog-remb", payloadType); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " goog-remb", payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full rtcp-fb goog-remb could not be written"); attributeCount++; if (pKvsPeerConnection->twccExtId != 0) { STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtcp-fb"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " TWCC_SDP_ATTR, payloadType); + amountWritten = + SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " " TWCC_SDP_ATTR, payloadType); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full rtcp-fb twcc could not be written"); attributeCount++; } @@ -730,8 +778,11 @@ STATUS populateSessionDescriptionDataChannel(PKvsPeerConnection pKvsPeerConnecti ENTERS(); STATUS retStatus = STATUS_SUCCESS; UINT32 attributeCount = 0; + INT32 amountWritten = 0; - SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), "application 9 UDP/DTLS/SCTP webrtc-datachannel"); + amountWritten = + SNPRINTF(pSdpMediaDescription->mediaName, SIZEOF(pSdpMediaDescription->mediaName), "application 9 UDP/DTLS/SCTP webrtc-datachannel"); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full data channel media name could not be written"); CHK_STATUS(iceAgentPopulateSdpMediaDescriptionCandidates(pKvsPeerConnection->pIceAgent, pSdpMediaDescription, MAX_SDP_ATTRIBUTE_VALUE_LENGTH, &attributeCount)); @@ -764,13 +815,15 @@ STATUS populateSessionDescriptionDataChannel(PKvsPeerConnection pKvsPeerConnecti attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "mid"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%d", mediaSectionId); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%d", mediaSectionId); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full data channel mid media section could not be written"); attributeCount++; STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "sctp-port"); - SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, - SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "5000"); + amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, + SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "5000"); + CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full data channel sctp-port could not be written"); attributeCount++; pSdpMediaDescription->mediaAttributesCount = attributeCount;