Re: [PHP] Reading class variable value always returns NULL

2012-08-15 Thread Reto Kaiser
So here's some new observations on the instance variables being NULL.
As far as we found out this is the sequence of events:

1. Apache (MPM) received request A which executes a php script.
2. Within this script during the unserialization of an object an
exception is thrown.
3. This exception is catched and an error message is display to
standard output with echo.
4. The script ends normally and the standard output contents are
returned in the HTTP response.
5. From now on this Apache worker is tainted, meaning that every
subsequent request will result in:

6. The same apache worker receives request B which executes a PHP script.
7. Within this PHP script reading instance variables will always
return NULL, e.g.:

?php
class A{}
$a = new A();
$a-foo = 1;
// Now: $a-foo === NULL

All subsequent requests to this apache worker will behave like this.
The constellation leading to this behavior is very hard to further
simplify. If we throw different exceptions, or unserialize different
objects it doesn't happen anymore...


As a workaround we added exit; to the end of our php script. With a
call to exit the apache worker will not get tainted...

Regards,
 Reto



On Tue, Aug 14, 2012 at 11:52 PM, Reto Kaiser r...@cargomedia.ch wrote:
 Hey,

 We have:
 error_reporting((E_ALL | E_STRICT)  ~(E_NOTICE | E_USER_NOTICE));

 Displaying errors is disabled:
 display_errors = Off

 We have a custom error handler which logs all errors to a file.
 In this file we receive byeffect errors, like that the second argument
 to array_key_exists should be array, but is NULL. When we further
 debug the reason is that the second argument is an instance variable,
 and all instance variables are NULL.
 We're pretty sure this is a software bug, since it only happens from
 time to time, and already happens in the first line of the php script,
 when none of our application code was loaded.
 For example:

 ?php
 class A{}
 $a = new A();
 $a-foo = 1;
 if ($a-foo === null) {
  throw new Exception(strange);
 }

 will throw an exception.

 Since it only happens from time to time, it is really hard to debug.
 We're now trying to reproduce in a virtual machine environment, while
 replaying the actual requests that our webserver received. When we're
 just simulating random load on the web server it doesn't happen. So it
 must have something to do with certain requests, and they must have
 some strange byeffect on php, or mod_php or something related.

 Any input welcome!

 Thanks,
  Reto

 On Tue, Aug 14, 2012 at 11:11 PM, Jim Lucas li...@cmsws.com wrote:
 On 08/12/2012 05:32 AM, Reto Kaiser wrote:

 Hi,

 So I have this strange situation where I assign a classvariable a
 value, but when I read the value it is NULL.

 Does anyone have an idea what could cause this, or how to further debug?

 Thanks,
   Reto


 What is your error reporting set to?

 Do you have display errors turned on?

 Are you saving your errors to a log file?

 --
 Jim Lucas

 http://www.cmsws.com/
 http://www.cmsws.com/examples/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading class variable value always returns NULL

2012-08-15 Thread Philipp Gysin
As a little clarification: The Apache server in question is configured as a
MPM prefork.


On Wed, Aug 15, 2012 at 4:28 PM, Reto Kaiser r...@cargomedia.ch wrote:

 So here's some new observations on the instance variables being NULL.
 As far as we found out this is the sequence of events:

 1. Apache (MPM) received request A which executes a php script.
 2. Within this script during the unserialization of an object an
 exception is thrown.
 3. This exception is catched and an error message is display to
 standard output with echo.
 4. The script ends normally and the standard output contents are
 returned in the HTTP response.
 5. From now on this Apache worker is tainted, meaning that every
 subsequent request will result in:

 6. The same apache worker receives request B which executes a PHP script.
 7. Within this PHP script reading instance variables will always
 return NULL, e.g.:

 ?php
 class A{}
 $a = new A();
 $a-foo = 1;
 // Now: $a-foo === NULL

 All subsequent requests to this apache worker will behave like this.
 The constellation leading to this behavior is very hard to further
 simplify. If we throw different exceptions, or unserialize different
 objects it doesn't happen anymore...


 As a workaround we added exit; to the end of our php script. With a
 call to exit the apache worker will not get tainted...

 Regards,
  Reto



 On Tue, Aug 14, 2012 at 11:52 PM, Reto Kaiser r...@cargomedia.ch wrote:
  Hey,
 
  We have:
  error_reporting((E_ALL | E_STRICT)  ~(E_NOTICE | E_USER_NOTICE));
 
  Displaying errors is disabled:
  display_errors = Off
 
  We have a custom error handler which logs all errors to a file.
  In this file we receive byeffect errors, like that the second argument
  to array_key_exists should be array, but is NULL. When we further
  debug the reason is that the second argument is an instance variable,
  and all instance variables are NULL.
  We're pretty sure this is a software bug, since it only happens from
  time to time, and already happens in the first line of the php script,
  when none of our application code was loaded.
  For example:
 
  ?php
  class A{}
  $a = new A();
  $a-foo = 1;
  if ($a-foo === null) {
   throw new Exception(strange);
  }
 
  will throw an exception.
 
  Since it only happens from time to time, it is really hard to debug.
  We're now trying to reproduce in a virtual machine environment, while
  replaying the actual requests that our webserver received. When we're
  just simulating random load on the web server it doesn't happen. So it
  must have something to do with certain requests, and they must have
  some strange byeffect on php, or mod_php or something related.
 
  Any input welcome!
 
  Thanks,
   Reto
 
  On Tue, Aug 14, 2012 at 11:11 PM, Jim Lucas li...@cmsws.com wrote:
  On 08/12/2012 05:32 AM, Reto Kaiser wrote:
 
  Hi,
 
  So I have this strange situation where I assign a classvariable a
  value, but when I read the value it is NULL.
 
  Does anyone have an idea what could cause this, or how to further
 debug?
 
  Thanks,
