Skip to content

Commit 3ca748d

Browse files
author
Ilia Alshanetsky
committed
Added missing resource type checks
1 parent 3d11fb3 commit 3ca748d

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

ext/shmop/shmop.c

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ zend_module_entry shmop_module_entry = {
7878
ZEND_GET_MODULE(shmop)
7979
#endif
8080

81+
#define PHP_SHMOP_GET_RES \
82+
shmop = zend_list_find(shmid, &type); \
83+
if (!shmop) { \
84+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); \
85+
RETURN_FALSE; \
86+
} else if (type != shm_type) { \
87+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a shmop resource"); \
88+
RETURN_FALSE; \
89+
} \
90+
8191
/* {{{ rsclean
8292
*/
8393
static void rsclean(zend_rsrc_list_entry *rsrc TSRMLS_DC)
@@ -201,13 +211,8 @@ PHP_FUNCTION(shmop_read)
201211
return;
202212
}
203213

204-
shmop = zend_list_find(shmid, &type);
214+
PHP_SHMOP_GET_RES
205215

206-
if (!shmop) {
207-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid);
208-
RETURN_FALSE;
209-
}
210-
211216
if (start < 0 || start > shmop->size) {
212217
php_error_docref(NULL TSRMLS_CC, E_WARNING, "start is out of range");
213218
RETURN_FALSE;
@@ -241,12 +246,7 @@ PHP_FUNCTION(shmop_close)
241246
return;
242247
}
243248

244-
shmop = zend_list_find(shmid, &type);
245-
246-
if (!shmop) {
247-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid);
248-
RETURN_FALSE;
249-
}
249+
PHP_SHMOP_GET_RES
250250

251251
zend_list_delete(shmid);
252252
}
@@ -264,12 +264,7 @@ PHP_FUNCTION(shmop_size)
264264
return;
265265
}
266266

267-
shmop = zend_list_find(shmid, &type);
268-
269-
if (!shmop) {
270-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid);
271-
RETURN_FALSE;
272-
}
267+
PHP_SHMOP_GET_RES
273268

274269
RETURN_LONG(shmop->size);
275270
}
@@ -290,12 +285,7 @@ PHP_FUNCTION(shmop_write)
290285
return;
291286
}
292287

293-
shmop = zend_list_find(shmid, &type);
294-
295-
if (!shmop) {
296-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid);
297-
RETURN_FALSE;
298-
}
288+
PHP_SHMOP_GET_RES
299289

300290
if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) {
301291
php_error_docref(NULL TSRMLS_CC, E_WARNING, "trying to write to a read only segment");
@@ -326,12 +316,7 @@ PHP_FUNCTION(shmop_delete)
326316
return;
327317
}
328318

329-
shmop = zend_list_find(shmid, &type);
330-
331-
if (!shmop) {
332-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid);
333-
RETURN_FALSE;
334-
}
319+
PHP_SHMOP_GET_RES
335320

336321
if (shmctl(shmop->shmid, IPC_RMID, NULL)) {
337322
php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't mark segment for deletion (are you the owner?)");

0 commit comments

Comments
 (0)