sscanf isn't safe with strings that aren't null-terminated. In such case, create a local copy that is null-terminated first.

TESTED=GYP_DEFINES=build_for_tool=memcheck gclient runhooks
ninja -C out/Debug/ libjingle_unittest
tools/valgrind-webrtc/webrtc_tests.sh --tool memcheck --test out/Debug/libjingle_unittest  --gtest_filter=Http*

R=noahric@google.com

Review URL: https://webrtc-codereview.appspot.com/1941004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4469 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
wu@webrtc.org
2013-08-01 21:20:46 +00:00
parent 17758e96c5
commit 0dc0f172a3
2 changed files with 7 additions and 24 deletions

View File

@@ -166,8 +166,12 @@ HttpParser::ProcessLine(const char* line, size_t len, HttpError* error) {
} while ((value < eol) && isspace(static_cast<unsigned char>(*value))); } while ((value < eol) && isspace(static_cast<unsigned char>(*value)));
size_t vlen = eol - value; size_t vlen = eol - value;
if (MatchHeader(line, nlen, HH_CONTENT_LENGTH)) { if (MatchHeader(line, nlen, HH_CONTENT_LENGTH)) {
// sscanf isn't safe with strings that aren't null-terminated, and there
// is no guarantee that |value| is.
// Create a local copy that is null-terminated.
std::string value_str(value, vlen);
unsigned int temp_size; unsigned int temp_size;
if (sscanf(value, "%u", &temp_size) != 1) { if (sscanf(value_str.c_str(), "%u", &temp_size) != 1) {
*error = HE_PROTOCOL; *error = HE_PROTOCOL;
return PR_COMPLETE; return PR_COMPLETE;
} }

View File

@@ -917,27 +917,6 @@
fun:BIO_new_mem_buf fun:BIO_new_mem_buf
fun:_ZN9talk_base15OpenSSLIdentity14FromPEMStringsERKSsS2_ fun:_ZN9talk_base15OpenSSLIdentity14FromPEMStringsERKSsS2_
} }
# For sscanf
{
sscanf_1
Memcheck:Uninitialized
fun:__GI___rawmemchr
fun:_IO_str_init_static_internal
fun:vsscanf
fun:sscanf
fun:_ZN9talk_base16HttpResponseData11parseLeaderEPKcm
...
}
{
sscanf_2
Memcheck:Uninitialized
fun:__GI___rawmemchr
fun:_IO_str_init_static_internal
fun:vsscanf
fun:sscanf
fun:_ZN9talk_base15HttpRequestData11parseLeaderEPKcm
...
}
# For HttpServer.SignalsCloseAfterForcedCloseAll # For HttpServer.SignalsCloseAfterForcedCloseAll
{ {
SignalsCloseAfterForcedCloseAll SignalsCloseAfterForcedCloseAll