1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
llvm-mirror/lib/Support
Andrew Browne 0b9b4fd582 Make SmallVector assert if it cannot grow.
Context:

  /// Double the size of the allocated memory, guaranteeing space for at
  /// least one more element or MinSize if specified.
  void grow(size_t MinSize = 0) { this->grow_pod(MinSize, sizeof(T)); }

  void push_back(const T &Elt) {
    if (LLVM_UNLIKELY(this->size() >= this->capacity()))
      this->grow();
    memcpy(reinterpret_cast<void *>(this->end()), &Elt, sizeof(T));
    this->set_size(this->size() + 1);
  }

When grow is called in push_back() without a MinSize specified, this is
relying on the guarantee of space for at least one more element.

There is an edge case bug where the SmallVector is already at its maximum size
and push_back() calls grow() with default MinSize of zero. Grow is unable to
provide space for one more element, but push_back() assumes the additional
element it will be available. This can result in silent memory corruption, as
this->end() will be an invalid pointer and the program may continue executing.

Another alternative to fix would be to remove the default argument from
grow(), which would mean several changing grow() to grow(this->size()+1)
in several places.

No test case added because it would require allocating ~4GB.

Reviewers: echristo

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77601
2020-04-21 17:53:39 -07:00
..
Unix
Windows
AArch64TargetParser.cpp
ABIBreak.cpp
Allocator.cpp
AMDGPUMetadata.cpp
APFloat.cpp
APInt.cpp
APSInt.cpp
ARMAttributeParser.cpp
ARMBuildAttrs.cpp
ARMTargetParser.cpp
ARMWinEH.cpp
Atomic.cpp
BinaryStreamError.cpp
BinaryStreamReader.cpp
BinaryStreamRef.cpp
BinaryStreamWriter.cpp
BlockFrequency.cpp
BranchProbability.cpp
BuryPointer.cpp
CachePruning.cpp
Chrono.cpp
circular_raw_ostream.cpp
CMakeLists.txt
CodeGenCoverage.cpp
COM.cpp
CommandLine.cpp
Compression.cpp
ConvertUTF.cpp
ConvertUTFWrapper.cpp
COPYRIGHT.regex
CrashRecoveryContext.cpp
CRC.cpp
DAGDeltaAlgorithm.cpp
DataExtractor.cpp
Debug.cpp
DebugCounter.cpp
DeltaAlgorithm.cpp
DJB.cpp
DynamicLibrary.cpp
ELFAttributeParser.cpp
ELFAttributes.cpp
Errno.cpp
Error.cpp
ErrorHandling.cpp
ExtensibleRTTI.cpp
FileCheck.cpp
FileCheckImpl.h
FileCollector.cpp
FileOutputBuffer.cpp
FileUtilities.cpp
FoldingSet.cpp
FormattedStream.cpp
FormatVariadic.cpp
GlobPattern.cpp
GraphWriter.cpp
Hashing.cpp
Host.cpp
InitLLVM.cpp
IntEqClasses.cpp
IntervalMap.cpp
ItaniumManglingCanonicalizer.cpp
JSON.cpp
KnownBits.cpp
LEB128.cpp
LineIterator.cpp
LLVMBuild.txt
Locale.cpp
LockFileManager.cpp
LowLevelType.cpp
ManagedStatic.cpp
MathExtras.cpp
MD5.cpp
Memory.cpp
MemoryBuffer.cpp
NativeFormatting.cpp
OptimizedStructLayout.cpp
Optional.cpp
Parallel.cpp
Path.cpp
PluginLoader.cpp
PrettyStackTrace.cpp
Process.cpp
Program.cpp
RandomNumberGenerator.cpp
raw_os_ostream.cpp
raw_ostream.cpp
regcomp.c
regengine.inc
regerror.c
regex2.h
regex_impl.h
Regex.cpp
regexec.c
regfree.c
regstrlcpy.c
regutils.h
RISCVAttributeParser.cpp
RISCVAttributes.cpp
RWMutex.cpp
ScaledNumber.cpp
ScopedPrinter.cpp
SHA1.cpp
Signals.cpp
Signposts.cpp
SmallPtrSet.cpp
SmallVector.cpp
SourceMgr.cpp
SpecialCaseList.cpp
Statistic.cpp
StringExtras.cpp
StringMap.cpp
StringRef.cpp
StringSaver.cpp
SymbolRemappingReader.cpp
SystemUtils.cpp
TargetParser.cpp
TargetRegistry.cpp
TarWriter.cpp
Threading.cpp
ThreadLocal.cpp
ThreadPool.cpp
TimeProfiler.cpp
Timer.cpp
ToolOutputFile.cpp
TrigramIndex.cpp
Triple.cpp
Twine.cpp
Unicode.cpp
UnicodeCaseFold.cpp
Valgrind.cpp
VersionTuple.cpp
VirtualFileSystem.cpp
Watchdog.cpp
WithColor.cpp
xxhash.cpp
YAMLParser.cpp
YAMLTraits.cpp
Z3Solver.cpp