-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/bcmath: Added fuzzer for divide #18045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SakiTakamachi
wants to merge
11
commits into
php:PHP-8.4
Choose a base branch
from
SakiTakamachi:bcmath/fuzz_84
base: PHP-8.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
24003b5
fuzzer for bcmath
SakiTakamachi 5341ef7
Fixed the number of `args`
SakiTakamachi 1fb2cd1
Changed "Comma" to "comma"
SakiTakamachi 82ed67d
Overall fix to scale parsing
SakiTakamachi bd630e3
Changed the six main calculation functions to be specified randomly
SakiTakamachi a2c3f56
remove `LLVMFuzzerCustomMutator`
SakiTakamachi 13319aa
Added bcmath dict
SakiTakamachi e1fa2fa
Removed unnecessary memory allocation.
SakiTakamachi 3d52e01
Added .gitignore
SakiTakamachi 39cca77
Fixed README.md
SakiTakamachi cddaede
I forgot to include the pattern for negative values
SakiTakamachi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
php-fuzz-* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
15,7,0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
14.14,-9,10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.23456789,0.56,10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.00123456789,0.001,10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-12345.6789,100,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12345.6,0.00001,20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"," | ||
"1234567890" | ||
"-9876543" | ||
"0.12345678" | ||
"-0.002468" | ||
"9999999999999999" | ||
"0.00000000000000000000001" | ||
"10" | ||
"-29" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 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: | | ||
| https://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. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Saki Takamachi <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
|
||
|
||
#include "fuzzer.h" | ||
|
||
#include "Zend/zend.h" | ||
#include <main/php_config.h> | ||
#include "main/php_main.h" | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#include "fuzzer-sapi.h" | ||
|
||
bool char_to_zend_long(const char *c, size_t scale_len, zend_long *ret) { | ||
*ret = 0; | ||
zend_long old_ret = 0; | ||
for (size_t i = 0; i < scale_len; i++) { | ||
if (*c >= '0' && *c <= '9') { | ||
*ret *= 10; | ||
*ret += *c - '0'; | ||
} | ||
if (*ret > old_ret) { | ||
old_ret = *ret; | ||
} else { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | ||
/* num1,num2,scale */ | ||
const char *n1ptr = (char *) Data; | ||
const char *comma1 = memchr(n1ptr, ',', Size); | ||
if (!comma1) { | ||
return 0; | ||
} | ||
size_t n1len = comma1 - n1ptr; | ||
Size -= n1len + 1; | ||
|
||
const char *n2ptr = comma1 + 1; | ||
const char *comma2 = memchr(n2ptr, ',', Size); | ||
if (!comma2) { | ||
return 0; | ||
} | ||
size_t n2len = comma2 - n2ptr; | ||
Size -= n2len + 1; | ||
|
||
zend_long scale = 0; | ||
if (!char_to_zend_long((char *) comma2 + 1, Size, &scale)) { | ||
return 0; | ||
} | ||
|
||
if (fuzzer_request_startup() == FAILURE) { | ||
return 0; | ||
} | ||
|
||
char func_name[6]; | ||
switch (rand() % 6) { | ||
case 0: | ||
sprintf(func_name, "%s", "bcadd"); | ||
break; | ||
case 1: | ||
sprintf(func_name, "%s", "bcsub"); | ||
break; | ||
case 2: | ||
sprintf(func_name, "%s", "bcmul"); | ||
break; | ||
case 3: | ||
sprintf(func_name, "%s", "bcdiv"); | ||
break; | ||
case 4: | ||
sprintf(func_name, "%s", "bcmod"); | ||
break; | ||
case 5: | ||
sprintf(func_name, "%s", "bcpow"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the exponent is large, the processing is too slow. It may be better to set a limit such as "when |
||
break; | ||
} | ||
|
||
fuzzer_setup_dummy_frame(); | ||
|
||
zval args[3]; | ||
ZVAL_STRINGL(&args[0], n1ptr, n1len); | ||
ZVAL_STRINGL(&args[1], n2ptr, n2len); | ||
ZVAL_LONG(&args[2], scale); | ||
|
||
fuzzer_call_php_func_zval(func_name, 3, args); | ||
|
||
zval_ptr_dtor(&args[0]); | ||
zval_ptr_dtor(&args[1]); | ||
|
||
fuzzer_request_shutdown(); | ||
|
||
return 0; | ||
} | ||
|
||
int LLVMFuzzerInitialize(int *argc, char ***argv) { | ||
fuzzer_init_php(NULL); | ||
|
||
/* fuzzer_shutdown_php(); */ | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should happen earlier to not leak memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unnecessary memory allocations and relocated code.
How about the code now?
e1fa2fa