]> granicus.if.org Git - php/commitdiff
Added missing resource type checks
authorIlia Alshanetsky <iliaa@php.net>
Sat, 30 Dec 2006 20:21:25 +0000 (20:21 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sat, 30 Dec 2006 20:21:25 +0000 (20:21 +0000)
ext/shmop/shmop.c

index 07f6ff45f6c187a43f2813c3ffa5f3a36ad17dbe..d1e849c1d5e58fd20f58571b7108834582627c31 100644 (file)
@@ -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)
@@ -201,13 +211,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;
@@ -241,12 +246,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);
 }
@@ -264,12 +264,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);
 }
@@ -290,12 +285,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");
@@ -326,12 +316,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?)");