]> granicus.if.org Git - php/commitdiff
Add additional initialization checks to SplFileInfo
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 19 Oct 2020 08:34:17 +0000 (10:34 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 19 Oct 2020 08:35:22 +0000 (10:35 +0200)
ext/spl/spl_directory.c
ext/spl/tests/bug79987.phpt

index a67b9efb03d70e1c4c7d7d027ac6d462633acbb9..3d0dae243502bbf27ee14d53526bb7fff2969743 100644 (file)
@@ -899,6 +899,11 @@ PHP_METHOD(SplFileInfo, getFilename)
                RETURN_THROWS();
        }
 
+       if (!intern->file_name) {
+               zend_throw_error(NULL, "Object not initialized");
+               RETURN_THROWS();
+       }
+
        spl_filesystem_object_get_path(intern, &path_len);
 
        if (path_len && path_len < intern->file_name_len) {
@@ -937,6 +942,11 @@ PHP_METHOD(SplFileInfo, getExtension)
                RETURN_THROWS();
        }
 
+       if (!intern->file_name) {
+               zend_throw_error(NULL, "Object not initialized");
+               RETURN_THROWS();
+       }
+
        spl_filesystem_object_get_path(intern, &path_len);
 
        if (path_len && path_len < intern->file_name_len) {
@@ -1000,6 +1010,11 @@ PHP_METHOD(SplFileInfo, getBasename)
                RETURN_THROWS();
        }
 
+       if (!intern->file_name) {
+               zend_throw_error(NULL, "Object not initialized");
+               RETURN_THROWS();
+       }
+
        spl_filesystem_object_get_path(intern, &path_len);
 
        if (path_len && path_len < intern->file_name_len) {
index bda5841ee7a69be43f0d43cfea03186e8c39aaa9..b6ea8e2a9c41218db326dae9da8c2662753c6703 100644 (file)
@@ -15,5 +15,24 @@ try {
 } catch (Throwable $e) {
     echo $e->getMessage() . "\n";
 }
+try {
+    var_dump($x->getFilename());
+} catch (Throwable $e) {
+    echo $e->getMessage() . "\n";
+}
+try {
+    var_dump($x->getExtension());
+} catch (Throwable $e) {
+    echo $e->getMessage() . "\n";
+}
+try {
+    var_dump($x->getBasename());
+} catch (Throwable $e) {
+    echo $e->getMessage() . "\n";
+}
+?>
 --EXPECT--
 Object not initialized
+Object not initialized
+Object not initialized
+Object not initialized