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

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

Issue 1123333004: Merge to XFA: Fix potential UAF in ConcatInPlace. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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/include/fxcrt/fx_string.h ('k') | core/src/fxcrt/fx_basic_bstring_unittest.cpp » ('j') | 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <stddef.h> // For offsetof(). 7 #include <stddef.h> // For offsetof().
8 8
9 #include "../../include/fxcrt/fx_basic.h" 9 #include "../../include/fxcrt/fx_basic.h"
10 #include "../../../third_party/base/numerics/safe_math.h" 10 #include "../../../third_party/base/numerics/safe_math.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 415 }
416 if (m_pData == NULL) { 416 if (m_pData == NULL) {
417 m_pData = StringData::Create(nSrcLen); 417 m_pData = StringData::Create(nSrcLen);
418 if (!m_pData) { 418 if (!m_pData) {
419 return; 419 return;
420 } 420 }
421 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen); 421 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen);
422 return; 422 return;
423 } 423 }
424 if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nA llocLength) { 424 if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nA llocLength) {
425 StringData* pOldData = m_pData;
426 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcDa ta); 425 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcDa ta);
427 pOldData->Release();
428 } else { 426 } else {
429 FXSYS_memcpy32(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData, nSrcLen); 427 FXSYS_memcpy32(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData, nSrcLen);
430 m_pData->m_nDataLength += nSrcLen; 428 m_pData->m_nDataLength += nSrcLen;
431 m_pData->m_String[m_pData->m_nDataLength] = 0; 429 m_pData->m_String[m_pData->m_nDataLength] = 0;
432 } 430 }
433 } 431 }
434 void CFX_ByteString::ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCSTR lpszSrc1Data, 432 void CFX_ByteString::ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCSTR lpszSrc1Data,
435 FX_STRSIZE nSrc2Len, FX_LPCSTR lpszSrc2Data) 433 FX_STRSIZE nSrc2Len, FX_LPCSTR lpszSrc2Data)
436 { 434 {
437 int nNewLen = nSrc1Len + nSrc2Len; 435 int nNewLen = nSrc1Len + nSrc2Len;
438 if (nNewLen == 0) { 436 if (nNewLen <= 0) {
439 return; 437 return;
440 } 438 }
439 // Don't release until done copying, might be one of the arguments.
440 StringData* pOldData = m_pData;
441 m_pData = StringData::Create(nNewLen); 441 m_pData = StringData::Create(nNewLen);
442 if (m_pData) { 442 if (m_pData) {
443 FXSYS_memcpy32(m_pData->m_String, lpszSrc1Data, nSrc1Len); 443 memcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len);
444 FXSYS_memcpy32(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len); 444 memcpy(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len);
445 } 445 }
446 pOldData->Release();
446 } 447 }
447 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst) const 448 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst) const
448 { 449 {
449 if (m_pData == NULL) { 450 if (m_pData == NULL) {
450 return CFX_ByteString(); 451 return CFX_ByteString();
451 } 452 }
452 return Mid(nFirst, m_pData->m_nDataLength - nFirst); 453 return Mid(nFirst, m_pData->m_nDataLength - nFirst);
453 } 454 }
454 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const 455 CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const
455 { 456 {
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 scale /= 10; 1127 scale /= 10;
1127 } 1128 }
1128 return buf_size; 1129 return buf_size;
1129 } 1130 }
1130 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) 1131 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision)
1131 { 1132 {
1132 FX_CHAR buf[32]; 1133 FX_CHAR buf[32];
1133 FX_STRSIZE len = FX_ftoa(d, buf); 1134 FX_STRSIZE len = FX_ftoa(d, buf);
1134 return CFX_ByteString(buf, len); 1135 return CFX_ByteString(buf, len);
1135 } 1136 }
OLDNEW
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | core/src/fxcrt/fx_basic_bstring_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698