Development

#524 ([PATCH] removeCredential problem)

You must first sign up to be able to contribute.

Ticket #524 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] removeCredential problem

Reported by: artym@free.fr Assigned to: slickrick
Priority: major Milestone: 0.6.3
Component: Version: 0.6.1
Keywords: Cc:
Qualification:

Description

In sfBasicSecurityUser we have:

  public function removeCredential($credential)
  {
    if ($this->hasCredential($credential))
    {
      for ($i = 0, $z = count($this->credentials); $i < $z; $i++)
      {
        if ($credential == $this->credentials[$i])
        {
          if (sfConfig::get('sf_logging_active')) $this->getContext()->getLogger()->info('{sfUser} remove credential "'.$credential.'"');

          unset($this->credentials[$i]);
          return;
        }
      }
    }
  }

Now imagine you set cred1, then you set cred2, then you unset cred1:

The array will have indice 0 for cred1, then indice 1 for cred2 then you remove indice 0, now if you try to remove another credential it will iterate on credentials[0] only as there is only one credential, but this indice will issue a notice about unexistent indice.

Maybe a foreach would be sufficient to correct this, like:

  public function removeCredential($credential)
  {
    if ($this->hasCredential($credential))
    {
      foreach ($this->credentials as $indice => $current)
      {
        if ($credential == $current)
        {
          if (sfConfig::get('sf_logging_active')) $this->getContext()->getLogger()->info('{sfUser} remove credential "'.$credential.'"');

          unset($this->credentials[$indice]);
          return;
        }
      }
    }
  }

This may have been already corrected in 0.6.2 though, i didnt find a ticket about it but i'm not very familiar with trac.

Change History

05/10/06 11:31:44 changed by hartym

  • owner set to hartym.

Patch included is working

06/13/06 08:44:48 changed by slickrick

  • owner changed from hartym to slickrick.
  • summary changed from removeCredential problem to [PATCH] removeCredential problem.

Confirmed bug, tested patch, all works well. Thanks hartym.

Fixed in r1427

06/13/06 14:35:21 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

in r1438