Skip to content

Commit

Permalink
Add PHAR fuzzer
Browse files Browse the repository at this point in the history
Remove HAVE_PHAR check, it's on by default
  • Loading branch information
smalyshev committed Apr 20, 2020
1 parent cd56395 commit f0f8612
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sapi/fuzzer/Makefile.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ $(SAPI_FUZZER_PATH)/php-fuzz-exif: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(PHP_FUZ

$(SAPI_FUZZER_PATH)/php-fuzz-mbstring: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(PHP_FUZZER_MBSTRING_OBJS)
$(FUZZER_BUILD) $(PHP_FUZZER_MBSTRING_OBJS) -o $@

$(SAPI_FUZZER_PATH)/php-fuzz-phar: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(PHP_FUZZER_PHAR_OBJS)
$(FUZZER_BUILD) $(PHP_FUZZER_PHAR_OBJS) -o $@
3 changes: 3 additions & 0 deletions sapi/fuzzer/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ if test "$PHP_FUZZER" != "no"; then
if test -n "$enable_mbstring" && test "$enable_mbstring" != "no"; then
PHP_FUZZER_TARGET([mbstring], PHP_FUZZER_MBSTRING_OBJS)
fi
if test -n "$enable_phar" && test "$enable_phar" != "no"; then
PHP_FUZZER_TARGET([phar], PHP_FUZZER_PHAR_OBJS)
fi

PHP_SUBST(PHP_FUZZER_BINARIES)
fi
Expand Down
Binary file added sapi/fuzzer/corpus/phar/72321_1.zip
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/72321_2.zip
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug69324.phar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug69441.phar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug69453.tar.phar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug69720.phar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug69958.tar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug70019.zip
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug70433.zip
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug71331.tar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug71354.tar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug71391.tar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug71488.tar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug71498.zip
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug72928.zip
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug73035.tar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug73764.phar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug73768.phar
Binary file not shown.
Binary file added sapi/fuzzer/corpus/phar/bug77143.phar
Binary file not shown.
72 changes: 72 additions & 0 deletions sapi/fuzzer/fuzzer-phar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
+----------------------------------------------------------------------+
| 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: |
| 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Stanislav Malyshev <stas@php.net> |
+----------------------------------------------------------------------+
*/

#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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "fuzzer-sapi.h"

int phar_create_or_parse_filename(char *fname, size_t fname_len, char *alias, size_t alias_len, zend_bool is_data, uint32_t options, void** pphar, char **error);
void phar_request_initialize(void);

int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
void *phar_data;
char *tmp_filename;
int tmpfd;

if (Size > 256 * 1024) {
/* Large inputs have a large impact on fuzzer performance,
* but are unlikely to be necessary to reach new codepaths. */
return 0;
}

if (fuzzer_request_startup() == FAILURE) {
return 0;
}
phar_request_initialize();

tmp_filename = estrdup("/tmp/phar-fuzz.temp.XXXXXX");
tmpfd = mkstemp(tmp_filename);
write(tmpfd, Data, Size);
close(tmpfd);

phar_create_or_parse_filename(tmp_filename, strlen(tmp_filename), NULL, 0, 1, REPORT_ERRORS, &phar_data, NULL);

/* cleanup */
unlink(tmp_filename);
efree(tmp_filename);
php_request_shutdown(NULL);

return 0;
}

int LLVMFuzzerInitialize(int *argc, char ***argv) {
fuzzer_init_php();

/* fuzzer_shutdown_php(); */
return 0;
}

0 comments on commit f0f8612

Please sign in to comment.