dfuzzer
Functions | Variables
rand.c File Reference
#include <gio/gio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include "rand.h"

Functions

static void df_rand_random_string (char *buf, const long size)
 
void df_rand_init (const long buf_size)
 
guint8 df_rand_guint8 (void)
 
gboolean df_rand_gboolean (void)
 
gint16 df_rand_gint16 (void)
 
guint16 df_rand_guint16 (void)
 
gint32 df_rand_gint32 (void)
 
guint32 df_rand_guint32 (void)
 
gint64 df_rand_gint64 (void)
 
guint64 df_rand_guint64 (void)
 
double drand (void)
 
gdouble df_rand_gdouble (void)
 
int df_rand_continue (const int fuzz_on_str_len)
 
int df_rand_string (gchar **buf)
 
int df_rand_dbus_objpath_string (gchar **buf)
 
int df_rand_dbus_signature_string (gchar **buf)
 
int df_rand_GVariant (GVariant **var)
 
int df_rand_unixFD (void)
 

Variables

static long df_buf_size
 
static unsigned int df_num_fuzz_counter
 
static unsigned short df_gu8f
 
static unsigned short df_gi16f
 
static unsigned short df_gu16f
 
static unsigned short df_gi32f
 
static unsigned short df_gu32f
 
static unsigned short df_gi64f
 
static unsigned short df_gu64f
 
static unsigned short df_gdouf
 
static long df_str_len
 
static const char * df_str_def []
 
static unsigned df_index_str
 
static unsigned df_index_var
 
static const char df_sig_def [16] = "ybnqiuxtdsogavh"
 

Function Documentation

◆ df_rand_continue()

int df_rand_continue ( const int  fuzz_on_str_len)

@function Tells callee whether to continue testing according to current size of generated strings not to exceed df_buf_size length.

Parameters
fuzz_on_str_lenIf 1, fuzzing will be controlled by generated random strings lengths
Returns
1 when callee should continue, 0 otherwise

◆ df_rand_dbus_objpath_string()

int df_rand_dbus_objpath_string ( gchar **  buf)

@function Allocates memory for pseudo-random object path string of size counted by adding 1 to size variable on every call of function to maximum size of MAXLEN. On every call pseudo-random object path string is generated into buf buffer. Warning: buf should be freed outside this module by callee of this function.

Parameters
bufAddress of pointer on buffer where generated object path string will be stored
Returns
0 on success, -1 on error

◆ df_rand_dbus_signature_string()

int df_rand_dbus_signature_string ( gchar **  buf)

@function Allocates memory for pseudo-random signature string of size counted by adding 1 to size variable on every call of function to maximum size of MAXSIG. On every call pseudo-random signature string is generated by random access into global variable df_sig_def which contains all D-Bus signatures and copying signature into buf buffer. Warning: buf should be freed outside this module by callee of this function.

Parameters
bufAddress of pointer on buffer where generated signature string will be stored
Returns
0 on success, -1 on error

◆ df_rand_gboolean()

gboolean df_rand_gboolean ( void  )
Returns
Generated pseudo-random boolean value

◆ df_rand_gdouble()

gdouble df_rand_gdouble ( void  )
Returns
Generated pseudo-random double precision floating point number

◆ df_rand_gint16()

gint16 df_rand_gint16 ( void  )
Returns
Generated pseudo-random 16-bit integer value

◆ df_rand_gint32()

gint32 df_rand_gint32 ( void  )
Returns
Generated pseudo-random 32-bit integer value

◆ df_rand_gint64()

gint64 df_rand_gint64 ( void  )
Returns
Generated pseudo-random 64-bit (long) integer value

◆ df_rand_guint16()

guint16 df_rand_guint16 ( void  )
Returns
Generated pseudo-random 16-bit unsigned integer value

◆ df_rand_guint32()

guint32 df_rand_guint32 ( void  )
Returns
Generated pseudo-random 32-bit unsigned integer value

◆ df_rand_guint64()

guint64 df_rand_guint64 ( void  )
Returns
Generated pseudo-random 64-bit (long) unsigned integer value

◆ df_rand_guint8()

guint8 df_rand_guint8 ( void  )
Returns
Generated pseudo-random 8-bit unsigned integer value

◆ df_rand_GVariant()

int df_rand_GVariant ( GVariant **  var)

@function Creates Gvariant containing pseudo-random string. At the beginning strings from global array df_str_def are used.

Parameters
varAddress of pointer on GVariant where new Gvariant value will be stored
Returns
0 on success, -1 on error

◆ df_rand_init()

void df_rand_init ( const long  buf_size)

@function Initializes global flag variables and seeds pseudo-random numbers generators.

Parameters
buf_sizeMaximum buffer size for generated strings (in Bytes)

◆ df_rand_random_string()

static void df_rand_random_string ( char *  buf,
const long  size 
)
static

@function Generates pseudo-random string of size size.

Parameters
bufPointer on buffer where generated string will be stored
sizeSize of buffer

◆ df_rand_string()

int df_rand_string ( gchar **  buf)

@function Allocates memory for pseudo-random string of size counted by adding generated pseudo-random number from interval <0, CHAR_MAX> to df_str_len (this mechanism is responsible for generating bigger strings by every call of df_rand_string()). Then pseudo-random string is generated and stored in buf. At the beginning strings from global array df_str_def are used. Warning: buf should be freed outside this module by callee of this function.

Parameters
bufAddress of pointer on buffer where generated string will be stored
Returns
0 on success, -1 on error

◆ df_rand_unixFD()

int df_rand_unixFD ( void  )
Returns
Generated pseudo-random FD number from interval <-1, INT_MAX)

◆ drand()

double drand ( void  )
inline
Returns
Generated pseudo-random double precision floating point number from interval <0, 1>

Variable Documentation

◆ df_buf_size

long df_buf_size
static

Maximum buffer size for generated strings (in Bytes)

◆ df_index_str

unsigned df_index_str
static

Index into df_str_def array for function df_rand_string()

◆ df_index_var

unsigned df_index_var
static

Index into df_str_def array for function df_rand_GVariant()

◆ df_num_fuzz_counter

unsigned int df_num_fuzz_counter
static

Counter for fuzzing methods which have only numbers as their parameters. Every call for some number generation increments this counter. See function df_rand_continue() how this counter is used.

◆ df_sig_def

const char df_sig_def[16] = "ybnqiuxtdsogavh"
static

Array of signature definitions, which will be send to tested process if it has any signature parameters.

◆ df_str_def

const char* df_str_def[]
static
Initial value:
= {
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
NULL
}

Array of strings, which will be send to tested process if it has any string parameters. Feel free to include any strings here (only valid UTF-8). Array must be terminated by NULL string.

◆ df_str_len

long df_str_len
static

Length of pseudo-random strings