From 4779cbca4f7e034ea215655fa42b7b2857d9049d Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" Date: Fri, 1 Dec 2006 15:55:24 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20356395:=20On=20bug=20creation,=20an=20err?= =?UTF-8?q?or=20is=20thrown=20when=20the=20requestee=20of=20a=20private=20?= =?UTF-8?q?attachment=20is=20not=20in=20the=20insidergroup,=20or=20when=20?= =?UTF-8?q?the=20requestee=20is=20not=20in=20the=20grant=20group=20(for=20?= =?UTF-8?q?attachment=20flags)=20-=20Patch=20by=20Fr=EF=BF=BD=EF=BF=BDd?= =?UTF-8?q?=EF=BF=BD=EF=BF=BDric=20Buclin=20=20r/a=3Dmy?= =?UTF-8?q?k?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webtools/bugzilla/Bugzilla/Attachment.pm | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/webtools/bugzilla/Bugzilla/Attachment.pm b/webtools/bugzilla/Bugzilla/Attachment.pm index c1b3a8a28e19..95d4026ad7ab 100644 --- a/webtools/bugzilla/Bugzilla/Attachment.pm +++ b/webtools/bugzilla/Bugzilla/Attachment.pm @@ -779,12 +779,6 @@ sub insert_attachment_for_bug { $$hr_vars->{'message'} = 'user_match_multiple'; } - # Flag::validate() should not detect any reference to existing flags - # when creating a new attachment. Setting the third param to -1 will - # force this function to check this point. - # XXX needs $throw_error treatment - Bugzilla::Flag::validate($cgi, $bug->bug_id, -1); - # Escape characters in strings that will be used in SQL statements. my $description = $cgi->param('description'); trick_taint($description); @@ -854,9 +848,28 @@ sub insert_attachment_for_bug { $timestamp, $fieldid, 0, 1)); } - # Create flags. my $attachment = Bugzilla::Attachment->get($attachid); - Bugzilla::Flag::process($bug, $attachment, $timestamp, $cgi); + + # 1. Add flags, if any. To avoid dying if something goes wrong + # while processing flags, we will eval() flag validation. + # This requires errors to die(). + # XXX: this can go away as soon as flag validation is able to + # fail without dying. + # + # 2. Flag::validate() should not detect any reference to existing flags + # when creating a new attachment. Setting the third param to -1 will + # force this function to check this point. + my $error_mode_cache = Bugzilla->error_mode; + Bugzilla->error_mode(ERROR_MODE_DIE); + eval { + Bugzilla::Flag::validate($cgi, $bug->bug_id, -1); + Bugzilla::Flag::process($bug, $attachment, $timestamp, $cgi); + }; + Bugzilla->error_mode($error_mode_cache); + if ($@) { + $$hr_vars->{'message'} = 'flag_creation_failed'; + $$hr_vars->{'flag_creation_error'} = $@; + } # Return the ID of the new attachment. return $attachid;