Reto
 
 
  What is your error reporting set to?
 
  Do you have display errors turned on?
 
  Are you saving your errors to a log file?
 
  --
  Jim Lucas
 
  http://www.cmsws.com/
  http://www.cmsws.com/examples/



Re: [PHP] Reading class variable value always returns NULL

2012-08-14 Thread Reto Kaiser
Hi,

Thanks for your input Robert and Volmar! I have googled again with
instance variable instead of class variable - but have not found
any similar reports.

I'm pretty sure those are the same objects. The application usually
runs alright. We only see the instance variables becoming NULL since
about a week.

We had 3 small software upgrade coming from debian since we observe
the problem. We think they cannot be related. Still we have reverted
all of those and still see the problem.
Next step is that we setup a exact copy of the machine. Maybe it is a
hardware problem...

Thanks,
 Reto

On Mon, Aug 13, 2012 at 5:09 PM, Robert Cummings rob...@interjinn.com wrote:
 On 12-08-12 08:32 AM, Reto Kaiser wrote:

 Hi,

 So I have this strange situation where I assign a classvariable a
 value, but when I read the value it is NULL.

 The class has one variable declared:
 =
 class A {
  private $_cookies;
 }
 =


 That is a private instance variable NOT a class variable.

 To declare a class variable you would do the following:

 ?php

 class A
 {
 private static $_cookies;
 }

 ?


 In a method of this class I assign this classvariable plus an
 undeclared classvariable and a local variable the value 1:
 =
 $this-_cookies = 1;
 $this-_cookies2 = 1;
 $cookies3 = 1;
 =

 When I now read the values of those variables, the classvariables are
 NULL while the local variable is 1:
 =
 $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL;
 $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL;
 $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
 =
 cookies: NULL
 cookies2: NULL
 cookies3: 1
 =

 But when reading the whole object, the classvariables are 1:
 =
 $logEntry .= var_export($this, true) . PHP_EOL;
 =
 A::__set_state(array(
 '_cookies' = 1,
 '_cookies2' = 1,
 ))
 =


 This happens periodically on a busy webserver. It seems that when it
 happens, all classvariables cannot be read anymore (return NULL).
 After restarting Apache it does not happen anymore, just to happen
 again after some minutes.

 The system is current Debian Squeeze:
 Linux: linux-image-2.6.32-5-amd64
 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
 2012 07:31:32)
 php -m:
 https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
 php -i:
 https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt

 Does anyone have an idea what could cause this, or how to further debug?


 I can't really speak to your specific problem (unless you're using two
 different instances of the class), just thought I'd clear up the difference
 between class variables and instance variables.

 Cheers,
 Rob.
 --
 E-Mail Disclaimer: Information contained in this message and any
 attached documents is considered confidential and legally protected.
 This message is intended solely for the addressee(s). Disclosure,
 copying, and distribution are prohibited unless authorized.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading class variable value always returns NULL

2012-08-14 Thread Reto Kaiser
Hi,

We have since deployed another webserver machine and observe the exact
same behavior there.
So it is not a hardware problem.

We have also disabled various php modules, but this didn't help either.

