Skip to content

Convert resource to object in Sysvshm extension #5499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code review fix
  • Loading branch information
kocsismate committed Jun 16, 2020
commit 21525ce4d39c401cab2c1b3b6a3c91a783c2a53d
23 changes: 21 additions & 2 deletions ext/sysvshm/sysvshm.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ PHP_FUNCTION(shm_remove)

shm_list_ptr = Z_SYSVSHM_P(shm_id);

if (!shm_list_ptr->ptr) {
RETURN_TRUE;
}

if (shmctl(shm_list_ptr->id, IPC_RMID, NULL) < 0) {
php_error_docref(NULL, E_WARNING, "Failed for key 0x%x, id " ZEND_LONG_FMT ": %s", shm_list_ptr->key, Z_LVAL_P(shm_id), strerror(errno));
RETURN_FALSE;
Expand Down Expand Up @@ -244,13 +248,16 @@ PHP_FUNCTION(shm_put_var)
RETURN_THROWS();
}

shm_list_ptr = Z_SYSVSHM_P(shm_id);
if (!shm_list_ptr->ptr) {
RETURN_FALSE;
}

/* 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);

shm_list_ptr = Z_SYSVSHM_P(shm_id);

/* insert serialized variable into shared memory */
ret = php_put_shm_data(shm_list_ptr->ptr, shm_key, shm_var.s? ZSTR_VAL(shm_var.s) : NULL, shm_var.s? ZSTR_LEN(shm_var.s) : 0);

Expand Down Expand Up @@ -317,6 +324,10 @@ PHP_FUNCTION(shm_has_var)

shm_list_ptr = Z_SYSVSHM_P(shm_id);

if (!shm_list_ptr->ptr) {
RETURN_FALSE;
}

RETURN_BOOL(php_check_shm_data(shm_list_ptr->ptr, shm_key) >= 0);
}
/* }}} */
Expand Down Expand Up @@ -382,6 +393,10 @@ static zend_long php_check_shm_data(sysvshm_chunk_head *ptr, zend_long key)
zend_long pos;
sysvshm_chunk *shm_var;

if (!ptr) {
return -1;
}

pos = ptr->start;

for (;;) {
Expand Down Expand Up @@ -409,6 +424,10 @@ static int php_remove_shm_data(sysvshm_chunk_head *ptr, zend_long shm_varpos)
sysvshm_chunk *chunk_ptr, *next_chunk_ptr;
zend_long memcpy_len;

if (!ptr) {
return -1;
}

chunk_ptr = (sysvshm_chunk *) ((char *) ptr + shm_varpos);
next_chunk_ptr = (sysvshm_chunk *) ((char *) ptr + shm_varpos + chunk_ptr->next);

Expand Down