Skip to content

Assertion error in shm_put_var #16591

Closed
Closed

Description

@chibinz

Description

The following code:

<?php


class C {
    function __serialize() {
        global $mem;
        shm_detach($mem);
    }
}

$mem = shm_attach(1);
shm_put_var($mem, 1, new C);

Resulted in this output:

php: /tmp/php-asan/ext/sysvshm/sysvshm.c:398: zend_long php_check_shm_data(sysvshm_chunk_head *, zend_long): Assertion `ptr' failed.

PHP Version

PHP 8.5.0-dev

Operating System

No response

Activity

  1. cmb69 commented on Oct 25, 2024

    @cmb69
    Member

    Yeah, destructors can be so destructive.

    In this case we may swap the check and the serialization, or maybe duplicate the check after serialization:

    shm_list_ptr = Z_SYSVSHM_P(shm_id);
    if (!shm_list_ptr->ptr) {
    zend_throw_error(NULL, "Shared memory block has already been destroyed");
    RETURN_THROWS();
    }
    /* setup string-variable and serialize */
    PHP_VAR_SERIALIZE_INIT(var_hash);
    php_var_serialize(&shm_var, arg_var, &var_hash);
    PHP_VAR_SERIALIZE_DESTROY(var_hash);

  2. ndossche commented on Oct 25, 2024

    @ndossche
    Member

    Probably just duplicate the check because we also shouldn't attempt to serialize if it's already been destroyed

  3. added a commit that references this issue on Oct 26, 2024
    959c64a
  4. added 3 commits that reference this issue on Oct 26, 2024
    992ac1c
    5605285
    dd84953
  5. added a commit that references this issue on Oct 26, 2024
    d8d388e
  6. added 10 commits that reference this issue on Jul 28, 2026
    3b50874
    fb6c60f
    86afbba
    056c150
    933e025
    69fc4b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions