php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
fuzzer-unserializehash.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 */
14
15
16#include "fuzzer.h"
17
18#include "Zend/zend.h"
19#include <main/php_config.h>
20#include "main/php_main.h"
21
22#include <stdio.h>
23#include <stdint.h>
24#include <stdlib.h>
25
26#include "fuzzer-sapi.h"
27
29
30int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t FullSize) {
31 const uint8_t *Start = memchr(Data, '|', FullSize);
32 if (!Start) {
33 return 0;
34 }
35 ++Start;
36
38 return 0;
39 }
40
41 size_t Size = (Data + FullSize) - Start;
42 unsigned char *orig_data = malloc(Size+1);
43 memcpy(orig_data, Start, Size);
44 orig_data[Size] = '\0';
45
47
48 {
49 const unsigned char *data = orig_data;
52
55 php_var_unserialize(&result, (const unsigned char **) &data, data + Size, &var_hash);
57
58 if (Z_TYPE(result) == IS_OBJECT
59 && zend_string_equals_literal(Z_OBJCE(result)->name, "HashContext")) {
60 zval args[2];
62 ZVAL_STRINGL(&args[1], (char *) Data, (Start - Data) - 1);
63 fuzzer_call_php_func_zval("hash_update", 2, args);
65 fuzzer_call_php_func_zval("hash_final", 1, args);
66 }
67
69 }
70
71 free(orig_data);
72
74 return 0;
75}
76
77int LLVMFuzzerInitialize(int *argc, char ***argv) {
79
80 /* fuzzer_shutdown_php(); */
81 return 0;
82}
memcpy(ptr1, ptr2, size)
int fuzzer_request_startup(void)
void fuzzer_setup_dummy_frame(void)
void fuzzer_call_php_func_zval(const char *func_name, int nargs, zval *args)
void fuzzer_request_shutdown(void)
int fuzzer_init_php(const char *extra_ini)
int LLVMFuzzerInitialize(int *argc, char ***argv)
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t FullSize)
#define NULL
Definition gdcache.h:45
#define PHP_VAR_UNSERIALIZE_DESTROY(d)
Definition php_var.h:59
struct php_unserialize_data * php_unserialize_data_t
Definition php_var.h:32
#define PHP_VAR_UNSERIALIZE_INIT(d)
Definition php_var.h:56
PHPAPI int php_var_unserialize(zval *rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash)
zend_constant * data
php_unserialize_data_t var_hash
Definition session.c:964
#define ZVAL_STRINGL(z, s, l)
Definition zend_API.h:952
struct _zval_struct zval
zval * args
#define zend_string_equals_literal(str, literal)
#define ZVAL_UNDEF(z)
@ FAILURE
Definition zend_types.h:61
#define IS_OBJECT
Definition zend_types.h:608
#define Z_TYPE(zval)
Definition zend_types.h:659
#define ZVAL_COPY_VALUE(z, v)
#define Z_OBJCE(zval)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zend_string * name
bool result