Any debug suggestions are welcome! :)

Reto

On Tue, Aug 14, 2012 at 10:40 AM, Reto Kaiser r...@cargomedia.ch wrote:
 Hi,

 Thanks for your input Robert and Volmar! I have googled again with
 instance variable instead of class variable - but have not found
 any similar reports.

 I'm pretty sure those are the same objects. The application usually
 runs alright. We only see the instance variables becoming NULL since
 about a week.

 We had 3 small software upgrade coming from debian since we observe
 the problem. We think they cannot be related. Still we have reverted
 all of those and still see the problem.
 Next step is that we setup a exact copy of the machine. Maybe it is a
 hardware problem...

 Thanks,
  Reto

 On Mon, Aug 13, 2012 at 5:09 PM, Robert Cummings rob...@interjinn.com wrote:
 On 12-08-12 08:32 AM, Reto Kaiser wrote:

 Hi,

 So I have this strange situation where I assign a classvariable a
 value, but when I read the value it is NULL.

 The class has one variable declared:
 =
 class A {
  private $_cookies;
 }
 =


 That is a private instance variable NOT a class variable.

 To declare a class variable you would do the following:

 ?php

 class A
 {
 private static $_cookies;
 }

 ?


 In a method of this class I assign this classvariable plus an
 undeclared classvariable and a local variable the value 1:
 =
 $this-_cookies = 1;
 $this-_cookies2 = 1;
 $cookies3 = 1;
 =

 When I now read the values of those variables, the classvariables are
 NULL while the local variable is 1:
 =
 $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL;
 $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL;
 $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
 =
 cookies: NULL
 cookies2: NULL
 cookies3: 1
 =

 But when reading the whole object, the classvariables are 1:
 =
 $logEntry .= var_export($this, true) . PHP_EOL;
 =
 A::__set_state(array(
 '_cookies' = 1,
 '_cookies2' = 1,
 ))
 =


 This happens periodically on a busy webserver. It seems that when it
 happens, all classvariables cannot be read anymore (return NULL).
 After restarting Apache it does not happen anymore, just to happen
 again after some minutes.

 The system is current Debian Squeeze:
 Linux: linux-image-2.6.32-5-amd64
 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
 2012 07:31:32)
 php -m:
 https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
 php -i:
 https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt

 Does anyone have an idea what could cause this, or how to further debug?


 I can't really speak to your specific problem (unless you're using two
 different instances of the class), just thought I'd clear up the difference
 between class variables and instance variables.

 Cheers,
 Rob.
 --
 E-Mail Disclaimer: Information contained in this message and any
 attached documents is considered confidential and legally protected.
 This message is intended solely for the addressee(s). Disclosure,
 copying, and distribution are prohibited unless authorized.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading class variable value always returns NULL

2012-08-14 Thread Robert Williams
I'm not real clear on what's happening. Are you saying that if you assign
values to the protected class members, and then immediately read them,
that they're null? So, there's code something like this:

class Foo {
   public function Something() {
  $this-foo = 1;

  //shows null instead of 1
  var_dump($this-foo);
   }

   protected $foo;
}



Is that right?


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading class variable value always returns NULL

2012-08-14 Thread Jim Lucas

On 08/12/2012 05:32 AM, Reto Kaiser wrote:

Hi,

So I have this strange situation where I assign a classvariable a
value, but when I read the value it is NULL.

Does anyone have an idea what could cause this, or how to further debug?

Thanks,
  Reto



What is your error reporting set to?

Do you have display errors turned on?

Are you saving your errors to a log file?

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading class variable value always returns NULL

2012-08-14 Thread Reto Kaiser
Hey,

We have:
error_reporting((E_ALL | E_STRICT)  ~(E_NOTICE | E_USER_NOTICE));

Displaying errors is disabled:
display_errors = Off

We have a custom error handler which logs all errors to a file.
In this file we receive byeffect errors, like that the second argument
to array_key_exists should be array, but is NULL. When we further
debug the reason is that the second argument is an instance variable,
and all instance variables are NULL.
We're pretty sure this is a software bug, since it only happens from
time to time, and already happens in the first line of the php script,
when none of our application code was loaded.
For example:

?php
class A{}
$a = new A();
$a-foo = 1;
if ($a-foo === null) {
 throw new Exception(strange);
}

will throw an exception.

Since it only happens from time to time, it is really hard to debug.
We're now trying to reproduce in a virtual machine environment, while
replaying the actual requests that our webserver received. When we're
just simulating random load on the web server it doesn't happen. So it
must have something to do with certain requests, and they must have
some strange byeffect on php, or mod_php or something related.

