Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin J. Thompson
Tor
Commits
56b61d18
Commit
56b61d18
authored
8 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Add more tweaks from teor's http fuzzing code.
Move option-manipulation code to fuzzing_common.
parent
584d723e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/test/fuzz/fuzz_http.c
+53
-23
53 additions, 23 deletions
src/test/fuzz/fuzz_http.c
src/test/fuzz/fuzzing_common.c
+14
-0
14 additions, 0 deletions
src/test/fuzz/fuzzing_common.c
with
67 additions
and
23 deletions
src/test/fuzz/fuzz_http.c
+
53
−
23
View file @
56b61d18
...
...
@@ -16,51 +16,81 @@
#include
"fuzzing.h"
static
int
mock_get_options_calls
=
0
;
static
or_options_t
*
mock_options
=
NULL
;
static
void
reset_options
(
or_options_t
*
options
,
int
*
get_options_calls
)
mock_connection_write_to_buf_impl_
(
const
char
*
string
,
size_t
len
,
connection_t
*
conn
,
int
zlib
)
{
memset
(
options
,
0
,
sizeof
(
or_options_t
));
options
->
TestingTorNetwork
=
1
;
*
get_options_calls
=
0
;
log_debug
(
LD_GENERAL
,
"%sResponse:
\n
%zu
\n
Connection: %p
\n
%s
\n
"
,
zlib
?
"Compressed "
:
""
,
len
,
conn
,
string
);
}
static
const
or_options_t
*
mock_get_options
(
void
)
static
int
mock_directory_handle_command_get
(
dir_connection_t
*
conn
,
const
char
*
headers
,
const
char
*
body
,
size_t
body_len
)
{
++
mock_get_options_calls
;
tor_assert
(
mock_options
);
return
mock_options
;
(
void
)
conn
;
log_debug
(
LD_GENERAL
,
"Method:
\n
GET
\n
"
);
if
(
headers
)
{
log_debug
(
LD_GENERAL
,
"Header-Length:
\n
%zu
\n
"
,
strlen
(
headers
));
log_debug
(
LD_GENERAL
,
"Headers:
\n
%s
\n
"
,
headers
);
}
log_debug
(
LD_GENERAL
,
"Body-Length:
\n
%zu
\n
"
,
body_len
);
if
(
body
)
{
log_debug
(
LD_GENERAL
,
"Body:
\n
%s
\n
"
,
body
);
}
/* Always tell the caller we succeeded */
return
0
;
}
static
void
mock_connection_write_to_buf_impl_
(
const
char
*
string
,
size_t
len
,
connection_t
*
conn
,
int
zlib
)
static
int
mock_directory_handle_command_post
(
dir_connection_t
*
conn
,
const
char
*
headers
,
const
char
*
body
,
size_t
body_len
)
{
log_debug
(
LD_GENERAL
,
"%sResponse:
\n
%zu
\n
Connection: %p
\n
%s
\n
"
,
zlib
?
"Compressed "
:
""
,
len
,
conn
,
string
);
(
void
)
conn
;
log_debug
(
LD_GENERAL
,
"Method:
\n
POST
\n
"
);
if
(
headers
)
{
log_debug
(
LD_GENERAL
,
"Header-Length:
\n
%zu
\n
"
,
strlen
(
headers
));
log_debug
(
LD_GENERAL
,
"Headers:
\n
%s
\n
"
,
headers
);
}
log_debug
(
LD_GENERAL
,
"Body-Length:
\n
%zu
\n
"
,
body_len
);
if
(
body
)
{
log_debug
(
LD_GENERAL
,
"Body:
\n
%s
\n
"
,
body
);
}
/* Always tell the caller we succeeded */
return
0
;
}
int
fuzz_init
(
void
)
{
mock_options
=
tor_malloc
(
sizeof
(
or_options_t
));
reset_options
(
mock_options
,
&
mock_get_options_calls
);
MOCK
(
get_options
,
mock_get_options
);
/* Set up fake response handler */
MOCK
(
connection_write_to_buf_impl_
,
mock_connection_write_to_buf_impl_
);
/* Set up the fake handler functions */
MOCK
(
directory_handle_command_get
,
mock_directory_handle_command_get
);
MOCK
(
directory_handle_command_post
,
mock_directory_handle_command_post
);
return
0
;
}
int
fuzz_cleanup
(
void
)
{
tor_free
(
mock_options
);
UNMOCK
(
get_options
);
UNMOCK
(
connection_write_to_buf_impl_
);
UNMOCK
(
directory_handle_command_get
);
UNMOCK
(
directory_handle_command_post
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
src/test/fuzz/fuzzing_common.c
+
14
−
0
View file @
56b61d18
...
...
@@ -10,6 +10,13 @@
extern
const
char
tor_git_revision
[];
const
char
tor_git_revision
[]
=
""
;
static
or_options_t
*
mock_options
=
NULL
;
static
const
or_options_t
*
mock_get_options
(
void
)
{
return
mock_options
;
}
static
int
mock_crypto_pk_public_checksig__nocheck
(
const
crypto_pk_t
*
env
,
char
*
to
,
size_t
tolen
,
...
...
@@ -116,6 +123,10 @@ main(int argc, char **argv)
init_logging
(
1
);
configure_backtrace_handler
(
get_version
());
/* set up the options. */
mock_options
=
tor_malloc
(
sizeof
(
or_options_t
));
MOCK
(
get_options
,
mock_get_options
);
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
!
strcmp
(
argv
[
i
],
"--warn"
))
{
loglevel
=
LOG_WARN
;
...
...
@@ -156,6 +167,9 @@ main(int argc, char **argv)
if
(
fuzz_cleanup
()
<
0
)
abort
();
tor_free
(
mock_options
);
UNMOCK
(
get_options
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment