]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1517606 - Infinite loop in Bugzilla::Extension::BMO::_inject_headers_into_body()
authorDylan William Hardison <dylan@hardison.net>
Fri, 4 Jan 2019 15:41:47 +0000 (10:41 -0500)
committerGitHub <noreply@github.com>
Fri, 4 Jan 2019 15:41:47 +0000 (10:41 -0500)
extensions/BMO/Extension.pm

index 03857b2b7a656765e86eb14dcc62db5f750d9299..d19d9e4db61f8b480da9e70eed7f61533d706adc 100644 (file)
@@ -1790,20 +1790,18 @@ sub _inject_headers_into_body {
 
         # these aren't real fields, but exist in the headers
         push @fields, ('Comment Created', 'Attachment Created');
-        @fields = sort { length($b) <=> length($a) } @fields;
-        while ($value ne '') {
-          foreach my $field (@fields) {
-            if ($value eq $field) {
-              push @headers, "$name: $field";
-              $value = '';
-              last;
-            }
-            if (substr($value, 0, length($field) + 1) eq $field . ' ') {
-              push @headers, "$name: $field";
-              $value = substr($value, length($field) + 1);
-              last;
-            }
-          }
+
+        # The fields should be in longest to shortest order
+        my @sorted_fields = sort { length($b) <=> length($a) } @fields;
+
+        # A field matches if it ends with a space or the end-of-string.
+        my @regexp_fields = map { '(' . quotemeta($_) . ')(?:\s|$)' } @sorted_fields;
+        my $fields_regexp = join('|', @regexp_fields);
+
+        # //g matches all patterns and the grep ensures we only get matches.
+        my @extracted_fields = grep { defined($_) } $value =~ /$fields_regexp/g;
+        foreach my $field (@extracted_fields) {
+          push @headers, "$name: $field";
         }
       }
       else {
@@ -1845,6 +1843,7 @@ sub _inject_headers_into_body {
   }
   elsif (!$email->content_type || $email->content_type =~ /^text\/(?:html|plain)/)
   {
+
     # text-only email
     _replace_placeholder_in_part($email, $replacement);
   }