Any input welcome!

Thanks,
 Reto

On Tue, Aug 14, 2012 at 11:11 PM, Jim Lucas li...@cmsws.com wrote:
 On 08/12/2012 05:32 AM, Reto Kaiser wrote:

 Hi,

 So I have this strange situation where I assign a classvariable a
 value, but when I read the value it is NULL.

 Does anyone have an idea what could cause this, or how to further debug?

 Thanks,
   Reto


 What is your error reporting set to?

 Do you have display errors turned on?

 Are you saving your errors to a log file?

 --
 Jim Lucas

 http://www.cmsws.com/
 http://www.cmsws.com/examples/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading class variable value always returns NULL

2012-08-13 Thread Robert Cummings

On 12-08-12 08:32 AM, Reto Kaiser wrote:

Hi,

So I have this strange situation where I assign a classvariable a
value, but when I read the value it is NULL.

The class has one variable declared:
=
class A {
 private $_cookies;
}
=


That is a private instance variable NOT a class variable.

To declare a class variable you would do the following:

?php

class A
{
private static $_cookies;
}

?


In a method of this class I assign this classvariable plus an
undeclared classvariable and a local variable the value 1:
=
$this-_cookies = 1;
$this-_cookies2 = 1;
$cookies3 = 1;
=

When I now read the values of those variables, the classvariables are
NULL while the local variable is 1:
=
$logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL;
$logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL;
$logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
=
cookies: NULL
cookies2: NULL
cookies3: 1
=

But when reading the whole object, the classvariables are 1:
=
$logEntry .= var_export($this, true) . PHP_EOL;
=
A::__set_state(array(
'_cookies' = 1,
'_cookies2' = 1,
))
=


This happens periodically on a busy webserver. It seems that when it
happens, all classvariables cannot be read anymore (return NULL).
After restarting Apache it does not happen anymore, just to happen
again after some minutes.

The system is current Debian Squeeze:
Linux: linux-image-2.6.32-5-amd64
Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
2012 07:31:32)
php -m: 
https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
php -i: 
https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt

Does anyone have an idea what could cause this, or how to further debug?


I can't really speak to your specific problem (unless you're using two 
different instances of the class), just thought I'd clear up the 
difference between class variables and instance variables.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading class variable value always returns NULL

2012-08-13 Thread Volmar Machado
It's only a hint, but You start checking if the Object Ids are the same or not.

2012/8/13 Robert Cummings rob...@interjinn.com:
 On 12-08-12 08:32 AM, Reto Kaiser wrote:

 Hi,

 So I have this strange situation where I assign a classvariable a
 value, but when I read the value it is NULL.

 The class has one variable declared:
 =
 class A {
  private $_cookies;
 }
 =


 That is a private instance variable NOT a class variable.

 To declare a class variable you would do the following:

 ?php

 class A
 {
 private static $_cookies;
 }

 ?


 In a method of this class I assign this classvariable plus an
 undeclared classvariable and a local variable the value 1:
 =
 $this-_cookies = 1;
 $this-_cookies2 = 1;
 $cookies3 = 1;
 =

 When I now read the values of those variables, the classvariables are
 NULL while the local variable is 1:
 =
 $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL;
 $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL;
 $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
 =
 cookies: NULL
 cookies2: NULL
 cookies3: 1
 =

 But when reading the whole object, the classvariables are 1:
 =
 $logEntry .= var_export($this, true) . PHP_EOL;
 =
 A::__set_state(array(
 '_cookies' = 1,
 '_cookies2' = 1,
 ))
 =


 This happens periodically on a busy webserver. It seems that when it
 happens, all classvariables cannot be read anymore (return NULL).
 After restarting Apache it does not happen anymore, just to happen
 again after some minutes.

 The system is current Debian Squeeze:
 Linux: linux-image-2.6.32-5-amd64
 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
 2012 07:31:32)
 php -m:
 https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
 php -i:
 https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt

 Does anyone have an idea what could cause this, or how to further debug?


 I can't really speak to your specific problem (unless you're using two
 different instances of the class), just thought I'd clear up the difference
 between class variables and instance variables.

 Cheers,
 Rob.
 --
 E-Mail Disclaimer: Information contained in this message and any
 attached documents is considered confidential and legally protected.
 This message is intended solely for the addressee(s). Disclosure,
 copying, and distribution are prohibited unless authorized.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php