[PATCH] D116722: [clang] Verify ssp buffer size is a valid integer
Alex via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 5 20:48:26 PST 2022
alextsao1999 created this revision.
alextsao1999 added a reviewer: compnerd.
alextsao1999 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch adds to verify whether the ssp buffer size is a legal integer and a new diagnostic driver kind has been added.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116722
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Clang.cpp
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3187,14 +3187,26 @@
CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
}
+ auto IsInteger = [](StringRef Str) -> bool {
+ if (Str.empty())
+ return false;
+ for (auto &Chr : Str)
+ if (Chr < '0' || Chr > '9')
+ return false;
+ return true;
+ };
+
// --param ssp-buffer-size=
for (const Arg *A : Args.filtered(options::OPT__param)) {
StringRef Str(A->getValue());
if (Str.startswith("ssp-buffer-size=")) {
if (StackProtectorLevel) {
- CmdArgs.push_back("-stack-protector-buffer-size");
- // FIXME: Verify the argument is a valid integer.
- CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
+ auto BufferSize = Str.drop_front(16);
+ if (IsInteger(BufferSize)) {
+ CmdArgs.push_back("-stack-protector-buffer-size");
+ CmdArgs.push_back(Args.MakeArgString(BufferSize));
+ } else
+ D.Diag(clang::diag::err_invalid_ssp_buffer_size);
}
A->claim();
}
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -278,6 +278,8 @@
DefaultError;
def err_invalid_macos_32bit_deployment_target : Error<
"32-bit targets are not supported when building for Mac Catalyst">;
+def err_invalid_ssp_buffer_size : Error<
+ "ssp buffer size is not valid">;
def err_drv_invalid_os_in_arg : Error<"invalid OS value '%0' in '%1'">;
def err_drv_conflicting_deployment_targets : Error<
"conflicting deployment targets, both '%0' and '%1' are present in environment">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116722.397784.patch
Type: text/x-patch
Size: 1907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220106/589ed848/attachment.bin>
More information about the cfe-commits
mailing list