bug80111.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. Bug #80111: PHP SplDoublyLinkedList::offsetUnset UAF Sandbox Escape
  3. --FILE--
  4. <?php
  5. function i2s(&$s, $p, $i, $x=8)
  6. {
  7. for($j=0;$j<$x;$j++)
  8. {
  9. $s[$p+$j] = chr($i & 0xff);
  10. $i >>= 8;
  11. }
  12. }
  13. class Trigger
  14. {
  15. function __destruct()
  16. {
  17. global $s, $b;
  18. # Add a reference afterwards
  19. //$v = new SplDoublyLinkedList();
  20. //$v->setIteratorMode(SplDoublyLinkedList::IT_MODE_DELETE);
  21. # Remove element #2 from the list: this has no effect on
  22. # intern->traverse_pointer, since it is removed from the list already
  23. # The element, along with the zval, is freed
  24. unset($s[0]);
  25. $a = str_shuffle(str_repeat('A', 40-24-1));
  26. # Build a fake zval (long, value: 12345678)
  27. i2s($a, 0x00, 12345678); # ptr
  28. i2s($a, 0x08, 4, 7); # type: long
  29. var_dump($s->current());
  30. $s->next();
  31. # The value is our fake zval
  32. var_dump($s->current());
  33. print_r('DONE'."\n");
  34. }
  35. }
  36. # Create a 3-item dllist
  37. $s = new SplDoublyLinkedList();
  38. # This is the UAF trigger
  39. $s->push(new Trigger());
  40. #$b = &$a;
  41. $s->push(3);
  42. # Points intern->traverse_pointer to our object element
  43. $s->rewind();
  44. #$s->next();
  45. # calls SplDoublyLinkedList::offsetUnset, which will remove the element from the
  46. # dllist, and then destruct the object, before clearing traverse_pointer
  47. unset($s[0]);
  48. ?>
  49. --EXPECT--
  50. NULL
  51. NULL
  52. DONE