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

Side by Side Diff: core/src/fxcrt/fx_basic_wstring_unittest.cpp

Issue 1130763007: Fix potential UAF in ConcatInPlace. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Add comment before strange looking test. Created 5 years, 7 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 | « core/src/fxcrt/fx_basic_wstring.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "../../../testing/fx_string_testhelpers.h" 6 #include "../../../testing/fx_string_testhelpers.h"
7 #include "../../include/fxcrt/fx_basic.h" 7 #include "../../include/fxcrt/fx_basic.h"
8 8
9 TEST(fxcrt, WideStringOperatorSubscript) { 9 TEST(fxcrt, WideStringOperatorSubscript) {
10 // CFX_WideString includes the NUL terminator for non-empty strings. 10 // CFX_WideString includes the NUL terminator for non-empty strings.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 const wchar_t* c_string2 = L"hellp"; 242 const wchar_t* c_string2 = L"hellp";
243 const wchar_t* c_string3 = L"hellod"; 243 const wchar_t* c_string3 = L"hellod";
244 EXPECT_TRUE(wide_string != c_string1); 244 EXPECT_TRUE(wide_string != c_string1);
245 EXPECT_TRUE(wide_string != c_string2); 245 EXPECT_TRUE(wide_string != c_string2);
246 EXPECT_TRUE(wide_string != c_string3); 246 EXPECT_TRUE(wide_string != c_string3);
247 EXPECT_TRUE(c_string1 != wide_string); 247 EXPECT_TRUE(c_string1 != wide_string);
248 EXPECT_TRUE(c_string2 != wide_string); 248 EXPECT_TRUE(c_string2 != wide_string);
249 EXPECT_TRUE(c_string3 != wide_string); 249 EXPECT_TRUE(c_string3 != wide_string);
250 } 250 }
251 251
252 TEST(fxcrt, WideStringConcatInPlace) {
253 CFX_WideString fred;
254 fred.ConcatInPlace(4, L"FRED");
255 EXPECT_EQ(L"FRED", fred);
256
257 fred.ConcatInPlace(2, L"DY");
258 EXPECT_EQ(L"FREDDY", fred);
259
260 fred.Delete(3, 3);
261 EXPECT_EQ(L"FRE", fred);
262
263 fred.ConcatInPlace(1, L"D");
264 EXPECT_EQ(L"FRED", fred);
265
266 CFX_WideString copy = fred;
267 fred.ConcatInPlace(2, L"DY");
268 EXPECT_EQ(L"FREDDY", fred);
269 EXPECT_EQ(L"FRED", copy);
270
271 // Test invalid arguments.
272 copy = fred;
273 fred.ConcatInPlace(-6, L"freddy");
274 CFX_WideString not_aliased(L"xxxxxx");
275 EXPECT_EQ(L"FREDDY", fred);
276 EXPECT_EQ(L"xxxxxx", not_aliased);
277 }
278
252 #define ByteStringLiteral(str) CFX_ByteString(FX_BSTRC(str)) 279 #define ByteStringLiteral(str) CFX_ByteString(FX_BSTRC(str))
253 280
254 TEST(fxcrt, WideStringUTF16LE_Encode) { 281 TEST(fxcrt, WideStringUTF16LE_Encode) {
255 struct UTF16LEEncodeCase { 282 struct UTF16LEEncodeCase {
256 CFX_WideString ws; 283 CFX_WideString ws;
257 CFX_ByteString bs; 284 CFX_ByteString bs;
258 } utf16le_encode_cases[] = { 285 } utf16le_encode_cases[] = {
259 { L"", ByteStringLiteral("\0\0") }, 286 { L"", ByteStringLiteral("\0\0") },
260 { L"abc", ByteStringLiteral("a\0b\0c\0\0\0") }, 287 { L"abc", ByteStringLiteral("a\0b\0c\0\0\0") },
261 { L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0\0\0") }, 288 { L"abcdef", ByteStringLiteral("a\0b\0c\0d\0e\0f\0\0\0") },
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 const wchar_t* c_string2 = L"hellp"; 433 const wchar_t* c_string2 = L"hellp";
407 const wchar_t* c_string3 = L"hellod"; 434 const wchar_t* c_string3 = L"hellod";
408 EXPECT_TRUE(wide_string_c != c_string1); 435 EXPECT_TRUE(wide_string_c != c_string1);
409 EXPECT_TRUE(wide_string_c != c_string2); 436 EXPECT_TRUE(wide_string_c != c_string2);
410 EXPECT_TRUE(wide_string_c != c_string3); 437 EXPECT_TRUE(wide_string_c != c_string3);
411 438
412 EXPECT_TRUE(c_string1 != wide_string_c); 439 EXPECT_TRUE(c_string1 != wide_string_c);
413 EXPECT_TRUE(c_string2 != wide_string_c); 440 EXPECT_TRUE(c_string2 != wide_string_c);
414 EXPECT_TRUE(c_string3 != wide_string_c); 441 EXPECT_TRUE(c_string3 != wide_string_c);
415 } 442 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_wstring.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698