summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-12-30 20:21:39 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-12-30 20:21:39 +0000
commitafdc0907f7ba8064c0b778d980c415a947db2732 (patch)
tree882f5e9f8c4c45d5064e9464e1ee3b5df53731a6
parent8351d9c7f3d69c1326b68fa7c6736a3ee1a516dc (diff)
downloadphp-git-afdc0907f7ba8064c0b778d980c415a947db2732.tar.gz
MFH: Added missing resource type checks
-rw-r--r--ext/shmop/shmop.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/ext/shmop/shmop.c b/ext/shmop/shmop.c
index 268ccaa18c..2ce7e8ae86 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)
@@ -210,13 +220,8 @@ PHP_FUNCTION(shmop_read)
WRONG_PARAM_COUNT;
}
- 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;
@@ -255,12 +260,7 @@ PHP_FUNCTION(shmop_close)
WRONG_PARAM_COUNT;
}
- 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);
}
@@ -278,12 +278,7 @@ PHP_FUNCTION(shmop_size)
WRONG_PARAM_COUNT;
}
- 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);
}
@@ -304,12 +299,7 @@ PHP_FUNCTION(shmop_write)
WRONG_PARAM_COUNT;
}
- 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");
@@ -340,12 +330,7 @@ PHP_FUNCTION(shmop_delete)
WRONG_PARAM_COUNT;
}
- 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?)");