Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: webrtc/p2p/base/stun_unittest.cc

Issue 2837133003: Don't crash if STUN error message is missing ERROR-CODE attribute. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/stun.cc ('k') | webrtc/p2p/base/stunport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 size_t size = ReadStunMessage(&msg, kStunMessageWithErrorAttribute); 1009 size_t size = ReadStunMessage(&msg, kStunMessageWithErrorAttribute);
1010 1010
1011 CheckStunHeader(msg, STUN_BINDING_ERROR_RESPONSE, size); 1011 CheckStunHeader(msg, STUN_BINDING_ERROR_RESPONSE, size);
1012 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); 1012 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength);
1013 const StunErrorCodeAttribute* errorcode = msg.GetErrorCode(); 1013 const StunErrorCodeAttribute* errorcode = msg.GetErrorCode();
1014 ASSERT_TRUE(errorcode != NULL); 1014 ASSERT_TRUE(errorcode != NULL);
1015 EXPECT_EQ(kTestErrorClass, errorcode->eclass()); 1015 EXPECT_EQ(kTestErrorClass, errorcode->eclass());
1016 EXPECT_EQ(kTestErrorNumber, errorcode->number()); 1016 EXPECT_EQ(kTestErrorNumber, errorcode->number());
1017 EXPECT_EQ(kTestErrorReason, errorcode->reason()); 1017 EXPECT_EQ(kTestErrorReason, errorcode->reason());
1018 EXPECT_EQ(kTestErrorCode, errorcode->code()); 1018 EXPECT_EQ(kTestErrorCode, errorcode->code());
1019 EXPECT_EQ(kTestErrorCode, msg.GetErrorCodeValue());
1020 }
1021
1022 // Test that GetErrorCodeValue returns STUN_ERROR_GLOBAL_FAILURE if the message
1023 // in question doesn't have an error code attribute, rather than crashing.
1024 TEST_F(StunTest, GetErrorCodeValueWithNoErrorAttribute) {
1025 StunMessage msg;
1026 ReadStunMessage(&msg, kStunMessageWithIPv6MappedAddress);
1027 EXPECT_EQ(STUN_ERROR_GLOBAL_FAILURE, msg.GetErrorCodeValue());
1019 } 1028 }
1020 1029
1021 TEST_F(StunTest, ReadMessageWithAUInt16ListAttribute) { 1030 TEST_F(StunTest, ReadMessageWithAUInt16ListAttribute) {
1022 StunMessage msg; 1031 StunMessage msg;
1023 size_t size = ReadStunMessage(&msg, kStunMessageWithUInt16ListAttribute); 1032 size_t size = ReadStunMessage(&msg, kStunMessageWithUInt16ListAttribute);
1024 CheckStunHeader(msg, STUN_BINDING_REQUEST, size); 1033 CheckStunHeader(msg, STUN_BINDING_REQUEST, size);
1025 const StunUInt16ListAttribute* types = msg.GetUnknownAttributes(); 1034 const StunUInt16ListAttribute* types = msg.GetUnknownAttributes();
1026 ASSERT_TRUE(types != NULL); 1035 ASSERT_TRUE(types != NULL);
1027 EXPECT_EQ(3U, types->Size()); 1036 EXPECT_EQ(3U, types->Size());
1028 EXPECT_EQ(0x1U, types->GetType(0)); 1037 EXPECT_EQ(0x1U, types->GetType(0));
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 EXPECT_TRUE(msg2.Write(&out2)); 1473 EXPECT_TRUE(msg2.Write(&out2));
1465 EXPECT_EQ(size, out2.Length()); 1474 EXPECT_EQ(size, out2.Length());
1466 size_t len2 = out2.Length(); 1475 size_t len2 = out2.Length();
1467 rtc::ByteBufferReader read_buf2(out2); 1476 rtc::ByteBufferReader read_buf2(out2);
1468 std::string outstring2; 1477 std::string outstring2;
1469 read_buf2.ReadString(&outstring2, len2); 1478 read_buf2.ReadString(&outstring2, len2);
1470 EXPECT_EQ(0, memcmp(outstring2.c_str(), input, len2)); 1479 EXPECT_EQ(0, memcmp(outstring2.c_str(), input, len2));
1471 } 1480 }
1472 1481
1473 } // namespace cricket 1482 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/stun.cc ('k') | webrtc/p2p/base/stunport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698