]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Prevent another potential stack overflow issue when demangling a maliciouslt mangled...
authorNick Clifton <nickc@redhat.com>
Mon, 4 Jul 2022 10:05:03 +0000 (11:05 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 4 Jul 2022 10:05:03 +0000 (11:05 +0100)
libiberty/
* rust-demangle.c (demangle_path_maybe_open_generics): Add
recursion limit.

libiberty/rust-demangle.c

index 36afcfae2780499f5db38e76b94eb24b3da4e0a7..d6daf23af27a80ae0dbad5f04c43e86a0ecce60c 100644 (file)
@@ -1082,6 +1082,18 @@ demangle_path_maybe_open_generics (struct rust_demangler *rdm)
   if (rdm->errored)
     return open;
 
+  if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
+    {
+      ++ rdm->recursion;
+      if (rdm->recursion > RUST_MAX_RECURSION_COUNT)
+       {
+         /* FIXME: There ought to be a way to report
+            that the recursion limit has been reached.  */
+         rdm->errored = 1;
+         goto end_of_func;
+       }
+    }
+
   if (eat (rdm, 'B'))
     {
       backref = parse_integer_62 (rdm);
@@ -1107,6 +1119,11 @@ demangle_path_maybe_open_generics (struct rust_demangler *rdm)
     }
   else
     demangle_path (rdm, 0);
+
+ end_of_func:
+  if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
+    -- rdm->recursion;
+
   return open;
 }