summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2015-05-17 20:38:01 +0000
committerdim <dim@FreeBSD.org>2015-05-17 20:38:01 +0000
commitd78b21b38eb27e1f0c55bd93a9c49ea3392b2544 (patch)
tree22e854a23e576c386d5a45634be096415d8903d9 /contrib
parentc3292ff7e0bfa8dc8a2f7f8ad88451e771229d45 (diff)
downloadFreeBSD-src-d78b21b38eb27e1f0c55bd93a9c49ea3392b2544.zip
FreeBSD-src-d78b21b38eb27e1f0c55bd93a9c49ea3392b2544.tar.gz
For clang 3.4.1, when using -fformat-extensions, and warning about the
FreeBSD-specific %D and %b printf format specifiers, avoid possible argument overruns. Also reduce the differences with the version added in r280031 (which has been sent upstream). Direct commit to stable/10, since head already has clang 3.6.0.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/llvm/patches/patch-r208987-format-extensions.diff22
-rw-r--r--contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp18
2 files changed, 22 insertions, 18 deletions
diff --git a/contrib/llvm/patches/patch-r208987-format-extensions.diff b/contrib/llvm/patches/patch-r208987-format-extensions.diff
index 6aa076c..57d0f9d 100644
--- a/contrib/llvm/patches/patch-r208987-format-extensions.diff
+++ b/contrib/llvm/patches/patch-r208987-format-extensions.diff
@@ -118,22 +118,25 @@ Index: tools/clang/lib/Sema/SemaChecking.cpp
===================================================================
--- tools/clang/lib/Sema/SemaChecking.cpp
+++ tools/clang/lib/Sema/SemaChecking.cpp
-@@ -2980,6 +2980,40 @@ CheckPrintfHandler::HandlePrintfSpecifier(const an
+@@ -2980,6 +2980,42 @@ CheckPrintfHandler::HandlePrintfSpecifier(const an
CoveredArgs.set(argIndex);
}
-+ // FreeBSD extensions
++ // FreeBSD kernel extensions.
+ if (CS.getKind() == ConversionSpecifier::FreeBSDbArg ||
+ CS.getKind() == ConversionSpecifier::FreeBSDDArg) {
-+ // claim the second argument
++ // We need at least two arguments.
++ if (!CheckNumArgs(FS, CS, startSpecifier, specifierLen, argIndex + 1))
++ return false;
++
++ // Claim the second argument.
+ CoveredArgs.set(argIndex + 1);
+
-+ // Now type check the data expression that matches the
-+ // format specifier.
++ // Type check the first argument (int for %b, pointer for %D)
+ const Expr *Ex = getDataArg(argIndex);
-+ const analyze_printf::ArgType &AT =
++ const analyze_printf::ArgType &AT =
+ (CS.getKind() == ConversionSpecifier::FreeBSDbArg) ?
-+ ArgType(S.Context.IntTy) : ArgType::CStrTy;
++ ArgType(S.Context.IntTy) : ArgType::CPointerTy;
+ if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType()))
+ S.Diag(getLocationOfByte(CS.getStart()),
+ diag::warn_printf_conversion_argument_type_mismatch)
@@ -141,8 +144,7 @@ Index: tools/clang/lib/Sema/SemaChecking.cpp
+ << getSpecifierRange(startSpecifier, specifierLen)
+ << Ex->getSourceRange();
+
-+ // Now type check the data expression that matches the
-+ // format specifier.
++ // Type check the second argument (char * for both %b and %D)
+ Ex = getDataArg(argIndex + 1);
+ const analyze_printf::ArgType &AT2 = ArgType::CStrTy;
+ if (AT2.isValid() && !AT2.matchesType(S.Context, Ex->getType()))
@@ -163,7 +165,7 @@ Index: tools/clang/lib/Driver/Tools.cpp
===================================================================
--- tools/clang/lib/Driver/Tools.cpp
+++ tools/clang/lib/Driver/Tools.cpp
-@@ -2991,6 +2991,7 @@ void Clang::ConstructJob(Compilation &C, const Job
+@@ -2984,6 +2984,7 @@ void Clang::ConstructJob(Compilation &C, const Job
// Forward -f (flag) options which we can pass directly.
Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
diff --git a/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp b/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp
index 0530a04..edc9016 100644
--- a/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp
+++ b/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp
@@ -2980,18 +2980,21 @@ CheckPrintfHandler::HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier
CoveredArgs.set(argIndex);
}
- // FreeBSD extensions
+ // FreeBSD kernel extensions.
if (CS.getKind() == ConversionSpecifier::FreeBSDbArg ||
CS.getKind() == ConversionSpecifier::FreeBSDDArg) {
- // claim the second argument
+ // We need at least two arguments.
+ if (!CheckNumArgs(FS, CS, startSpecifier, specifierLen, argIndex + 1))
+ return false;
+
+ // Claim the second argument.
CoveredArgs.set(argIndex + 1);
- // Now type check the data expression that matches the
- // format specifier.
+ // Type check the first argument (int for %b, pointer for %D)
const Expr *Ex = getDataArg(argIndex);
- const analyze_printf::ArgType &AT =
+ const analyze_printf::ArgType &AT =
(CS.getKind() == ConversionSpecifier::FreeBSDbArg) ?
- ArgType(S.Context.IntTy) : ArgType::CStrTy;
+ ArgType(S.Context.IntTy) : ArgType::CPointerTy;
if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType()))
S.Diag(getLocationOfByte(CS.getStart()),
diag::warn_printf_conversion_argument_type_mismatch)
@@ -2999,8 +3002,7 @@ CheckPrintfHandler::HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier
<< getSpecifierRange(startSpecifier, specifierLen)
<< Ex->getSourceRange();
- // Now type check the data expression that matches the
- // format specifier.
+ // Type check the second argument (char * for both %b and %D)
Ex = getDataArg(argIndex + 1);
const analyze_printf::ArgType &AT2 = ArgType::CStrTy;
if (AT2.isValid() && !AT2.matchesType(S.Context, Ex->getType()))
OpenPOWER on IntegriCloud