From: Ilia Alshanetsky Date: Sat, 30 Dec 2006 20:21:47 +0000 (+0000) Subject: MFB: Added missing resource type checks X-Git-Tag: RELEASE_1_0_0RC1~450 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=647ad42cf72305908820f7a75a295fac3f1efd02;p=php MFB: Added missing resource type checks --- diff --git a/ext/shmop/shmop.c b/ext/shmop/shmop.c index dea3bfe7e0..ff47c4c97b 100644 --- a/ext/shmop/shmop.c +++ b/ext/shmop/shmop.c @@ -78,6 +78,16 @@ zend_module_entry shmop_module_entry = { ZEND_GET_MODULE(shmop) #endif +#define PHP_SHMOP_GET_RES \ + shmop = zend_list_find(shmid, &type); \ + if (!shmop) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); \ + RETURN_FALSE; \ + } else if (type != shm_type) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a shmop resource"); \ + RETURN_FALSE; \ + } \ + /* {{{ rsclean */ static void rsclean(zend_rsrc_list_entry *rsrc TSRMLS_DC) @@ -219,13 +229,8 @@ PHP_FUNCTION(shmop_read) return; } - shmop = zend_list_find(shmid, &type); + PHP_SHMOP_GET_RES - if (!shmop) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); - RETURN_FALSE; - } - if (start < 0 || start > shmop->size) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "start is out of range"); RETURN_FALSE; @@ -259,12 +264,7 @@ PHP_FUNCTION(shmop_close) return; } - shmop = zend_list_find(shmid, &type); - - if (!shmop) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); - RETURN_FALSE; - } + PHP_SHMOP_GET_RES zend_list_delete(shmid); } @@ -282,12 +282,7 @@ PHP_FUNCTION(shmop_size) return; } - shmop = zend_list_find(shmid, &type); - - if (!shmop) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); - RETURN_FALSE; - } + PHP_SHMOP_GET_RES RETURN_LONG(shmop->size); } @@ -308,12 +303,7 @@ PHP_FUNCTION(shmop_write) return; } - shmop = zend_list_find(shmid, &type); - - if (!shmop) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); - RETURN_FALSE; - } + PHP_SHMOP_GET_RES if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "trying to write to a read only segment"); @@ -344,12 +334,7 @@ PHP_FUNCTION(shmop_delete) return; } - shmop = zend_list_find(shmid, &type); - - if (!shmop) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); - RETURN_FALSE; - } + PHP_SHMOP_GET_RES if (shmctl(shmop->shmid, IPC_RMID, NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't mark segment for deletion (are you the owner?)");