Skip to content

Commit 23afc62

Browse files
committed
Allow pointer to end of memory in IS_UNSERIALIZED()
We already use <= for IS_SERIALIZED(), but the same general problem can also occur for IS_UNSERIALIZED(). We don't seem to hit this in practice prior to GH-5595 though.
1 parent ae2ea34 commit 23afc62

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ext/opcache/zend_file_cache.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ static int zend_file_cache_flock(int fd, int type)
113113
#define IS_SERIALIZED_INTERNED(ptr) \
114114
((size_t)(ptr) & Z_UL(1))
115115

116-
/* Allowing == here to account for a potential empty allocation at the end of the memory */
116+
/* Allowing == on the upper bound accounts for a potential empty allocation at the end of the
117+
* memory region. This can also happen for a return-type-only arg_info, where &arg_info[1] is
118+
* stored, which may point to the end of the region. */
117119
#define IS_SERIALIZED(ptr) \
118120
((char*)(ptr) <= (char*)script->size)
119121
#define IS_UNSERIALIZED(ptr) \
120-
(((char*)(ptr) >= (char*)script->mem && (char*)(ptr) < (char*)script->mem + script->size) || \
122+
(((char*)(ptr) >= (char*)script->mem && (char*)(ptr) <= (char*)script->mem + script->size) || \
121123
IS_ACCEL_INTERNED(ptr))
122124
#define SERIALIZE_PTR(ptr) do { \
123125
if (ptr) { \

0 commit comments

Comments
 (0)