Nikita Popov
11e050920d
Fix memory unsafety in array_walk()
...
Fixes bugs #61967 , #62607 , #69068 , #70713 .
The primary changes are:
a) Use the ht_iterator mechanism to ensure safety not only if the
iterated array itself changes, but also if it is replaced (and
potentially destroyed) entirely. We use the same semantics for
behavior under modification as foreach-by-reference. In
particular, we advance to the next element before processing it.
If the iterated entity is exchanged we iterate the new one from
the start. If it is not an array/object we warn and abort.
b) Always create a reference to the current value. Previously the
code kept the value as a non-reference and updated it to the
reference value produced by the user callback. However this is
unsafe, as the array may have been reallocated in the meantime,
so the previous value pointer is no longer value.
c) Around a recursive walk, incref the reference containing the
array. This ensures that the location where the currently
iterated value is stored cannot be freed.
One problem I was not able to solve is that we cannot decrement
the apply count if the array is exchanged during a recursive walk.
2016-07-30 00:15:32 +02:00
..
2015-01-14 18:02:41 +08:00
2015-03-31 17:55:27 +02:00
2015-02-24 17:40:25 +03:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2010-04-26 00:13:34 +00:00
2011-12-12 13:31:43 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2009-02-14 10:32:26 +00:00
2013-07-06 20:50:34 +00:00
2013-04-21 22:35:04 -07:00
2016-04-16 09:59:01 +02:00
2013-04-01 19:11:45 +08:00
2016-04-16 09:59:01 +02:00
2015-06-27 07:35:44 +08:00
2013-04-22 16:19:21 -07:00
2010-08-27 03:54:10 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2013-06-10 14:30:59 -07:00
2010-08-27 03:54:10 +00:00
2010-08-27 03:54:10 +00:00
2012-10-10 10:27:49 +08:00
2008-12-02 13:32:53 +00:00
2013-08-04 16:05:36 -07:00
2012-10-10 10:27:49 +08:00
2008-12-02 13:32:53 +00:00
2008-12-05 12:42:15 +00:00
2014-12-19 05:06:54 +03:00
2013-06-10 14:30:59 -07:00
2013-11-12 22:02:51 +01:00
2013-06-10 13:36:17 -07:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2012-10-10 10:27:49 +08:00
2010-05-24 14:11:39 +00:00
2010-05-24 14:11:39 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2013-06-10 14:30:59 -07:00
2013-11-12 22:02:51 +01:00
2013-09-28 00:06:03 +08:00
2014-12-21 13:23:02 +00:00
2016-06-16 02:32:02 +03:00
2014-12-21 13:23:02 +00:00
2010-01-24 14:38:34 +00:00
2015-03-31 17:55:27 +02:00
2013-06-10 14:30:59 -07:00
2013-06-10 14:30:59 -07:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2011-10-21 06:08:47 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-05 12:42:15 +00:00
2008-12-05 12:42:15 +00:00
2013-06-10 14:30:59 -07:00
2013-06-10 14:30:59 -07:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2015-01-14 18:02:41 +08:00
2009-04-24 17:14:32 +00:00
2009-04-24 17:14:32 +00:00
2014-12-21 13:23:02 +00:00
2010-04-26 00:13:34 +00:00
2014-12-21 13:23:02 +00:00
2014-08-15 18:44:39 +02:00
2014-10-16 14:44:35 +02:00
2015-01-05 17:27:25 -07:00
2016-06-16 02:32:02 +03:00
2015-04-01 11:17:55 +02:00
2015-04-03 16:35:06 +03:00
2009-02-13 22:01:28 +00:00
2016-06-16 02:32:02 +03:00
2016-06-16 02:32:02 +03:00
2010-10-01 11:53:04 +00:00
2013-06-10 14:30:59 -07:00
2016-07-29 19:07:04 +02:00
2010-04-26 00:13:34 +00:00
2013-06-10 13:36:17 -07:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2016-06-23 20:58:45 +08:00
2016-06-23 20:58:45 +08:00
2016-06-23 20:58:45 +08:00
2011-08-29 20:23:34 +00:00
2011-08-29 20:23:34 +00:00
2015-04-01 11:17:55 +02:00
2008-12-02 13:32:53 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2009-07-15 13:44:14 +00:00
2013-06-10 14:30:59 -07:00
2014-12-21 13:23:02 +00:00
2009-06-07 19:28:15 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2015-01-17 18:50:28 +00:00
2015-01-17 18:50:28 +00:00
2016-07-06 12:35:13 +01:00
2008-12-02 13:32:53 +00:00
2016-06-16 02:32:02 +03:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2014-12-21 13:23:02 +00:00
2014-11-19 20:23:00 +00:00
2014-12-21 13:23:02 +00:00
2015-04-01 11:17:55 +02:00
2015-04-01 11:17:55 +02:00
2008-12-30 16:49:43 +00:00
2014-12-21 13:23:02 +00:00
2009-06-05 17:15:33 +00:00
2010-04-26 00:13:34 +00:00
2014-12-21 13:23:02 +00:00
2015-06-16 18:02:45 +02:00
2014-12-21 13:23:02 +00:00
2015-01-17 18:50:28 +00:00
2015-03-31 17:55:27 +02:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2016-06-16 02:32:02 +03:00
2015-01-28 22:54:17 +01:00
2015-03-31 17:55:27 +02:00
2008-12-02 13:32:53 +00:00
2015-03-31 17:55:27 +02:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2016-06-16 02:32:02 +03:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2016-06-16 02:32:02 +03:00
2008-12-02 13:32:53 +00:00
2015-03-31 17:55:27 +02:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2016-06-16 02:32:02 +03:00
2015-03-31 17:55:27 +02:00
2008-12-02 13:32:53 +00:00
2015-03-31 17:55:27 +02:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2016-06-16 02:32:02 +03:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2016-06-16 02:32:02 +03:00
2008-12-12 23:59:48 +00:00
2014-12-21 13:23:02 +00:00
2013-06-10 14:30:59 -07:00
2009-04-24 17:14:32 +00:00
2015-01-16 15:21:21 +08:00
2015-01-16 17:12:50 +08:00
2014-12-21 13:23:02 +00:00
2009-07-15 13:44:14 +00:00
2013-06-10 14:30:59 -07:00
2015-01-14 18:02:41 +08:00
2008-12-02 13:32:53 +00:00
2014-12-21 13:23:02 +00:00
2010-04-02 21:44:09 +00:00
2010-04-26 00:13:34 +00:00
2013-07-15 00:23:03 -07:00
2013-06-10 13:36:17 -07:00
2013-06-26 13:36:36 -03:00
2016-06-16 02:32:02 +03:00
2009-04-24 17:14:32 +00:00
2009-04-24 17:14:32 +00:00
2009-04-24 17:14:32 +00:00
2013-06-10 13:36:17 -07:00
2016-06-16 02:32:02 +03:00
2009-04-24 17:14:32 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2011-08-29 20:23:34 +00:00
2015-05-17 17:31:43 -05:00
2015-05-17 17:31:43 -05:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2015-01-15 14:23:47 +08:00
2012-02-12 08:01:25 +00:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2011-08-29 20:23:34 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2015-01-15 14:23:47 +08:00
2011-12-13 23:04:01 +00:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2012-10-10 10:27:49 +08:00
2015-07-23 12:14:34 +08:00
2015-07-23 12:14:34 +08:00
2014-08-27 00:31:20 +02:00
2012-10-10 10:31:31 +08:00
2012-10-10 10:27:49 +08:00
2013-06-12 13:13:48 +02:00
2012-10-10 10:27:49 +08:00
2013-07-15 00:23:03 -07:00
2013-07-15 00:23:03 -07:00
2012-10-10 10:27:49 +08:00
2012-10-10 10:27:49 +08:00
2010-12-12 19:27:04 +00:00
2010-12-12 19:27:04 +00:00
2015-05-17 18:47:06 +02:00
2015-01-14 18:02:41 +08:00
2015-04-01 11:17:55 +02:00
2013-06-10 14:30:59 -07:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2009-07-21 21:15:48 +00:00
2015-03-31 17:55:27 +02:00
2008-12-27 03:06:57 +00:00
2009-05-10 20:12:56 +00:00
2011-04-06 10:16:14 +00:00
2009-07-08 18:23:08 +00:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2010-06-11 08:53:31 +00:00
2010-08-04 23:11:44 +00:00
2012-03-02 18:05:38 +00:00
2011-04-06 10:23:06 +00:00
2012-03-02 03:40:40 +00:00
2016-07-30 00:15:32 +02:00
2016-07-30 00:15:32 +02:00
2016-07-30 00:15:32 +02:00
2013-07-21 21:07:19 +08:00
2014-07-30 18:15:14 +08:00
2016-07-30 00:15:32 +02:00
2016-07-30 00:15:32 +02:00
2015-03-03 17:31:20 +08:00
2015-03-07 16:49:07 +08:00
2015-03-25 23:50:54 +08:00
2015-04-05 18:45:14 +08:00
2015-04-10 09:49:07 +02:00
2015-07-29 10:46:12 +08:00
2015-05-29 13:50:44 +08:00
2015-08-13 13:30:25 +08:00
2015-10-08 14:59:02 +03:00
2016-07-30 00:15:32 +02:00
2015-10-29 14:33:58 +08:00
2015-11-13 19:39:59 -08:00
2015-12-25 21:31:42 -08:00
2016-03-30 22:49:27 +02:00
2016-02-16 11:02:57 +08:00
2016-02-25 16:07:22 +08:00
2016-03-17 07:41:41 -07:00
2016-04-16 09:58:57 +02:00
2016-04-28 11:02:47 +02:00
2016-06-09 15:07:44 +03:00
2016-07-20 16:12:37 +08:00
2008-12-02 13:32:53 +00:00
2014-12-19 00:40:59 +00:00
2008-12-02 13:32:53 +00:00
2014-12-21 13:23:02 +00:00
2015-11-23 06:21:30 -08:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2010-05-20 17:55:58 +00:00
2008-12-02 13:32:53 +00:00
2010-04-26 00:13:34 +00:00
2013-12-15 16:51:21 +08:00
2014-12-21 13:23:02 +00:00
2009-04-16 10:54:45 +00:00
2014-03-18 13:28:50 +04:00
2015-07-23 12:14:34 +08:00
2009-01-20 13:21:52 +00:00
2008-11-26 00:59:41 +00:00
2008-11-26 00:59:41 +00:00
2014-11-19 20:23:00 +00:00
2014-05-25 18:19:00 +02:00
2009-08-26 17:17:58 +00:00
2009-08-28 14:31:19 +00:00
2009-08-26 17:17:58 +00:00
2009-08-26 17:17:58 +00:00
2014-12-21 13:23:02 +00:00
2011-08-29 20:23:34 +00:00
2015-02-10 15:48:04 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2012-02-12 08:01:25 +00:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2011-08-29 20:23:34 +00:00
2015-02-10 15:48:04 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2012-02-12 08:01:25 +00:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2012-05-27 19:57:34 -04:00
2009-06-29 07:52:23 +00:00
2009-06-29 07:52:23 +00:00
2015-01-14 18:02:41 +08:00
2014-12-21 13:23:02 +00:00
2015-01-14 18:02:41 +08:00
2015-01-15 14:23:47 +08:00
2015-01-14 18:02:41 +08:00
2010-04-02 21:44:09 +00:00
2015-01-14 18:02:41 +08:00
2008-12-02 13:32:53 +00:00
2014-12-21 13:23:02 +00:00
2012-10-10 10:27:49 +08:00
2012-10-10 10:27:49 +08:00
2015-04-01 11:17:55 +02:00
2012-10-10 10:27:49 +08:00
2014-12-21 13:23:02 +00:00
2012-10-10 10:27:49 +08:00
2015-08-14 14:34:48 +02:00
2015-08-14 14:34:48 +02:00
2015-08-17 12:54:33 +03:00
2015-08-17 12:54:33 +03:00
2016-01-12 07:07:51 +01:00
2016-01-12 07:07:51 +01:00
2016-05-16 19:15:40 +02:00
2011-10-21 06:08:47 +00:00
2014-12-21 13:23:02 +00:00
2011-08-29 20:23:34 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2008-12-02 13:32:53 +00:00
2010-04-26 00:13:34 +00:00
2011-12-12 14:02:06 +00:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2014-12-21 13:23:02 +00:00
2015-01-17 18:50:28 +00:00
2015-01-17 18:50:28 +00:00
2013-06-10 14:30:59 -07:00
2013-06-10 14:30:59 -07:00
2014-12-21 13:23:02 +00:00
2011-08-29 20:23:34 +00:00
2014-12-21 13:23:02 +00:00
2014-12-21 13:23:02 +00:00
2012-02-12 08:01:25 +00:00
2015-01-14 18:02:41 +08:00
2015-01-14 18:02:41 +08:00
2013-06-10 14:30:59 -07:00
2015-01-14 18:02:41 +08:00
2014-12-21 13:23:02 +00:00
2015-01-17 18:50:28 +00:00
2010-01-24 14:41:47 +00:00
2015-01-14 18:02:41 +08:00
2013-03-07 23:05:05 +01:00
2013-07-15 00:23:03 -07:00
2015-01-14 18:02:41 +08:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2014-12-21 13:23:02 +00:00
2008-12-02 13:32:53 +00:00
2016-03-30 22:49:27 +02:00
2016-03-30 22:49:27 +02:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2013-06-10 14:30:59 -07:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2014-12-21 13:23:02 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2015-01-17 18:50:28 +00:00
2008-12-02 13:32:53 +00:00
2015-01-14 18:02:41 +08:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2008-12-02 13:32:53 +00:00
2015-01-19 01:36:56 -05:00
2009-01-07 21:23:10 +00:00