Do not allow using traits/interfaces/abstract classes as stream wrappers
authorSara Golemon <pollita@php.net>
Wed, 19 Jul 2017 16:29:05 +0000 (12:29 -0400)
committerSara Golemon <pollita@php.net>
Wed, 19 Jul 2017 18:00:00 +0000 (14:00 -0400)
Fixes https://bugs.php.net/bug.php?id=74951

ext/standard/tests/streams/bug74951.phpt [new file with mode: 0644]
main/streams/userspace.c

diff --git a/ext/standard/tests/streams/bug74951.phpt b/ext/standard/tests/streams/bug74951.phpt
new file mode 100644 (file)
index 0000000..82788b0
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug#74951 Null pointer dereference in user streams
+--FILE--
+<?php
+trait Stream00ploiter{
+  public function s() {}
+  public function n($_) {}
+}
+stream_wrapper_register('e0ploit','Stream00ploiter');
+$s=fopen('e0ploit://',0);
+--EXPECTF--
+Warning: fopen(e0ploit://): failed to open stream: operation failed in %s/bug74951.php on line 7
index 94d32abd11ebaf14c4b2d12f2f128985b62d2b13..e2cccf32d6a4490a31906f5d4b8332bac695f515 100644 (file)
@@ -283,6 +283,11 @@ typedef struct _php_userstream_data php_userstream_data_t;
 
 static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context, zval *object)
 {
+       if (uwrap->ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
+               ZVAL_UNDEF(object);
+               return;
+       }
+
        /* create an instance of our class */
        object_init_ex(object, uwrap->ce);