Resolving a crash related to strncopy followed by a strcat

call. strncopy will not explicity copy or add a "\0" therefore
strcat did not know where to append the "\n" which was causing
an out of bounds crash.
Because we are checking the length, strcpy should be good enough
as it also copies the "\0". Please note that that I am pre-emptively
adding 2 instead of 1 to the length to take into account of the \n
that will be added later.
Review URL: http://webrtc-codereview.appspot.com/253004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@857 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
punyabrata@webrtc.org 2011-11-01 15:19:44 +00:00
parent 36a992b030
commit 0ab521f754

View File

@ -71,14 +71,14 @@ VP8Encoder::VersionStatic(WebRtc_Word8* version, WebRtc_Word32 length)
{
const char* str = vpx_codec_iface_name(vpx_codec_vp8_cx());
WebRtc_Word32 verLen = (WebRtc_Word32)strlen(str);
// Accounting for added new line char.
if (verLen + 1 > length)
// Accounting for "\0" and "\n" (to be added a bit later)
if (verLen + 2 > length)
{
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
strncpy(version, str, verLen);
strcpy(version, str);
strcat(version, "\n");
return (verLen + 1);
return (verLen + 2);
}
WebRtc_Word32