[llvm] r369557 - [BitcodeReader] Check if we can create a null constant for type.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 11:20:11 PDT 2019
Author: fhahn
Date: Wed Aug 21 11:20:11 2019
New Revision: 369557
URL: http://llvm.org/viewvc/llvm-project?rev=369557&view=rev
Log:
[BitcodeReader] Check if we can create a null constant for type.
We cannot create null constants for certain types, e.g. VoidTy,
FunctionTy or LabelTy. getNullValue asserts if we pass in an
unsupported type. We should also check for opaque types, but I'm not
sure how.
This fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14795.
Reviewers: t.p.northover, jfb, vsk
Reviewed By: vsk
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65897
Added:
llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll
llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll.bc (with props)
Modified:
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=369557&r1=369556&r2=369557&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed Aug 21 11:20:11 2019
@@ -2377,6 +2377,8 @@ Error BitcodeReader::parseConstants() {
CurTy = flattenPointerTypes(CurFullTy);
continue; // Skip the ValueList manipulation.
case bitc::CST_CODE_NULL: // NULL
+ if (CurTy->isVoidTy() || CurTy->isFunctionTy() || CurTy->isLabelTy())
+ return error("Invalid type for a constant null value");
V = Constant::getNullValue(CurTy);
break;
case bitc::CST_CODE_INTEGER: // INTEGER: [intval]
Added: llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll?rev=369557&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll (added)
+++ llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll Wed Aug 21 11:20:11 2019
@@ -0,0 +1,6 @@
+; Bitcode with a CST_CODE_NULL with void type.
+
+; RUN: not llvm-dis %s.bc -o - 2>&1 | FileCheck %s
+
+; CHECK: error: Invalid type for a constant null value
+
Added: llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll.bc?rev=369557&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/Bitcode/invalid-type-for-null-constant.ll.bc
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
More information about the llvm-commits
mailing list