Skip to content

Commit 7aaeccd

Browse files
committed
Added license, tests, and updated readme
1 parent bdeb3a4 commit 7aaeccd

File tree

5 files changed

+55
-17
lines changed

5 files changed

+55
-17
lines changed

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
Copyright 2024-present Rafael Grigorian
3+
4+
* * *
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
this software and associated documentation files (the "Software"), to deal in
8+
the Software without restriction, including without limitation the rights to
9+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
the Software, and to permit persons to whom the Software is furnished to do so,
11+
subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Once you copy the `.so` file to the PHP extensions directory, you can enable it
1010

1111
```ini
1212
extension=nop.so
13-
nop.ignore_functions=chmod,chown
13+
nop.functions=chmod,chown
1414
```
1515

16-
Notice that `nop.ignore_functions` is a comma-separated list of functions that you want to replace with the NOP function.
16+
Notice that `nop.functions` is a comma-separated list of functions that you want to replace with the NOP function.
1717

1818
## Development
1919

@@ -29,16 +29,11 @@ Inside the container, run the following commands:
2929
# Install build dependencies and build the extension
3030
apk --update add php83-dev make g++
3131
phpize && ./configure && make && make install
32+
make test
3233

33-
# Setup a quick test
34-
touch ./private/sample
35-
echo "<?php chmod(__DIR__ . '/sample', 0777);" > ./private/sample.php
36-
37-
# Run the test
38-
chmod 644 ./private/sample
39-
ls -la ./private/sample
40-
php -d 'extension=nop.so' -d 'nop.ignore_functions=chmod' ./private/sample.php
41-
ls -la ./private/sample
34+
# Manually test functionality
35+
php -d 'extension=nop.so' -d 'nop.functions=' -r 'printf ("hi\n");'
36+
php -d 'extension=nop.so' -d 'nop.functions=printf' -r 'printf ("hi\n");'
4237
```
4338

4439
## Additional Resources

nop.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif
1818

1919
ZEND_BEGIN_MODULE_GLOBALS(nop)
20-
char *ignore_functions;
20+
char *functions;
2121
ZEND_END_MODULE_GLOBALS(nop)
2222

2323
ZEND_DECLARE_MODULE_GLOBALS(nop)
@@ -30,7 +30,7 @@ ZEND_DECLARE_MODULE_GLOBALS(nop)
3030

3131
static void php_nop_init_globals(zend_nop_globals *nop_globals)
3232
{
33-
nop_globals->ignore_functions = NULL;
33+
nop_globals->functions = NULL;
3434
}
3535

3636
PHP_FUNCTION(no_operation)
@@ -50,7 +50,7 @@ PHP_RINIT_FUNCTION(nop)
5050
/* }}} */
5151

5252
PHP_INI_BEGIN()
53-
STD_PHP_INI_ENTRY("nop.ignore_functions", "", PHP_INI_ALL, OnUpdateString, ignore_functions, zend_nop_globals, nop_globals)
53+
STD_PHP_INI_ENTRY("nop.functions", "", PHP_INI_ALL, OnUpdateString, functions, zend_nop_globals, nop_globals)
5454
PHP_INI_END()
5555

5656
/* {{{ PHP_MINIT_FUNCTION */
@@ -59,10 +59,10 @@ PHP_MINIT_FUNCTION(nop)
5959
ZEND_INIT_MODULE_GLOBALS(nop, php_nop_init_globals, NULL);
6060
REGISTER_INI_ENTRIES();
6161

62-
char *ignore_functions = NOP_G(ignore_functions);
63-
if (ignore_functions != NULL) {
62+
char *functions = NOP_G(functions);
63+
if (functions != NULL) {
6464
char *token;
65-
char *rest = ignore_functions;
65+
char *rest = functions;
6666
while ((token = strtok_r(rest, ",", &rest))) {
6767
zend_function *original;
6868
original = zend_hash_str_find_ptr(CG(function_table), token, strlen(token));

tests/003.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
functions=
3+
--EXTENSIONS--
4+
nop
5+
--FILE--
6+
<?php
7+
printf("Hello, World!\n");
8+
?>
9+
--EXPECT--
10+
Hello, World!

tests/004.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
functions=printf
3+
--EXTENSIONS--
4+
nop
5+
--INI--
6+
nop.functions=printf
7+
--FILE--
8+
<?php
9+
printf("Hello, World!\n");
10+
?>
11+
--EXPECT--
12+

0 commit comments

Comments
 (0)