[PATCH] D116722: [clang] Verify ssp buffer size is a valid integer

Alex via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 8 11:20:08 PST 2022


alextsao1999 updated this revision to Diff 398354.
alextsao1999 added a comment.

update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116722/new/

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,27 @@
     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=")) {
+    auto StrSplit = Str.split('=');
+    if (StrSplit.first.equals("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)));
+        if (IsInteger(StrSplit.second)) {
+          CmdArgs.push_back("-stack-protector-buffer-size");
+          CmdArgs.push_back(Args.MakeArgString(StrSplit.second));
+        } 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.398354.patch
Type: text/x-patch
Size: 1973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220108/291243bc/attachment.bin>


More information about the cfe-commits mailing list