aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2022-02-10 13:40:28 -0800
committerReid Kleckner <rnk@google.com>2022-02-10 13:52:11 -0800
commit64037afe014e241e1c642952a703b6031d17d5a5 (patch)
treeac2646ab1ca00a9b545319297b5492845a378bcf /llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
parenta18d06a0f8ff2cce09166c814caeff97eefce03f (diff)
downloadllvm-64037afe014e241e1c642952a703b6031d17d5a5.zip
llvm-64037afe014e241e1c642952a703b6031d17d5a5.tar.gz
llvm-64037afe014e241e1c642952a703b6031d17d5a5.tar.bz2
[CodeView] Avoid integer overflow while parsing long version strings
This came up on a funny vendor-provided version string that didn't have a standard dotted quad of numbers.
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 52c7471..6cc30eb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -826,6 +826,8 @@ static Version parseVersion(StringRef Name) {
if (isdigit(C)) {
V.Part[N] *= 10;
V.Part[N] += C - '0';
+ V.Part[N] =
+ std::min<int>(V.Part[N], std::numeric_limits<uint16_t>::max());
} else if (C == '.') {
++N;
if (N >= 4)
@@ -867,7 +869,6 @@ void CodeViewDebug::emitCompilerInformation() {
Version FrontVer = parseVersion(CompilerVersion);
OS.AddComment("Frontend version");
for (int N : FrontVer.Part) {
- N = std::min<int>(N, std::numeric_limits<uint16_t>::max());
OS.emitInt16(N);
}