Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libzafl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Open Source Software
libzafl
Commits
2570bd73
Commit
2570bd73
authored
6 years ago
by
Anh Nguyen-Tuong
Browse files
Options
Downloads
Patches
Plain Diff
Suppress debug output unless ZAFL_DEBUG env. var is set
parent
c47ed939
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/libzafl.cpp
+20
-11
20 additions, 11 deletions
src/libzafl.cpp
with
20 additions
and
11 deletions
src/libzafl.cpp
+
20
−
11
View file @
2570bd73
...
...
@@ -29,16 +29,17 @@
#include
"libzafl.hpp"
//
these are
externally visible so that Zipr transformations can access directly
// externally visible so that Zipr transformations can access directly
u8
*
zafl_trace_map
;
unsigned
short
zafl_prev_id
;
static
s32
shm_id
;
/* ID of the SHM region */
static
s32
shm_id
;
static
int
__afl_temp_data
;
static
pid_t
__afl_fork_pid
;
static
auto
debug
=
false
;
#define PRINT_ERROR(string) (void)(write(2, string, strlen(string))
+1)
#define PRINT_DEBUG(string) (void)(write(1, string, strlen(string))
+1)
#define PRINT_ERROR(string)
if (debug) {
(void)(write(2, string, strlen(string))
);}
#define PRINT_DEBUG(string)
if (debug) {
(void)(write(1, string, strlen(string))
);}
static
void
zafl_setupSharedMemory
();
static
bool
shared_memory_is_setup
=
false
;
...
...
@@ -52,7 +53,7 @@ static void zafl_setupSharedMemory()
char
*
shm_env_var
=
getenv
(
SHM_ENV_VAR
);
if
(
!
shm_env_var
)
{
PRINT_ERROR
(
"Error getting shm
\n
"
);
PRINT_ERROR
(
"Error getting shm
environment variable
\n
"
);
return
;
}
shm_id
=
atoi
(
shm_env_var
);
...
...
@@ -67,32 +68,40 @@ static void zafl_setupSharedMemory()
void
zafl_initAflForkServer
()
{
static
auto
fork_server_initialized
=
false
;
if
(
fork_server_initialized
)
return
;
if
(
getenv
(
"ZAFL_DEBUG"
))
debug
=
true
;
if
(
!
shared_memory_is_setup
)
zafl_setupSharedMemory
();
if
(
!
zafl_trace_map
)
{
zafl_trace_map
=
(
u8
*
)
malloc
(
MAP_SIZE
);
printf
(
"no shmem detected: fake it: zafl_trace_map = %p, malloc_size(%d)
\n
"
,
zafl_trace_map
,
MAP_SIZE
);
if
(
debug
)
printf
(
"no shmem detected: fake it: zafl_trace_map = %p, malloc_size(%d)
\n
"
,
zafl_trace_map
,
MAP_SIZE
);
}
int
n
=
write
(
FORKSRV_FD
+
1
,
&
__afl_temp_data
,
4
);
if
(
n
!=
4
)
{
PRINT_ERROR
(
"Error writting fork server
\n
"
);
perror
(
"zafl_initAflForkServer()"
);
printf
(
"zafl_trace_map = %p, FORKSVR_FD(%d)
\n
"
,
zafl_trace_map
,
FORKSRV_FD
);
if
(
debug
)
perror
(
"zafl_initAflForkServer()"
);
return
;
}
fork_server_initialized
=
true
;
while
(
1
)
{
n
=
read
(
FORKSRV_FD
,
&
__afl_temp_data
,
4
);
if
(
n
!=
4
)
{
PRINT_ERROR
(
"Error reading fork server
\n
"
);
perror
(
"Error reading fork server
\n
"
);
return
;
}
__afl_fork_pid
=
fork
();
if
(
__afl_fork_pid
<
0
)
{
PRINT_ERROR
(
"Error on fork()
\n
"
);
perror
(
"Error on fork()
\n
"
);
return
;
}
if
(
__afl_fork_pid
==
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