Support from Acquia helps fund testing for Drupal Acquia logo

Comments

soxofaan’s picture

Status: Needs review » Needs work

Good catches, thanks.

  1. +  if (!isset($_SESSION['captcha_success_form_ids'])) {
    +    $_SESSION['captcha_success_form_ids'] = array();
    +  }
       $captcha_success_form_ids = (array)($_SESSION['captcha_success_form_ids']);
    

    Good point, but I would do this like

       $captcha_success_form_ids = isset($_SESSION['captcha_success_form_ids']) ? (array)($_SESSION['captcha_success_form_ids']) : array();
    

    to avoid writing to $_SESSION when not needed.

  2. -    'solution' => $captcha['solution'],
    +    'solution' => isset($captcha['solution']) ? $captcha['solution'] : '',
    

    this looks strange. with what challenge module did you get an undefined index warning here?
    Anyway, if the solution is not set, I, think its a bit dangerous to leave it empty, as if the empty answer is the right one. I'll have to look into this.

  3. -  $csid = $form_state['clicked_button']['#post']['captcha_sid'];
    +  $csid = isset($form_state['clicked_button']['#post']['captcha_sid']) ? $form_state['clicked_button']['#post']['captcha_sid'] : 0;
     

    On which form did you get an undefined index warning here?

eMPee584’s picture

ooops totally forgot this issue when posting patch at #349218: Sometimes first character of image CAPTCHA is invisible: weird bug in PHP's bounding box calculation.. well regarding 1, yes sure better although i'm not sure about the cast.. 2) well it happens, form hickups with spam bots and everything... 3) same thing.. might be from aborted page calls or what not?! Just had couple of those in my watchdog table and thought, better make this spam bullet proof...

soxofaan’s picture

Status: Needs work » Postponed (maintainer needs more info)

reproduced problem 1) and committed fix in http://drupal.org/cvs?commit=256840, thanks

concerning 2) and 3) I really would like more info on how to reproduce. Your explanation in #2 is a bit fuzzy :) I immediately don't see how "hickups" and aborted page calls could cause "undefined indices" messages that would not show up on normal page calls in those cases.

For example:
for 2) which CAPTCHA type are you using?
for 3) on which form_ids do you have a CAPTCHA?

eMPee584’s picture

Status: Postponed (maintainer needs more info) » Needs work

well using image captchas, pretty much for all anon form submissions..
thing is, stuff like this ain't always reproducible. i catch those errors from my watchdog, look what causes them, fix/retry and during that usually find some more ;/
so, if you really want to know the exact circumstances of when these occured, maybe i'll put in some debug code. But not right now *g

soxofaan’s picture

Status: Needs work » Postponed (maintainer needs more info)

3) is related to #534168: Submit with "return"/"enter" key in IE7 leads to failing CAPTCHA and it will be solved over there

The remaining thing is 2):

-    'solution' => $captcha['solution'],
+    'solution' => isset($captcha['solution']) ? $captcha['solution'] : '',

I'd like instruction on how to reproduce this because if $captcha['solution'] is not set, something is seriously wrong. Ignoring this by just blindly setting the solution to an empty string is a bad idea IMHO.

eMPee584’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.5 KB

Wow now after wasting quite some time on doing that (grokking 3).. how trivial is this one. Think about it ;D

soxofaan’s picture

Status: Needs review » Postponed (maintainer needs more info)

Can you describe what bug the patch is trying to fix?

-    if (!$captcha) {
+    if (empty($captcha)) {

Why this change? According to the PHP documentation (http://www.php.net/manual/en/function.empty.php, http://php.net/manual/en/language.types.boolean.php), there is not much difference in this context ($captcha should be an array).

 
+    // Store information for usage in the validation and pre_render phase.
+    $element['#captcha_info'] = array(
+      'form_id' => $this_form_id,
+      'module' => $captcha_type_module,
+      'type' => $captcha_type_challenge,
+      'captcha_sid' => $captcha_sid,
+      'solution' => $captcha['solution'],
+    );
   }
 
-  // Store information for usage in the validation and pre_render phase.
-  $element['#captcha_info'] = array(
-    'form_id' => $this_form_id,
-    'module' => $captcha_type_module,
-    'type' => $captcha_type_challenge,
-    'captcha_sid' => $captcha_sid,
-    'solution' => $captcha['solution'],
-  );
-

Why this move? What is the bug here?

eMPee584’s picture

Status: Postponed (maintainer needs more info) » Needs review

> Can you describe what bug the patch is trying to fix?
number 3 was still unanswered, right?

-    if (!$captcha) {
+    if (empty($captcha)) {
Why this change?

Only cosmetic. Of course it works to apply an implicit boolean comparison on an array. But it is ugly, imho-

+    // Store information for usage in the validation and pre_render phase.
+    $element['#captcha_info'] = array(
+      'form_id' => $this_form_id,
+      'module' => $captcha_type_module,
+      'type' => $captcha_type_challenge,
+      'captcha_sid' => $captcha_sid,
+      'solution' => $captcha['solution'],
+    );
   }

-  // Store information for usage in the validation and pre_render phase.
-  $element['#captcha_info'] = array(
-    'form_id' => $this_form_id,
-    'module' => $captcha_type_module,
-    'type' => $captcha_type_challenge,
-    'captcha_sid' => $captcha_sid,
-    'solution' => $captcha['solution'],
-  );
-
Why this move? What is the bug here?

This is still about point 3)... Please, have a look at that function again. Try to regrok it (hint: if statement can evaluate to false too - for good reason..) and you'll lol too ;-p

soxofaan’s picture

Category: bug » task
FileSize
2.57 KB

the $element['#captcha_info'] stuff is outside the if body, because that information could also be used by other "consumers" than the validate and prerender handlers. The documentation does not mention that, so I understand the misunderstanding :). Apart from that, 'solution' => $captcha['solution'] is indeed undefined when the if condition evaluates to false, so can cause "undefined indices" problems.

Anyway, I worked a bit on your patch

soxofaan’s picture

reroll
(and hopefully the testbot will pick this up)

soxofaan’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.