summaryrefslogtreecommitdiff
path: root/memory_limit.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory_limit.c')
-rw-r--r--memory_limit.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/memory_limit.c b/memory_limit.c
new file mode 100644
index 0000000..fd54301
--- /dev/null
+++ b/memory_limit.c
@@ -0,0 +1,90 @@
1/*
2 +----------------------------------------------------------------------+
3 | Suhosin Version 1 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2006-2007 The Hardened-PHP Project |
6 | Copyright (c) 2007 SektionEins GmbH |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
16 | Author: Stefan Esser <sesser@sektioneins.de> |
17 +----------------------------------------------------------------------+
18*/
19/*
20 $Id: memory_limit.c,v 1.1.1.1 2007-11-28 01:15:35 sesser Exp $
21*/
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "php.h"
28#include "php_ini.h"
29#include "ext/standard/info.h"
30#include "php_suhosin.h"
31
32
33/* {{{ PHP_INI_MH
34 */
35static PHP_INI_MH(suhosin_OnChangeMemoryLimit)
36{
37 long hard_memory_limit = 1<<30;
38
39 if (stage == ZEND_INI_STAGE_RUNTIME) {
40 if (SUHOSIN_G(memory_limit) > 0) {
41 SUHOSIN_G(hard_memory_limit) = SUHOSIN_G(memory_limit);
42 } else if (SUHOSIN_G(hard_memory_limit) == 0) {
43 SUHOSIN_G(hard_memory_limit) = PG(memory_limit);
44 }
45 hard_memory_limit = SUHOSIN_G(hard_memory_limit);
46 } else {
47 SUHOSIN_G(hard_memory_limit) = 0;
48 }
49 if (new_value) {
50 PG(memory_limit) = zend_atoi(new_value, new_value_length);
51 if (PG(memory_limit) > hard_memory_limit || PG(memory_limit) < 0) {
52 suhosin_log(S_MISC, "script tried to increase memory_limit to %u bytes which is above the allowed value", PG(memory_limit));
53 if (!SUHOSIN_G(simulation)) {
54 PG(memory_limit) = hard_memory_limit;
55 return FAILURE;
56 }
57 }
58 } else {
59 PG(memory_limit) = hard_memory_limit;
60 }
61 return zend_set_memory_limit(PG(memory_limit));
62}
63/* }}} */
64
65
66void suhosin_hook_memory_limit()
67{
68 zend_ini_entry *ini_entry;
69 TSRMLS_FETCH();
70
71 /* check if we are compiled against memory_limit */
72 if (zend_hash_find(EG(ini_directives), "memory_limit", sizeof("memory_limit"), (void **) &ini_entry)==FAILURE) {
73 return;
74 }
75
76 /* replace OnUpdateMemoryLimit handler */
77 ini_entry->on_modify = suhosin_OnChangeMemoryLimit;
78}
79
80
81/*
82 * Local variables:
83 * tab-width: 4
84 * c-basic-offset: 4
85 * End:
86 * vim600: noet sw=4 ts=4 fdm=marker
87 * vim<600: noet sw=4 ts=4
88 */
89
90