-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathphp_taint.h
135 lines (116 loc) · 4.18 KB
/
php_taint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
+----------------------------------------------------------------------+
| Taint |
+----------------------------------------------------------------------+
| Copyright (c) 2012-2015 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Xinchen Hui <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_TAINT_H
#define PHP_TAINT_H
extern zend_module_entry taint_module_entry;
#define phpext_taint_ptr &taint_module_entry
#ifdef PHP_WIN32
#define PHP_TAINT_API __declspec(dllexport)
#else
#define PHP_TAINT_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#define PHP_TAINT_VERSION "2.1.1-dev"
/* it's important that make sure
* this value is not used by Zend or
* any other extension against string */
#define IS_STR_TAINT_POSSIBLE (1<<7)
#if PHP_VERSION_ID >= 70000
# if PHP_VERSION_ID >= 70200
# undef IS_STR_TAINT_POSSIBLE
/* Coflicts with GC_COLLECTABLE which is introduced in 7.2 */
# define IS_STR_TAINT_POSSIBLE (1<<6)
# endif
# if PHP_VERSION_ID >=70300
# define EX_CONSTANT(op) RT_CONSTANT(EX(opline), op)
# undef IS_STR_TAINT_POSSIBLE
# define IS_STR_TAINT_POSSIBLE (1<<5) /* GC_PROTECTED */
# define TAINT_MARK(str) GC_ADD_FLAGS(str, IS_STR_TAINT_POSSIBLE)
# define TAINT_POSSIBLE(str) (GC_FLAGS((str)) & IS_STR_TAINT_POSSIBLE)
# define TAINT_CLEAN(str) GC_DEL_FLAGS(str, IS_STR_TAINT_POSSIBLE)
# else
# define TAINT_MARK(str) (GC_FLAGS((str)) |= IS_STR_TAINT_POSSIBLE)
# define TAINT_POSSIBLE(str) (GC_FLAGS((str)) & IS_STR_TAINT_POSSIBLE)
# define TAINT_CLEAN(str) (GC_FLAGS((str)) &= ~IS_STR_TAINT_POSSIBLE)
# endif
#else
# error "Unsupported PHP Version ID:" PHP_VERSION_ID
#endif
#define TAINT_OP1_TYPE(opline) (opline->op1_type)
#define TAINT_OP2_TYPE(opline) (opline->op2_type)
#if PHP_VERSION_ID < 70100
#define TAINT_RET_USED(opline) (!((opline)->result_type & EXT_TYPE_UNUSED))
#define TAINT_ISERR(var) (var == &EG(error_zval))
#define TAINT_ERR_ZVAL(var) (var = &EG(error_zval))
#else
#define TAINT_RET_USED(opline) ((opline)->result_type != IS_UNUSED)
#define TAINT_ISERR(var) (Z_ISERROR_P(var))
#define TAINT_ERR_ZVAL(var) (ZVAL_ERROR(var))
#endif
typedef zval* taint_free_op;
PHP_MINIT_FUNCTION(taint);
PHP_MSHUTDOWN_FUNCTION(taint);
PHP_RINIT_FUNCTION(taint);
PHP_RSHUTDOWN_FUNCTION(taint);
PHP_MINFO_FUNCTION(taint);
PHP_FUNCTION(taint);
PHP_FUNCTION(untaint);
PHP_FUNCTION(is_tainted);
PHP_FUNCTION(taint_strval);
PHP_FUNCTION(taint_sprintf);
PHP_FUNCTION(taint_vsprintf);
PHP_FUNCTION(taint_explode);
PHP_FUNCTION(taint_implode);
PHP_FUNCTION(taint_trim);
PHP_FUNCTION(taint_rtrim);
PHP_FUNCTION(taint_ltrim);
PHP_FUNCTION(taint_strstr);
PHP_FUNCTION(taint_substr);
PHP_FUNCTION(taint_str_replace);
PHP_FUNCTION(taint_str_ireplace);
PHP_FUNCTION(taint_str_pad);
PHP_FUNCTION(taint_strtolower);
PHP_FUNCTION(taint_strtoupper);
PHP_FUNCTION(taint_dirname);
PHP_FUNCTION(taint_basename);
PHP_FUNCTION(taint_pathinfo);
#if PHP_VERSION_ID >= 70300
typedef zif_handler php_func;
#else
typedef void (*php_func)(INTERNAL_FUNCTION_PARAMETERS);
#endif
ZEND_BEGIN_MODULE_GLOBALS(taint)
zend_bool enable;
int error_level;
ZEND_END_MODULE_GLOBALS(taint)
#ifdef ZTS
#define TAINT_G(v) TSRMG(taint_globals_id, zend_taint_globals *, v)
#else
#define TAINT_G(v) (taint_globals.v)
#endif
#endif /* PHP_TAINT_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/