func
stringlengths
181
23.6k
path
stringlengths
12
123
source
stringclasses
2 values
label
int64
0
40
void bad() char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; dest [ i ] = data [ i ]; dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
78292/CWE127_Buffer_Underread__new_char_loop_43.cpp
SARD
3
void CWE127_Buffer_Underread__char_declare_memmove_11_bad() char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; memmove ( dest , data , 100 * sizeof ( char ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
77572/CWE127_Buffer_Underread__char_declare_memmove_11.c
SARD
3
static void goodG2B() char * data ; char * dataGoodBuffer = ( char * ) ALLOCA ( ( 10 + 1 ) * sizeof ( char ) ) ; data = dataGoodBuffer; data [ 0 ] = '\0'; CWE121_Stack_Based_Buffer_Overflow__CWE193_char_alloca_memmove_63b_goodG2BSink ( & data ); void CWE121_Stack_Based_Buffer_Overflow__CWE193_char_alloca_memmove_63b_goodG2BSink(char * * dataPtr) char * data = * dataPtr ; char source [ 10 + 1 ] = SRC_STRING ; memmove ( data , source , ( strlen ( source ) + 1 ) * sizeof ( char ) ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
63181/CWE121_Stack_Based_Buffer_Overflow__CWE193_char_alloca_memmove_63b.c
SARD
0
static void goodB2G1() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( staticTrue ) size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) fclose ( pFile );
80206/CWE134_Uncontrolled_Format_String__char_file_w32_vsnprintf_05.c
SARD
0
void bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) baseObject -> action ( data ); void CWE78_OS_Command_Injection__char_listen_socket_w32_spawnv_82_bad::action(char * data)
120292/CWE78_OS_Command_Injection__char_listen_socket_w32_spawnv_82a.cpp
SARD
0
static void build_state_zero(struct dfa *d) d -> tralloc = 1; d -> trcount = 0; d -> realtrans = ( ( sizeof ( ( * d -> realtrans ) ) == 1 ? xzalloc ( ( d -> tralloc + 1 ) ) : xcalloc ( ( d -> tralloc + 1 ) , sizeof ( ( * d -> realtrans ) ) ) ) ); while ( 0 ) d -> trans = d -> realtrans + 1; d -> fails = ( ( sizeof ( ( * d -> fails ) ) == 1 ? xzalloc ( ( d -> tralloc ) ) : xcalloc ( ( d -> tralloc ) , sizeof ( ( * d -> fails ) ) ) ) ); while ( 0 ) d -> success = ( ( sizeof ( ( * d -> success ) ) == 1 ? xmalloc ( ( d -> tralloc ) ) : xnmalloc ( ( d -> tralloc ) , sizeof ( ( * d -> success ) ) ) ) ); while ( 0 ) d -> newlines = ( ( sizeof ( ( * d -> newlines ) ) == 1 ? xmalloc ( ( d -> tralloc ) ) : xnmalloc ( ( d -> tralloc ) , sizeof ( ( * d -> newlines ) ) ) ) ); while ( 0 ) build_state ( 0 , d ); static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) position_set follows ; alloc_position_set ( & follows , d -> nleaves ); static void alloc_position_set(position_set *s,size_t size) s -> elems = ( ( sizeof ( ( * s -> elems ) ) == 1 ? xmalloc ( size ) : xnmalloc ( size , sizeof ( ( * s -> elems ) ) ) ) ); while ( 0 ) s -> alloc = size; s -> nelem = 0;
150042/dfa.c
SARD
0
static rlc_am_reassemble(tvbuff_t *tvb, guint8 offs, packet_info proto_tree *tree, proto_tree enum rlc_channel_type channel, guint16 seq, gboolean poll_set, struct rlc_li guint16 num_li, gboolean final, gboolean li_is_on_2_bytes) guint8 i ; for (i = 0; i < num_li; i++) if ( ( ! li_is_on_2_bytes && ( li [ i ] . li == 0x7e ) ) || ( li [ i ] . li == 0x7ffe ) ) if ( ( ! li_is_on_2_bytes && ( li [ i ] . li == 0x7f ) ) || ( li [ i ] . li == 0x7fff ) ) offs += tvb_captured_length_remaining ( tvb , offs ); if ( global_rlc_perform_reassemby ) add_fragment ( RLC_AM , tvb , pinfo , li [ i ] . tree , offs , seq , i , li [ i ] . len , TRUE ); offs += li [ i ] . len; static struct rlc_frag add_fragment(enum rlc_mode mode, tvbuff_t *tvb, packet_info proto_tree *tree, guint16 offset, guint16 seq, guint16 guint16 len, gboolean final) struct rlc_channel ch_lookup ; int snmod ; if ( rlc_channel_assign ( & ch_lookup , mode , pinfo ) == - 1 ) snmod = getChannelSNModulus ( & ch_lookup ); if ( g_hash_table_lookup_extended ( reassembled_table , & frag_lookup , & orig_key , & value ) ) frags = get_frags ( pinfo , & ch_lookup ); endlist = get_endlist ( pinfo , & ch_lookup ); if ( pinfo -> fd -> flags . visited ) if ( tree && len > 0 ) if ( endlist -> list && endlist -> list -> next ) gint16 start = ( GPOINTER_TO_INT ( endlist -> list -> data ) + 1 ) % snmod ; gint16 end = GPOINTER_TO_INT ( endlist -> list -> next -> data ) ; gint16 missing = start ; gboolean wecanreasmmore = TRUE ; for (; moduloCompare(missing,end,snmod ) <= 0; missing = (missing+1)%snmod) if ( frags [ missing ] == NULL ) wecanreasmmore = FALSE; if ( wecanreasmmore ) reassemble_sequence ( frags , endlist , & ch_lookup , start , end ); static reassemble_sequence(struct rlc_frag ** frags, struct rlc_seqlist * struct rlc_channel * ch_lookup, guint16 start, guint16 end) struct rlc_sdu * sdu = rlc_sdu_create ( ) ; reassemble_data ( ch_lookup , sdu , NULL ); static reassemble_data(struct rlc_channel *ch, struct rlc_sdu *sdu, struct rlc_frag *frag) struct rlc_frag * temp ; guint16 offs = 0 ; if ( ! sdu || ! ch || ! sdu -> frags ) if ( sdu -> data ) if ( frag ) sdu -> reassembled_in = frag; sdu -> reassembled_in = sdu -> last; sdu -> data = ( guint8 * ) wmem_alloc ( wmem_file_scope ( ) , sdu -> len ); temp = sdu -> frags; while ( temp && ( ( offs + temp -> len ) <= sdu -> len ) ) memcpy ( sdu -> data + offs , temp -> data , temp -> len ); temp -> data = NULL; g_hash_table_insert ( reassembled_table , temp , sdu ); offs += temp -> len; temp = temp -> next;
CVE-2016-6508/wireshark_2.0.4_CVE_2016_6508_epan_dissectors_packet-rlc.c
NVD
0
static void goodB2G2() int count ; count = - 1; if ( GLOBAL_CONST_FIVE == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; count = atoi ( inputBuffer ); while ( 0 ) if ( GLOBAL_CONST_FIVE == 5 ) const char * filename = "output_good.txt" ; if ( count > 0 && count <= 20 ) pFile = fopen ( filename , "w+" ); if ( pFile == NULL ) if ( strlen ( SENTENCE ) != fwrite ( SENTENCE , sizeof ( char ) , strlen ( SENTENCE ) , pFile ) ) if ( pFile ) fclose ( pFile );
98973/CWE400_Resource_Exhaustion__listen_socket_fwrite_13.c
SARD
0
void CWE680_Integer_Overflow_to_Buffer_Overflow__malloc_fgets_03_bad() if ( 5 == 5 ) char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = atoi ( inputBuffer ); intPointer = ( int * ) malloc ( data * sizeof ( int ) ); for (i = 0; i < (size_t)data; i++) intPointer [ i ] = 0; printIntLine ( intPointer [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( intPointer );
110362/CWE680_Integer_Overflow_to_Buffer_Overflow__malloc_fgets_03.c
SARD
3
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_68b_goodG2BSink() char * data = CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_68_goodG2BData ; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; strncat ( data , source , 100 ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
71400/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_68b.c
SARD
0
int show_help(void *optctx,const char *opt,const char *arg) char * topic ; char * par ; topic = av_strdup ( ( arg ? arg : "" ) ); par = strchr ( topic , '=' ); if ( par ) * ( par ++ ) = 0; if ( ! ( * topic ) ) if ( ! strcmp ( topic , "decoder" ) ) show_help_codec ( par , 0 ); static void show_help_codec(const char *name,int encoder) const AVCodecDescriptor * desc ; const AVCodec * codec ; if ( ! name ) codec = ( ( encoder ? avcodec_find_encoder_by_name ( name ) : avcodec_find_decoder_by_name ( name ) ) ); if ( codec ) if ( desc = avcodec_descriptor_get_by_name ( name ) ) while ( codec = next_codec_for_id ( desc -> id , codec , encoder ) ) static const AVCodec *next_codec_for_id(enum AVCodecID id,const AVCodec *prev,int encoder) while ( prev = ( av_codec_next ( prev ) ) ) if ( ( prev -> id ) == id && ( ( encoder ? av_codec_is_encoder ( prev ) : av_codec_is_decoder ( prev ) ) ) ) return prev ; return ( ( void * ) 0 ) ; print_codec ( codec ); static void print_codec(const AVCodec *c) if ( c -> pix_fmts ) const enum AVPixelFormat * p = c -> pix_fmts ; while ( ( * p ) != AV_PIX_FMT_NONE ) p ++; if ( c -> supported_samplerates ) const int * p = c -> supported_samplerates ; while ( * p != 0 ) char name [ 16 ] ; snprintf ( name , sizeof ( name ) , "%d" , * p ); printf ( " %s" , name ); p ++; printf ( " %s" , name ); av_get_channel_layout_string ( name , ( sizeof ( name ) ) , 0 , * p ); printf ( " %s" , name );
153742/cmdutils.c
SARD
0
static state_num transit_state(struct dfa *d,state_num s,const unsigned char **pp) int mbclen ; int maxlen = 0 ; size_t i ; int * match_lens = ( ( void * ) 0 ) ; size_t nelem = d -> states [ s ] . mbps . nelem ; position_set follows ; if ( nelem > 0 ) match_lens = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) transit_state_consume_1char ( d , s , pp , match_lens , & mbclen , & follows ); static status_transit_state transit_state_consume_1char(struct dfa *d,state_num s,const unsigned char **pp,int *match_lens,int *mbclen,position_set *pps) int k ; state_num s1 ; state_num s2 ; int * work_mbls ; * mbclen = ( mblen_buf [ * pp - buf_begin ] == 0 ? 1 : mblen_buf [ * pp - buf_begin ] ); s1 = s; for (k = 0; k < *mbclen; k++) s2 = s1; rs = transit_state_singlebyte ( d , s2 , ( * pp ) ++ , & s1 ); static status_transit_state transit_state_singlebyte(struct dfa *d,state_num s,const unsigned char *p,state_num *next_state) state_num * t ; state_num works = s ; status_transit_state rval = TRANSIT_STATE_IN_PROGRESS ; while ( rval == TRANSIT_STATE_IN_PROGRESS ) if ( ( t = d -> trans [ works ] ) != ( ( void * ) 0 ) ) works = t [ * p ]; rval = TRANSIT_STATE_DONE; if ( works < 0 ) works = 0; if ( works < 0 ) works = 0; if ( d -> fails [ works ] ) works = d -> fails [ works ] [ * p ]; rval = TRANSIT_STATE_DONE; return rval ; if ( match_lens == ( ( void * ) 0 ) && d -> states [ s ] . mbps . nelem != 0 ) work_mbls = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); static int *check_matching_with_multibyte_ops(struct dfa *d,state_num s,size_t idx) size_t i ; int * rarray ; rarray = ( ( sizeof ( ( * rarray ) ) == 1 ? xmalloc ( d -> states [ s ] . mbps . nelem ) : xnmalloc ( d -> states [ s ] . mbps . nelem , sizeof ( ( * rarray ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> states[s] . mbps . nelem; ++i) position pos = d -> states [ s ] . mbps . elems [ i ] ; switch ( d -> tokens [ pos . index ] ) rarray [ i ] = match_anychar ( d , s , pos , idx ); rarray [ i ] = match_mb_charset ( d , s , pos , idx ); static int match_mb_charset(struct dfa *d,state_num s,position pos,size_t idx) size_t i ; int match_len ; int op_len ; char buffer [ 128 ] ; struct mb_char_classes * work_mbc ; int context ; wchar_t wc ; wc = inputwcs [ idx ]; if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) context = wchar_context ( wc ); if ( ! ( ( ( ( context & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( context & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( context & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) work_mbc = & d -> mbcsets [ d -> multibyte_prop [ pos . index ] >> 2 ]; match_len = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc < 1 << 8 && work_mbc -> cset != ( - 1 ) && tstbit ( ( ( unsigned char ) wc ) , d -> charclasses [ work_mbc -> cset ] ) ) for (i = 0; i < work_mbc -> nch_classes; i++) if ( iswctype ( ( ( wint_t ) wc ) , work_mbc -> ch_classes [ i ] ) ) strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , match_len ); buffer [ match_len ] = '\0'; for (i = 0; i < work_mbc -> nequivs; i++) op_len = ( strlen ( work_mbc -> equivs [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> equivs [ i ] , buffer ) == 0 ) for (i = 0; i < work_mbc -> ncoll_elems; i++) op_len = ( strlen ( work_mbc -> coll_elems [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> coll_elems [ i ] , buffer ) == 0 )
153577/dfa.c
SARD
0
static void xhci_kick_ep(XHCIState *xhci, unsigned int unsigned int epid, unsigned int streamid) XHCIStreamContext * stctx ; XHCIEPContext * epctx ; XHCIRing * ring ; int length ; if ( ! xhci -> slots [ slotid - 1 ] . enabled ) epctx = xhci -> slots [ slotid - 1 ] . eps [ epid - 1 ]; if ( ! epctx ) if ( ! xhci -> slots [ slotid - 1 ] . uport || ! xhci -> slots [ slotid - 1 ] . uport -> dev || ! xhci -> slots [ slotid - 1 ] . uport -> dev -> attached ) if ( epctx -> retry ) XHCITransfer * xfer = epctx -> retry ; if ( xfer -> timed_xfer ) if ( xfer -> running_retry ) xfer -> timed_xfer = 0; xfer -> running_retry = 1; if ( xfer -> iso_xfer ) if ( xhci_setup_packet ( xfer ) < 0 ) if ( xhci_setup_packet ( xfer ) < 0 ) if ( xfer -> packet . status == USB_RET_NAK ) epctx -> retry = NULL; if ( epctx -> state == EP_HALTED ) if ( epctx -> nr_pstreams ) stctx = xhci_find_stream ( epctx , streamid , & err ); if ( stctx == NULL ) ring = & stctx -> ring; ring = & epctx -> ring; streamid = 0; while ( 1 ) XHCITransfer * xfer = & epctx -> transfers [ epctx -> next_xfer ] ; if ( xfer -> running_async || xfer -> running_retry ) length = xhci_ring_chain_length ( xhci , ring ); if ( length < 0 ) if ( length == 0 ) if ( xfer -> trbs && xfer -> trb_alloced < length ) xfer -> trb_count = 0; xfer -> trb_alloced = 0; xfer -> trbs = NULL; if ( ! xfer -> trbs ) xfer -> trbs = g_malloc ( sizeof ( XHCITRB ) * length ); xfer -> trb_alloced = length; xfer -> trb_count = length; xfer -> streamid = streamid; if ( epid == 1 ) if ( xhci_fire_ctl_transfer ( xhci , xfer ) >= 0 ) epctx -> next_xfer = ( epctx -> next_xfer + 1 ) % TD_QUEUE; if ( xhci_fire_transfer ( xhci , xfer , epctx ) >= 0 ) epctx -> next_xfer = ( epctx -> next_xfer + 1 ) % TD_QUEUE; if ( epctx -> state == EP_HALTED ) if ( xfer -> running_retry ) static int xhci_fire_transfer(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx) return xhci_submit ( xhci , xfer , epctx ) ; static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx) xfer -> in_xfer = epctx -> type >> 2; switch ( epctx -> type ) xfer -> pkts = 0; xfer -> iso_xfer = false; xfer -> timed_xfer = true; if ( xfer -> running_retry ) xfer -> pkts = 0; xfer -> iso_xfer = false; xfer -> timed_xfer = false; xfer -> pkts = 1; xfer -> iso_xfer = true; xfer -> timed_xfer = true; if ( xfer -> running_retry ) if ( xhci_setup_packet ( xfer ) < 0 ) if ( ! xfer -> running_async && ! xfer -> running_retry ) xhci_kick_ep ( xhci , xfer -> slotid , xfer -> epid , xfer -> streamid ); static void xhci_kick_ep(XHCIState *xhci, unsigned int unsigned int epid, unsigned int streamid) XHCIStreamContext * stctx ; XHCIEPContext * epctx ; XHCIRing * ring ; if ( ! xhci -> slots [ slotid - 1 ] . enabled ) epctx = xhci -> slots [ slotid - 1 ] . eps [ epid - 1 ]; if ( ! epctx ) if ( ! xhci -> slots [ slotid - 1 ] . uport || ! xhci -> slots [ slotid - 1 ] . uport -> dev || ! xhci -> slots [ slotid - 1 ] . uport -> dev -> attached ) if ( epctx -> retry ) XHCITransfer * xfer = epctx -> retry ; if ( xfer -> timed_xfer ) if ( xfer -> running_retry ) xfer -> timed_xfer = 0; xfer -> running_retry = 1; if ( xfer -> iso_xfer ) if ( xhci_setup_packet ( xfer ) < 0 ) if ( xhci_setup_packet ( xfer ) < 0 ) if ( xfer -> packet . status == USB_RET_NAK ) epctx -> retry = NULL; if ( epctx -> state == EP_HALTED ) if ( epctx -> nr_pstreams ) stctx = xhci_find_stream ( epctx , streamid , & err ); if ( stctx == NULL ) ring = & stctx -> ring; ring = & epctx -> ring; assert ( ring -> dequeue != 0 );
CVE-2016-7466/qemu_2.3.0_CVE-2016-7466_hcd-xhci.c
NVD
0
static void goodB2G2() if ( STATIC_CONST_FIVE == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); if ( data != 0 ) printIntLine ( 100 % data ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
95015/CWE369_Divide_by_Zero__int_connect_socket_modulo_06.c
SARD
0
void CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_18_bad() wchar_t * data ; wchar_t * dataBuffer = ( wchar_t * ) ALLOCA ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' data = dataBuffer - 8; wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcsncpy ( data , source , 100 - 1 ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line )
75375/CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_18.c
SARD
3
void CWE590_Free_Memory_Not_on_Heap__free_char_static_02_bad() if ( 1 ) static char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
108177/CWE590_Free_Memory_Not_on_Heap__free_char_static_02.c
SARD
1
void CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_connect_socket_52_bad() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 )
112549/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_connect_socket_52a.c
SARD
0
static void goodB2G1() if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); if ( data >= 0 && data < ( 10 ) ) printIntLine ( buffer [ data ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
75605/CWE126_Buffer_Overread__CWE129_connect_socket_08.c
SARD
0
static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) int separate_contexts ; state_num state_letter ; if ( d -> searchflag ) separate_contexts = state_separate_contexts ( ( & follows ) ); if ( separate_contexts & 2 ) state_letter = state_index ( d , ( & follows ) , 2 ); static state_num state_index(struct dfa *d,const position_set *s,int context) size_t hash = 0 ; state_num i ; state_num j ; for (i = 0; i < s -> nelem; ++i) hash ^= s -> elems [ i ] . index + s -> elems [ i ] . constraint; for (i = 0; i < d -> sindex; ++i) if ( hash != d -> states [ i ] . hash || s -> nelem != d -> states [ i ] . elems . nelem || context != d -> states [ i ] . context ) if ( j == s -> nelem ) if ( d -> salloc <= d -> sindex + 1 ) size_t new_n_alloc = ( d -> sindex + 1 + ( ! d -> states ) ) ; d -> states = ( x2nrealloc ( ( d -> states ) , & new_n_alloc , sizeof ( ( * d -> states ) ) ) ); d -> salloc = new_n_alloc; while ( 0 ) d -> states [ i ] . hash = hash; alloc_position_set ( & d -> states [ i ] . elems , s -> nelem ); static void alloc_position_set(position_set *s,size_t size) s -> elems = ( ( sizeof ( ( * s -> elems ) ) == 1 ? xmalloc ( size ) : xnmalloc ( size , sizeof ( ( * s -> elems ) ) ) ) ); while ( 0 ) s -> alloc = size; s -> nelem = 0;
150157/dfa.c
SARD
0
void CWE789_Uncontrolled_Mem_Alloc__malloc_char_rand_07_bad() size_t data ; if ( staticFive == 5 ) data = rand ( ); if ( data > strlen ( HELLO_STRING ) ) myString = ( char * ) malloc ( data * sizeof ( char ) ); strcpy ( myString , HELLO_STRING ); printLine ( myString ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( myString );
117181/CWE789_Uncontrolled_Mem_Alloc__malloc_char_rand_07.c
SARD
10
static void goodB2G1() if ( GLOBAL_CONST_TRUE ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = ( float ) atof ( inputBuffer ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); if ( fabs ( data ) > 0.000001 ) int result = ( int ) ( 100.0 / data ) ; printIntLine ( result ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
94682/CWE369_Divide_by_Zero__float_connect_socket_09.c
SARD
0
void tile_manager_get_tile_coordinates(TileManager *tm,Tile *tile,gint *x,gint *y) char * allochezia_filings ; if ( __sync_bool_compare_and_swap ( & undeviated_galliferous , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) stonesoup_read_taint ( & allochezia_filings , "HORNBILL_UNOXIDIZED" ); void stonesoup_read_taint(char** stonesoup_tainted_buff, char* stonesoup_env_var_name) if ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) == NULL || strcmp ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) , "1" ) != 0 ) stonesoup_tainted_file_name = getenv ( stonesoup_env_var_name ); stonesoup_tainted_file = fopen ( stonesoup_tainted_file_name , "rb" ); if ( stonesoup_tainted_file != 0 ) stonesoup_lsize = ftell ( stonesoup_tainted_file ); * stonesoup_tainted_buff = ( ( char * ) ( malloc ( sizeof ( char ) * ( stonesoup_lsize + 1 ) ) ) ); if ( * stonesoup_tainted_buff != 0 ) stonesoup_result = fread ( * stonesoup_tainted_buff , 1 , stonesoup_lsize , stonesoup_tainted_file );
151543/tile-manager.c
SARD
0
static int stonesoup_ev_handler(struct mg_connection *conn, enum mg_event ev) char * ifmatch_header ; char * stonesoup_tainted_buff ; int buffer_size = 1000 ; if ( ev == MG_REQUEST ) ifmatch_header = ( char * ) mg_get_header ( conn , "if-match" ); if ( strcmp ( ifmatch_header , "weak_taint_source_value" ) == 0 ) while ( 1 ) stonesoup_tainted_buff = ( char * ) malloc ( buffer_size * sizeof ( char ) ); data_size = mg_get_var ( conn , "data" , stonesoup_tainted_buff , buffer_size * sizeof ( char ) ); if ( data_size < buffer_size ) buffer_size = buffer_size * 2; stonesoup_handle_taint ( stonesoup_tainted_buff ); void stonesoup_handle_taint(char *mesially_photopolymer) if ( mesially_photopolymer != 0 ) if ( mesially_photopolymer != 0 ) free ( ( ( char * ) mesially_photopolymer ) );
151920/xact.c
SARD
0
static void goodB2G2() wchar_t * password ; wchar_t passwordBuffer [ 100 ] = L "" password = passwordBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t passwordLen = wcslen ( password ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( password + passwordLen ) , ( 100 - passwordLen - 1 ) * sizeof ( wchar_t ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
94212/CWE319_Cleartext_Tx_Sensitive_Info__w32_wchar_t_connect_socket_21.c
SARD
0
void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_18_bad() char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = strtoul ( inputBuffer , NULL , 0 ); if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); printWLine ( myString ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( myString );
117288/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_18.c
SARD
10
void CWE126_Buffer_Overread__malloc_char_memmove_64b_badSink(void * dataVoidPtr) char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; memmove ( dest , data , strlen ( dest ) * sizeof ( char ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
76366/CWE126_Buffer_Overread__malloc_char_memmove_64b.c
SARD
3
static void goodB2G2() wchar_t * data ; data = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ); data [ 0 ] = L '\0' size_t dataLen = wcslen ( data ) ; wchar_t * environment = GETENV ( ENV_VARIABLE ) ; if ( environment != NULL ) wcsncat ( data + dataLen , environment , 100 - dataLen - 1 ); if ( globalTrue ) size_t i ; for (i=0; i < wcslen(data); i++) if ( data [ i ] == SEARCH_CHAR )
112912/CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_environment_10.c
SARD
0
RestyleManager::ReparentStyleContext(nsIFrame* aFrame) nsStyleContext * oldContext = aFrame -> StyleContext ( ) ; nsRefPtr < nsStyleContext > newContext ; nsIFrame * providerFrame = aFrame -> GetParentStyleContextFrame ( ) ; bool isChild = providerFrame && providerFrame -> GetParent ( ) == aFrame ; nsStyleContext * newParentContext = nullptr ; if ( isChild ) newParentContext = providerFrame -> StyleContext ( ); if ( providerFrame ) newParentContext = providerFrame -> StyleContext ( ); nsIFrame * prevContinuation = GetPrevContinuationWithPossiblySameStyle ( aFrame ) ; nsStyleContext * prevContinuationContext ; bool copyFromContinuation = prevContinuation && ( prevContinuationContext = prevContinuation -> StyleContext ( ) ) -> GetPseudo ( ) == oldContext -> GetPseudo ( ) && prevContinuationContext -> GetParent ( ) == newParentContext ; if ( copyFromContinuation ) newContext = prevContinuationContext; nsIFrame * parentFrame = aFrame -> GetParent ( ) ; Element * element = ElementForStyleContext ( parentFrame ? parentFrame -> GetContent ( ) : nullptr , aFrame , oldContext -> GetPseudoType ( ) ) ; nsIContent * pseudoElementContent = aFrame -> GetContent ( ) ; Element * pseudoElement = ( pseudoElementContent && pseudoElementContent -> IsElement ( ) ) ? pseudoElementContent -> AsElement ( ) : nullptr ; newContext = mPresContext -> StyleSet ( ) -> ReparentStyleContext ( oldContext , newParentContext , element , pseudoElement ); if ( newContext ) if ( newContext != oldContext ) VerifyStyleTree ( mPresContext , aFrame , newParentContext ); static VerifyStyleTree(nsPresContext* aPresContext, nsIFrame* nsStyleContext* aParentContext) nsIFrame :: ChildListIterator lists ( aFrame ) ; for (; !lists.IsDone(); lists.Next()) nsFrameList :: Enumerator childFrames ( lists . CurrentList ( ) ) ; for (; !childFrames.AtEnd(); childFrames.Next()) nsIFrame * child = childFrames . get ( ) ; if ( ! ( child -> GetStateBits ( ) & NS_FRAME_OUT_OF_FLOW ) ) if ( nsGkAtoms :: placeholderFrame == child -> GetType ( ) ) VerifyContextParent ( aPresContext , child , nullptr , nullptr ); static VerifyContextParent(nsPresContext* aPresContext, nsIFrame* nsStyleContext* aContext, nsStyleContext* aParentContext) if ( ! aContext ) aContext = aFrame -> StyleContext ( ); if ( ! aParentContext ) nsIFrame * providerFrame = aFrame -> GetParentStyleContextFrame ( ) ; if ( providerFrame ) aParentContext = providerFrame -> StyleContext ( ); nsStyleContext * actualParentContext = aContext -> GetParent ( ) ; if ( aParentContext ) if ( aParentContext != actualParentContext ) DumpContext ( aFrame , aContext ); static DumpContext(nsIFrame* aFrame, nsStyleContext* aContext) if ( aFrame ) nsAutoString name ; fputs ( NS_LossyConvertUTF16toASCII ( name ) . get ( ) , stdout );
CVE-2015-0826/Firefox_35.0b8_CVE_2015_0826_layout_base_RestyleManager.cpp
NVD
0
static void good1() if ( globalReturnsTrueOrFalse ( ) ) int valGoodSink ; if ( ! stdThreadLockCreate ( & gGoodLock ) ) if ( ! stdThreadCreate ( helperGood , ( void * ) & valGoodSink , & threadB ) ) threadB = NULL; stdThread threadB = NULL ; int valGoodSink ; valGoodSink = 0; if ( ! stdThreadLockCreate ( & gGoodLock ) ) if ( ! stdThreadCreate ( helperGood , ( void * ) & valGoodSink , & threadB ) ) int stdThreadCreate(stdThreadRoutine start, void *args, stdThread *thread) uintptr_t handle ; stdThread my_thread ; my_thread = ( stdThread ) malloc ( sizeof ( * my_thread ) ); if ( my_thread == NULL ) return 0 ; my_thread -> start = start; my_thread -> args = args; handle = _beginthreadex ( NULL , 0 , internal_start , my_thread , 0 , NULL ); if ( handle == 0 ) return 0 ; return 1 ; threadB = NULL; if ( threadB && stdThreadJoin ( threadB ) ) int stdThreadJoin(stdThread thread) DWORD value ; value = WaitForSingleObject ( ( HANDLE ) thread -> handle , INFINITE ); if ( value != WAIT_OBJECT_0 ) return 0 ; return 1 ; stdThreadDestroy ( threadB ); int stdThreadDestroy(stdThread thread) free ( thread );
94631/std_thread.c
SARD
0
void parse_options(void *optctx,int argc,char **argv,const OptionDef *options,void (*parse_arg_function)(void *, const char *)) const char * opt ; int optindex ; int handleoptions = 1 ; int ret ; optindex = 1; while ( optindex < argc ) opt = argv [ optindex ++ ]; if ( handleoptions && opt [ 0 ] == '-' && opt [ 1 ] != '\0' ) if ( opt [ 1 ] == '-' && opt [ 2 ] == '\0' ) handleoptions = 0; opt ++; if ( ( ret = parse_option ( optctx , opt , argv [ optindex ] , options ) ) < 0 ) optindex += ret; int parse_option(void *optctx,const char *opt,const char *arg,const OptionDef *options) const OptionDef * po ; int ret ; po = find_option ( options , opt ); static const OptionDef *find_option(const OptionDef *po,const char *name) const char * p = ( strchr ( name , ':' ) ) ; int len = ( p ? ( p - name ) : strlen ( name ) ) ; while ( po -> name != ( ( void * ) 0 ) ) if ( ! strncmp ( name , po -> name , len ) && strlen ( po -> name ) == len ) po ++; return po ; if ( ! po -> name && opt [ 0 ] == 'n' && opt [ 1 ] == 'o' ) po = find_option ( options , opt + 2 ); static const OptionDef *find_option(const OptionDef *po,const char *name) const char * p = ( strchr ( name , ':' ) ) ; int len = ( p ? ( p - name ) : strlen ( name ) ) ; while ( po -> name != ( ( void * ) 0 ) ) if ( ! strncmp ( name , po -> name , len ) && strlen ( po -> name ) == len ) po ++; return po ; if ( po -> name && po -> flags & 0x00002 ) arg = "0"; if ( po -> flags & 0x00002 ) arg = "1"; if ( ! po -> name ) po = find_option ( options , "default" ); static const OptionDef *find_option(const OptionDef *po,const char *name) const char * p = ( strchr ( name , ':' ) ) ; int len = ( p ? ( p - name ) : strlen ( name ) ) ; while ( po -> name != ( ( void * ) 0 ) ) if ( ! strncmp ( name , po -> name , len ) && strlen ( po -> name ) == len ) po ++; return po ; if ( ! po -> name ) if ( po -> flags & 0x0001 && ! arg ) ret = write_option ( optctx , po , opt , arg ); static int write_option(void *optctx,const OptionDef *po,const char *opt,const char *arg) void * dst = po -> flags & ( 0x4000 | 0x8000 ) ? ( ( ( uint8_t * ) optctx ) + po -> u . off ) : po -> u . dst_ptr ; int * dstcount ; if ( po -> flags & 0x8000 ) SpecifierOpt * * so = dst ; dstcount = ( ( int * ) ( so + 1 ) ); * so = ( grow_array ( ( * so ) , ( sizeof ( ( * ( * so ) ) ) ) , dstcount , * dstcount + 1 ) ); void *grow_array(void *array,int elem_size,int *size,int new_size) if ( * size < new_size ) uint8_t * tmp = ( av_realloc ( array , ( new_size * elem_size ) ) ) ; memset ( ( tmp + * size * elem_size ) , 0 , ( ( new_size - * size ) * elem_size ) ); return tmp ;
150415/cmdutils.c
SARD
0
static void goodG2B1() int * data ; int * dataGoodBuffer = ( int * ) ALLOCA ( 100 * sizeof ( int ) ) ; if ( GLOBAL_CONST_FIVE != 5 ) data = dataGoodBuffer; int source [ 100 ] = { 0 } ; memcpy ( data , source , 100 * sizeof ( int ) ); printIntLine ( data [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
64604/CWE121_Stack_Based_Buffer_Overflow__CWE805_int_alloca_memcpy_13.c
SARD
0
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memcpy_34_bad() int64_t * data ; CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memcpy_34_unionType myUnion ; data = NULL; data = ( int64_t * ) malloc ( 50 * sizeof ( int64_t ) ); myUnion . unionFirst = data; int64_t * data = myUnion . unionSecond ; int64_t source [ 100 ] = { 0 } ; memcpy ( data , source , 100 * sizeof ( int64_t ) ); printLongLongLine ( data [ 0 ] ); void printLongLongLine (int64_t longLongIntNumber) printf ( "%lld\n" , longLongIntNumber ); free ( data );
71575/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memcpy_34.c
SARD
3
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); funcPtr ( data );
108967/CWE606_Unchecked_Loop_Condition__char_connect_socket_65a.c
SARD
0
void CWE605_Multiple_Binds_Same_Port__basic_06_bad() if ( STATIC_CONST_FIVE == 5 ) char data [ 100 ] = "" ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; size_t dataLen = strlen ( data ) ; int bOptLen = sizeof ( BOOL ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) if ( setsockopt ( listenSocket , SOL_SOCKET , SO_REUSEADDR , ( char * ) & bOptVal , bOptLen ) != 0 ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , data + dataLen , ( int ) ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ recvResult ] = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 )
108917/CWE605_Multiple_Binds_Same_Port__basic_06.c
SARD
39
void CWE510_Trapdoor__hostname_based_logic_03_bad() if ( 5 == 5 ) WSADATA wsaData ; struct sockaddr_in service , acceptService ; char hostname [ NI_MAXHOST ] ; char servInfo [ NI_MAXSERV ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( 20000 ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , 5 ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) if ( getsockname ( acceptSocket , ( struct sockaddr * ) & acceptService , & acceptServiceLen ) == - 1 ) if ( getnameinfo ( ( struct sockaddr * ) & acceptService , sizeof ( struct sockaddr ) , hostname , NI_MAXHOST , servInfo , NI_MAXSERV , NI_NUMERICSERV ) != 0 ) if ( strcmp ( "admin.google.com" , hostname ) == 0 ) if ( send ( acceptSocket , ADMIN_MESSAGE , strlen ( ADMIN_MESSAGE ) , 0 ) == SOCKET_ERROR ) while ( 0 )
105169/CWE510_Trapdoor__hostname_based_logic_03.c
SARD
34
static void goodG2B() char * data ; data = NULL; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cpy_64b_goodG2BSink ( & data ); void CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cpy_64b_goodG2BSink(void * dataVoidPtr) char * * dataPtr = ( char * * ) dataVoidPtr ; char * data = ( * dataPtr ) ; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; strcpy ( data , source ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
72884/CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cpy_64b.c
SARD
0
void bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); baseObject -> action ( data ); void CWE78_OS_Command_Injection__char_connect_socket_execl_82_bad::action(char * data)
117988/CWE78_OS_Command_Injection__char_connect_socket_execl_82a.cpp
SARD
0
static void goodB2G1() size_t data ; data = 0; if ( 5 == 5 ) data = rand ( ); if ( 5 != 5 ) char * myString ; if ( data > strlen ( HELLO_STRING ) && data < 100 ) myString = new char [ data ]; strcpy ( myString , HELLO_STRING ); printLine ( myString ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); delete [ ] myString
117657/CWE789_Uncontrolled_Mem_Alloc__new_char_rand_03.cpp
SARD
0
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; CWE134_Uncontrolled_Format_String__char_connect_socket_vprintf_68_goodB2GData = data;
79330/CWE134_Uncontrolled_Format_String__char_connect_socket_vprintf_68a.c
SARD
0
static void goodG2B() char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memcpy ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
64129/CWE121_Stack_Based_Buffer_Overflow__CWE805_char_declare_memcpy_18.c
SARD
0
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; CWE134_Uncontrolled_Format_String__char_listen_socket_snprintf_64b_goodB2GSink ( & data ); void CWE134_Uncontrolled_Format_String__char_listen_socket_snprintf_64b_goodB2GSink(void * dataVoidPtr) char * * dataPtr = ( char * * ) dataVoidPtr ; char * data = ( * dataPtr ) ; SNPRINTF ( dest , 100 - 1 , "%s" , data );
80382/CWE134_Uncontrolled_Format_String__char_listen_socket_snprintf_64a.c
SARD
0
static void goodB2G1() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( staticFive == 5 ) size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0'; fclose ( pFile ); if ( sscanf ( data , "%d" , & n ) == 1 )
109080/CWE606_Unchecked_Loop_Condition__char_file_07.c
SARD
0
static void goodB2G1() size_t data ; data = 0; if ( 5 == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) if ( 5 != 5 ) char * myString ; if ( data > strlen ( HELLO_STRING ) && data < 100 ) myString = ( char * ) malloc ( data * sizeof ( char ) ); strcpy ( myString , HELLO_STRING ); free ( myString );
117129/CWE789_Uncontrolled_Mem_Alloc__malloc_char_listen_socket_03.c
SARD
0
static void goodB2G() char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = atoi ( inputBuffer ); if ( data > 0 ) if ( data < ( INT_MAX / 2 ) ) int result = data * 2 ; printIntLine ( result ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
83183/CWE190_Integer_Overflow__int_fgets_multiply_18.c
SARD
0
void CWE194_Unexpected_Sign_Extension__connect_socket_malloc_66_bad() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
86324/CWE194_Unexpected_Sign_Extension__connect_socket_malloc_66a.c
SARD
0
static void eepro100_write(void *opaque, hwaddr uint64_t data, unsigned size) EEPRO100State * s = opaque ; switch ( size ) eepro100_write2 ( s , addr , data ); static void eepro100_write2(EEPRO100State * s, uint32_t addr, uint16_t val) switch ( addr ) TRACE ( OTHER , logout ( "addr=%s val=0x%04x\n" , regname ( addr ) , val ) ); static char *regname(uint32_t addr) static char buf [ 32 ] ; if ( addr < PCI_IO_SIZE ) snprintf ( buf , sizeof ( buf ) , "??? 0x%08x" , addr ); return buf ;
CVE-2016-9101/qemu_2.3.0_CVE-2016-9101_eepro100.c
NVD
0
void CWE126_Buffer_Overread__CWE129_connect_socket_11_bad() if ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
75608/CWE126_Buffer_Overread__CWE129_connect_socket_11.c
SARD
0
void CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memcpy_02_bad() int data ; data = - 1; char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) memcpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
87871/CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memcpy_02.c
SARD
20
conversation_t *find_or_create_conversation(packet_info *pinfo) if ( ( conv = find_conversation ( pinfo -> fd -> num , ( & pinfo -> src ) , ( & pinfo -> dst ) , pinfo -> ptype , pinfo -> srcport , pinfo -> destport , 0 ) ) == ( ( void * ) 0 ) ) conversation_t *find_conversation(const guint32 frame_num,const address *addr_a,const address *addr_b,const port_type ptype,const guint32 port_a,const guint32 port_b,const guint options) conversation_t * conversation ; if ( ! ( options & ( 0x01 | 0x02 ) ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_exact , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_exact , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x02 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( conversation -> options & 0x01 ) && ptype != PT_UDP ) if ( ! ( conversation -> options & 0x08 ) ) conversation = conversation_create_from_template ( conversation , addr_b , 0 ); static conversation_t *conversation_create_from_template(conversation_t *conversation,const address *addr2,const guint32 port2) if ( conversation -> options & 0x08 && ( conversation -> key_ptr -> ptype ) != PT_UDP ) conversation_t * new_conversation_from_template ; guint options = conversation -> options & ( ~ ( 0x08 | 0x01 | 0x02 ) ) ; if ( conversation -> options & 0x01 && conversation -> options & 0x02 ) if ( conversation -> options & 0x02 ) if ( conversation -> options & 0x01 ) new_conversation_from_template = conversation_new ( conversation -> setup_frame , ( & conversation -> key_ptr -> addr1 ) , addr2 , conversation -> key_ptr -> ptype , conversation -> key_ptr -> port1 , conversation -> key_ptr -> port2 , options ); conversation_t *conversation_new(const guint32 setup_frame,const address *addr1,const address *addr2,const port_type ptype,const guint32 port1,const guint32 port2,const guint options) guint8 * SE_COPY_ADDRESS_data ; SE_COPY_ADDRESS_data = ( se_alloc ( ( addr1 -> len ) ) ); memcpy ( SE_COPY_ADDRESS_data , addr1 -> data , ( addr1 -> len ) ); ( & new_key -> addr1 ) -> data = SE_COPY_ADDRESS_data; ( & new_key -> addr2 ) -> type = addr2 -> type; ( & new_key -> addr2 ) -> len = addr2 -> len; memcpy ( SE_COPY_ADDRESS_data , addr2 -> data , ( addr2 -> len ) ); ( & new_key -> addr2 ) -> data = SE_COPY_ADDRESS_data; new_key -> ptype = ptype; new_key -> port1 = port1; new_key -> port2 = port2; conversation -> key_ptr = new_key; conversation_insert_into_hashtable ( hashtable , conversation ); return conversation ;
149895/conversation.c
SARD
0
static void goodG2BSink() int data = CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_malloc_45_goodG2BData ; if ( data < 100 ) char * dataBuffer = ( char * ) malloc ( data ) ; memset ( dataBuffer , 'A' , data - 1 ); dataBuffer [ data - 1 ] = '\0'; printLine ( dataBuffer ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( dataBuffer );
87850/CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_malloc_45.c
SARD
0
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); funcPtr ( data );
90673/CWE23_Relative_Path_Traversal__char_listen_socket_ofstream_65a.cpp
SARD
0
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; if ( globalFive == 5 ) size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( FILENAME_MAX - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) fclose ( pFile );
96319/CWE36_Absolute_Path_Traversal__char_file_ifstream_14.cpp
SARD
0
static void goodG2B1() wchar_t * data ; wchar_t * dataGoodBuffer = ( wchar_t * ) ALLOCA ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBadBuffer , L 'A' , 50 - 1 dataBadBuffer [ 50 - 1 ] = L wmemset ( dataGoodBuffer , L 'A' , 100 - 1 dataGoodBuffer [ 100 - 1 ] = L '\0' if ( globalReturnsFalse ( ) ) int globalReturnsFalse() return 0 ; data = dataGoodBuffer; wchar_t dest [ 100 ] ; wmemset ( dest , L 'C' , 100 - 1 dest [ 100 - 1 ] = L '\0' memcpy ( dest , data , wcslen ( dest ) * sizeof ( wchar_t ) ); printWLine ( dest ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line )
76860/CWE126_Buffer_Overread__wchar_t_alloca_memcpy_11.c
SARD
0
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; goodB2GSource ( data ); static void goodB2GSource(char * &data) size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0';
80084/CWE134_Uncontrolled_Format_String__char_file_snprintf_43.cpp
SARD
0
void stonesoup_setup_printf_context() ss_tc_root = getenv ( "SS_TC_ROOT" ); if ( ss_tc_root != NULL ) size_dirpath = strlen ( ss_tc_root ) + strlen ( "testData" ) + 2; dirpath = ( char * ) malloc ( size_dirpath * sizeof ( char ) ); if ( dirpath != NULL ) sprintf ( dirpath , "%s/%s" , ss_tc_root , "testData" ); if ( stat ( dirpath , & st ) == - 1 ) retval = mkdir ( dirpath , 0700 ); if ( retval == 0 )
149893/dynahash.c
SARD
0
static void goodG2B1() char * data ; data = NULL; if ( 5 != 5 ) data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; strncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = '\0'; free ( data );
71410/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncpy_03.c
SARD
0
void bad() char * data ; data = ( char * ) calloc ( 100 , sizeof ( char ) ); strcpy ( data , "A String" ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); baseObject -> action ( data ); void CWE401_Memory_Leak__char_calloc_82_bad::action(char * data)
99246/CWE401_Memory_Leak__char_calloc_82a.cpp
SARD
0
void bad() wchar_t * data ; wchar_t dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; badSource ( data ); void badSource(wchar_t * &data) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
90814/CWE23_Relative_Path_Traversal__wchar_t_connect_socket_fopen_62b.cpp
SARD
0
static void goodG2B() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; strcat ( data , "c:\\temp\\file.txt" ); dataArray [ 2 ] = data; goodG2BSink ( dataArray ); void goodG2BSink(char * dataArray[]) char * data = dataArray [ 2 ] ; inputFile . open ( ( char * ) data );
96584/CWE36_Absolute_Path_Traversal__char_listen_socket_ifstream_66a.cpp
SARD
0
static void goodB2G() if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); if ( data >= 0 && data < ( 10 ) ) buffer [ data ] = 1; printIntLine ( buffer [ i ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); if ( data >= 0 && data < ( 10 ) ) buffer [ data ] = 1; printIntLine ( buffer [ i ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
73561/CWE124_Buffer_Underwrite__CWE839_connect_socket_12.c
SARD
0
static void goodG2B() char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer; dataMap [ 0 ] = data; dataMap [ 1 ] = data; dataMap [ 2 ] = data; goodG2BSink ( dataMap ); void goodG2BSink(map<int, char *> dataMap) char * data = dataMap [ 2 ] ; memcpy ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
73859/CWE124_Buffer_Underwrite__char_alloca_memcpy_74a.cpp
SARD
0
void bad() wchar_t * data ; wchar_t dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; size_t dataLen = wcslen ( data ) ; FILE * pFile ; if ( FILENAME_MAX - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) if ( fgetws ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , pFile ) == NULL ) fclose ( pFile );
91524/CWE23_Relative_Path_Traversal__wchar_t_file_fopen_41.cpp
SARD
0
void bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; badSource ( data ); static void badSource(char * &data) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
117969/CWE78_OS_Command_Injection__char_connect_socket_execl_43.cpp
SARD
0
gboolean try_conversation_dissector(const address *addr_a,const address *addr_b,const port_type ptype,const guint32 port_a,const guint32 port_b,tvbuff_t *tvb,packet_info *pinfo,proto_tree *tree) conversation_t * conversation ; conversation = find_conversation ( pinfo -> fd -> num , addr_a , addr_b , ptype , port_a , port_b , 0 ); conversation_t *find_conversation(const guint32 frame_num,const address *addr_a,const address *addr_b,const port_type ptype,const guint32 port_a,const guint32 port_b,const guint options) conversation_t * conversation ; if ( ! ( options & ( 0x01 | 0x02 ) ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_exact , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_exact , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x02 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x01 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_b , addr_a , ptype , port_b , port_a ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x01 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_port2 , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_port2 , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( conversation -> options & 0x02 ) && ptype != PT_UDP ) if ( ! ( conversation -> options & 0x08 ) ) conversation_set_port2 ( conversation , port_b ); void conversation_set_port2(conversation_t *conv,const guint32 port) ( void ) ( ! ( conv -> options & 0x08 ) ? ( ( void ) 0 ) : ( ( getenv ( "WIRESHARK_ABORT_ON_DISSECTOR_BUG" ) != ( ( void * ) 0 ) ? abort ( ) : except_throw ( 1 , 4 , ( ep_strdup_printf ( "%s:%u: failed assertion \"%s\" (%s)" , "conversation.c" , 680 , "!(conv->options & 0x08)" , "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask" ) ) ) ) ) );
151269/conversation.c
SARD
0
void bad() char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; memmove ( dest , data , strlen ( dest ) * sizeof ( char ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
76625/CWE126_Buffer_Overread__new_char_memmove_08.cpp
SARD
3
static void goodG2B() char * data ; data = NULL; data = goodG2BSource ( data ); static char * goodG2BSource(char * data) data = ( char * ) malloc ( ( 10 + 1 ) * sizeof ( char ) ); return data ; char source [ 10 + 1 ] = SRC_STRING ; strncpy ( data , source , strlen ( source ) + 1 ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
70953/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_char_ncpy_42.c
SARD
0
void CWE122_Heap_Based_Buffer_Overflow__c_CWE806_char_ncpy_41_bad() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); memset ( data , 'A' , 100 - 1 ); data [ 100 - 1 ] = '\0'; CWE122_Heap_Based_Buffer_Overflow__c_CWE806_char_ncpy_41_badSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE806_char_ncpy_41_badSink(char * data) char dest [ 50 ] = "" ; strncpy ( dest , data , strlen ( data ) ); dest [ 50 - 1 ] = '\0';
72440/CWE122_Heap_Based_Buffer_Overflow__c_CWE806_char_ncpy_41.c
SARD
3
void CWE690_NULL_Deref_From_Return__char_calloc_04_bad() char * data ; data = NULL; data = ( char * ) calloc ( 20 , sizeof ( char ) ); if ( STATIC_CONST_TRUE ) strcpy ( data , "Initialize" ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
110981/CWE690_NULL_Deref_From_Return__char_calloc_04.c
SARD
2
static void goodB2G1() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; count = atoi ( inputBuffer ); while ( 0 ) goodB2G1Sink ( count ); static void goodB2G1Sink(int count) if ( count > 0 && count <= 2000 ) SLEEP ( count );
98595/CWE400_Resource_Exhaustion__connect_socket_sleep_21.c
SARD
0
static void goodB2G() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; count = atoi ( inputBuffer ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); CWE400_Resource_Exhaustion__connect_socket_for_loop_53b_goodB2GSink ( count ); void CWE400_Resource_Exhaustion__connect_socket_for_loop_53b_goodB2GSink(int count) CWE400_Resource_Exhaustion__connect_socket_for_loop_53c_goodB2GSink ( count ); void CWE400_Resource_Exhaustion__connect_socket_for_loop_53c_goodB2GSink(int count) CWE400_Resource_Exhaustion__connect_socket_for_loop_53d_goodB2GSink ( count ); void CWE400_Resource_Exhaustion__connect_socket_for_loop_53d_goodB2GSink(int count) if ( count > 0 && count <= 20 ) for (i = 0; i < (size_t)count; i++)
98512/CWE400_Resource_Exhaustion__connect_socket_for_loop_53a.c
SARD
0
static status_transit_state transit_state_consume_1char(struct dfa *d,state_num s,const unsigned char **pp,int *match_lens,int *mbclen,position_set *pps) int k ; state_num s1 ; state_num s2 ; * mbclen = ( mblen_buf [ * pp - buf_begin ] == 0 ? 1 : mblen_buf [ * pp - buf_begin ] ); s1 = s; for (k = 0; k < *mbclen; k++) s2 = s1; rs = transit_state_singlebyte ( d , s2 , ( * pp ) ++ , & s1 ); static status_transit_state transit_state_singlebyte(struct dfa *d,state_num s,const unsigned char *p,state_num *next_state) state_num * t ; state_num works = s ; status_transit_state rval = TRANSIT_STATE_IN_PROGRESS ; while ( rval == TRANSIT_STATE_IN_PROGRESS ) if ( ( t = d -> trans [ works ] ) != ( ( void * ) 0 ) ) works = t [ * p ]; rval = TRANSIT_STATE_DONE; if ( works < 0 ) works = 0; if ( works < 0 ) works = 0; if ( d -> fails [ works ] ) works = d -> fails [ works ] [ * p ]; rval = TRANSIT_STATE_DONE; build_state ( works , d ); static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) leaf_set * grps ; charclass * labels ; size_t ngrps = 0 ; position pos ; charclass matches ; int matchesf ; charclass intersect ; int intersectf ; charclass leftovers ; int leftoversf ; size_t i ; size_t j ; size_t k ; grps = ( ( sizeof ( ( * grps ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * grps ) ) ) ) ); while ( 0 ) labels = ( ( sizeof ( ( * labels ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * labels ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> states[s] . elems . nelem; ++i) pos = d -> states [ s ] . elems . elems [ i ]; if ( d -> tokens [ pos . index ] >= 0 && d -> tokens [ pos . index ] < ( 1 << 8 ) ) if ( d -> tokens [ pos . index ] >= CSET ) if ( pos . constraint != 0x777 ) if ( ! ( ( ( ( 4 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= ~newline [ j ]; if ( ! ( ( ( ( 2 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= ~letters [ j ]; if ( ! ( ( ( ( 1 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= letters [ j ] | newline [ j ]; for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )) && !matches[j]; ++j) if ( j == ( ( 1 << 8 ) + 8 * sizeof ( int ) - 1 ) / ( 8 * sizeof ( int ) ) ) for (j = 0; j < ngrps; ++j) if ( d -> tokens [ pos . index ] >= 0 && d -> tokens [ pos . index ] < ( 1 << 8 ) && ! tstbit ( d -> tokens [ pos . index ] , labels [ j ] ) ) intersectf = 0; for (k = 0; k < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++k) ( intersect [ k ] = matches [ k ] & labels [ j ] [ k ] ) ? ( intersectf = 1 ) : 0; if ( ! intersectf ) leftoversf = matchesf = 0; for (k = 0; k < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++k) int match = matches [ k ] ; int label = labels [ j ] [ k ] ; ( leftovers [ k ] = ~match & label ) ? ( leftoversf = 1 ) : 0; ( matches [ k ] = match & ~label ) ? ( matchesf = 1 ) : 0; if ( leftoversf ) copyset ( leftovers , labels [ ngrps ] ); copyset ( intersect , labels [ j ] ); grps [ ngrps ] . elems = ( ( sizeof ( ( * grps [ ngrps ] . elems ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * grps [ ngrps ] . elems ) ) ) ) ); while ( 0 ) memcpy ( grps [ ngrps ] . elems , grps [ j ] . elems , sizeof ( grps [ j ] . elems [ 0 ] ) * grps [ j ] . nelem ); grps [ ngrps ] . nelem = grps [ j ] . nelem; grps [ j ] . elems [ grps [ j ] . nelem ++ ] = pos . index; if ( ! matchesf ) if ( j == ngrps ) copyset ( matches , labels [ ngrps ] ); zeroset ( matches ); grps [ ngrps ] . elems = ( ( sizeof ( ( * grps [ ngrps ] . elems ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * grps [ ngrps ] . elems ) ) ) ) ); while ( 0 ) grps [ ngrps ] . nelem = 1; grps [ ngrps ] . elems [ 0 ] = pos . index; for (i = 0; i < ngrps; ++i) for (j = 0; j < grps[i] . nelem; ++j) for (k = 0; k < d -> follows[grps[i] . elems[j]] . nelem; ++k) insert ( d -> follows [ grps [ i ] . elems [ j ] ] . elems [ k ] , & follows ); for (j = 0; j < follows . nelem; ++j) if ( ! ( d -> multibyte_prop [ follows . elems [ j ] . index ] & 1 ) ) for (j = 0; j < d -> states[0] . elems . nelem; ++j) insert ( d -> states [ 0 ] . elems . elems [ j ] , & follows ); for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) for (k = 0; k < 8 * sizeof(int ); ++k) if ( labels [ i ] [ j ] & 1 << k ) int c = ( j * ( 8 * sizeof ( int ) ) + k ) ; if ( c == eolbyte ) trans [ c ] = state_newline; if ( 1 && ( ( * __ctype_b_loc ( ) ) [ ( int ) c ] & ( ( unsigned short ) _ISalnum ) || c == '_' ) ) trans [ c ] = state_letter; if ( c < 1 << 8 ) trans [ c ] = state; for (i = 0; i < ngrps; ++i) free ( grps [ i ] . elems ); free ( grps );
153747/dfa.c
SARD
0
static void CVE_2012_3553_PATCHED_setsubstate(struct skinny_subchannel *sub, int state) struct skinny_line * l = sub -> line ; struct skinny_subline * subline = sub -> subline ; struct skinny_device * d = l -> device ; struct ast_channel * c = sub -> owner ; pthread_t t ; int actualstate = state ; if ( ! l -> device ) if ( sub -> substate == SUBSTATE_ONHOOK ) if ( state != SUBSTATE_RINGIN && sub -> aa_sched ) sub -> aa_sched = 0; sub -> aa_beep = 0; sub -> aa_mute = 0; if ( ( state == SUBSTATE_RINGIN ) && ( ( d -> hookstate == SKINNY_OFFHOOK ) || ( AST_LIST_NEXT ( AST_LIST_FIRST ( & l -> sub ) , list ) ) ) ) actualstate = SUBSTATE_CALLWAIT; if ( ( state == SUBSTATE_CONNECTED ) && ( ! subline ) && ( AST_LIST_FIRST ( & l -> sublines ) ) ) const char * slastation ; struct skinny_subline * tmpsubline ; slastation = pbx_builtin_getvar_helper ( c , "SLASTATION" ); if ( slastation ) subline = tmpsubline; if ( subline ) subline -> sub = sub; sub -> subline = subline; subline -> callid = sub -> callid; if ( subline ) switch ( actualstate ) if ( actualstate == sub -> substate ) switch ( actualstate ) sub -> substate = SUBSTATE_OFFHOOK; if ( ast_pthread_create ( & t , NULL , skinny_ss , sub -> owner ) ) ast_log ( LOG_WARNING , "Unable to create switch thread: %s\n" , strerror ( errno ) );
CVE-2012-3553/CVE_2012_3553_PATCHED_setsubstate.c
NVD
0
void CWE124_Buffer_Underwrite__malloc_char_ncpy_66b_goodG2BSink(char * dataArray[]) char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; strncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
74468/CWE124_Buffer_Underwrite__malloc_char_ncpy_66b.c
SARD
0
static void goodG2B1() int * data ; int * dataGoodBuffer = ( int * ) ALLOCA ( 100 * sizeof ( int ) ) ; if ( globalFive != 5 ) data = dataGoodBuffer; int source [ 100 ] = { 0 } ; memmove ( data , source , 100 * sizeof ( int ) ); printIntLine ( data [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
64645/CWE121_Stack_Based_Buffer_Overflow__CWE805_int_alloca_memmove_14.c
SARD
0
void CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_21_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); badVaSink ( data , data ); static void badVaSink(char * data, ...) va_start ( args , data ); vsnprintf ( dest , 100 - 1 , data , args ); printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
79356/CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_21.c
SARD
15
static void goodB2G() int count ; count = - 1; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; count = atoi ( inputBuffer ); while ( 0 ) CWE400_Resource_Exhaustion__listen_socket_fwrite_53b_goodB2GSink ( count ); void CWE400_Resource_Exhaustion__listen_socket_fwrite_53b_goodB2GSink(int count) CWE400_Resource_Exhaustion__listen_socket_fwrite_53c_goodB2GSink ( count ); void CWE400_Resource_Exhaustion__listen_socket_fwrite_53c_goodB2GSink(int count) CWE400_Resource_Exhaustion__listen_socket_fwrite_53d_goodB2GSink ( count ); void CWE400_Resource_Exhaustion__listen_socket_fwrite_53d_goodB2GSink(int count) const char * filename = "output_good.txt" ; if ( count > 0 && count <= 20 ) pFile = fopen ( filename , "w+" ); for (i = 0; i < (size_t)count; i++) if ( strlen ( SENTENCE ) != fwrite ( SENTENCE , sizeof ( char ) , strlen ( SENTENCE ) , pFile ) )
98992/CWE400_Resource_Exhaustion__listen_socket_fwrite_53d.c
SARD
0
static void goodG2B1() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( 0 ) strcpy ( data , "C:\\Windows\\System32\\winsrv.dll" ); HMODULE hModule ; hModule = LoadLibraryA ( data ); if ( hModule != NULL ) FreeLibrary ( hModule );
62037/CWE114_Process_Control__w32_char_environment_02.c
SARD
0
void stonesoup_handle_taint(char *aesopic_tastelessness) int pasadis_dorididae = 7 ; if ( aesopic_tastelessness != 0 ) calcaire_nro = ( ( void * ) aesopic_tastelessness ); loquent_forbid = & calcaire_nro; nonpressing_nucla = & loquent_forbid; seminarcosis_almadie ( pasadis_dorididae , nonpressing_nucla ); void seminarcosis_almadie(int surceased_epitaphic,void ***eradication_pearlstone) surceased_epitaphic --; if ( surceased_epitaphic > 0 ) seminarcosis_almadie ( surceased_epitaphic , eradication_pearlstone ); void seminarcosis_almadie(int surceased_epitaphic,void ***eradication_pearlstone) surceased_epitaphic --; if ( surceased_epitaphic > 0 ) seminarcosis_almadie ( surceased_epitaphic , eradication_pearlstone ); void seminarcosis_almadie(int surceased_epitaphic,void ***eradication_pearlstone) surceased_epitaphic --; if ( surceased_epitaphic > 0 ) stonesoup_data = ( struct stonesoup_struct * ) malloc ( sizeof ( struct stonesoup_struct ) ); if ( stonesoup_data != NULL ) stonesoup_data -> before = stonesoup_toupper; memset ( stonesoup_data -> buffer , 0 , 64 ); stonesoup_data -> after = stonesoup_toupper; tracepoint ( stonesoup_trace , variable_signed_integral , "stonesoup_data->before" , stonesoup_data -> before , & stonesoup_data -> before , "INITIAL-STATE" ); tracepoint ( stonesoup_trace , variable_buffer , "stonesoup_data->buffer" , stonesoup_data -> buffer , "INITIAL-STATE" ); tracepoint ( stonesoup_trace , variable_signed_integral , "stonesoup_data->after" , stonesoup_data -> after , & stonesoup_data -> after , "INITIAL-STATE" ); strcpy ( stonesoup_data -> buffer , panthous_zimarra ); tracepoint ( stonesoup_trace , variable_buffer , "stonesoup_data->buffer" , stonesoup_data -> buffer , "CROSSOVER-STATE" ); stonesoup_opt_var = strlen ( stonesoup_data -> buffer ); for (; stonesoup_i < stonesoup_opt_var; ++stonesoup_i) stonesoup_data -> buffer [ stonesoup_i ] = stonesoup_toupper ( stonesoup_data -> buffer [ stonesoup_i ] ); stonesoup_printf ( "%c" , stonesoup_data -> after ( stonesoup_data -> buffer [ stonesoup_i ] ) ); tracepoint ( stonesoup_trace , variable_signed_integral , "stonesoup_i" , stonesoup_i , & stonesoup_i , "FINAL-STATE" ); tracepoint ( stonesoup_trace , variable_buffer , "stonesoup_data->buffer" , stonesoup_data -> buffer , "FINAL-STATE" ); free ( stonesoup_data );
153442/bss_file.c
SARD
3
void dfacomp(const char *s,size_t len,struct dfa *d,int searchflag) dfaanalyze ( d , searchflag ); void dfaanalyze(struct dfa *d,int searchflag) int * nullable ; size_t * nfirstpos ; position * firstpos ; size_t * nlastpos ; position * lastpos ; position_set merged ; position * o_firstpos ; position * o_lastpos ; size_t i ; size_t j ; position * pos ; d -> searchflag = searchflag; nullable = ( ( sizeof ( ( * nullable ) ) == 1 ? xmalloc ( d -> depth ) : xnmalloc ( d -> depth , sizeof ( ( * nullable ) ) ) ) ); while ( 0 ) nfirstpos = ( ( sizeof ( ( * nfirstpos ) ) == 1 ? xmalloc ( d -> depth ) : xnmalloc ( d -> depth , sizeof ( ( * nfirstpos ) ) ) ) ); while ( 0 ) firstpos = ( ( sizeof ( ( * firstpos ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * firstpos ) ) ) ) ); while ( 0 ) o_firstpos = firstpos , firstpos += d -> nleaves; nlastpos = ( ( sizeof ( ( * nlastpos ) ) == 1 ? xmalloc ( d -> depth ) : xnmalloc ( d -> depth , sizeof ( ( * nlastpos ) ) ) ) ); while ( 0 ) lastpos = ( ( sizeof ( ( * lastpos ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * lastpos ) ) ) ) ); while ( 0 ) o_lastpos = lastpos , lastpos += d -> nleaves; d -> follows = ( ( sizeof ( ( * d -> follows ) ) == 1 ? xzalloc ( d -> tindex ) : xcalloc ( d -> tindex , sizeof ( ( * d -> follows ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> tindex; ++i) switch ( d -> tokens [ i ] ) * ( nullable ++ ) = 1; * ( nfirstpos ++ ) = * ( nlastpos ++ ) = 0; pos = lastpos; for (j = 0; j < nlastpos[- 1]; ++j) copy ( ( & merged ) , & d -> follows [ pos [ j ] . index ] ); if ( d -> tokens [ i ] != PLUS ) nullable [ - 1 ] = 1; pos = lastpos + nlastpos [ - 1 ]; if ( nullable [ - 2 ] ) nfirstpos [ - 2 ] += nfirstpos [ - 1 ]; firstpos += nfirstpos [ - 1 ]; if ( nullable [ - 1 ] ) nlastpos [ - 2 ] += nlastpos [ - 1 ]; pos = lastpos + nlastpos [ - 2 ]; for (j = nlastpos[- 1]; j-- > 0; ) pos [ j ] = lastpos [ j ]; lastpos += nlastpos [ - 2 ]; nlastpos [ - 2 ] = nlastpos [ - 1 ]; nullable [ - 2 ] = nullable [ - 1 ] && nullable [ - 2 ]; nfirstpos [ - 2 ] += nfirstpos [ - 1 ]; nlastpos [ - 2 ] += nlastpos [ - 1 ]; nullable [ - 2 ] = nullable [ - 1 ] || nullable [ - 2 ]; * ( nullable ++ ) = d -> tokens [ i ] == BACKREF; * ( nfirstpos ++ ) = * ( nlastpos ++ ) = 1; firstpos -> index = lastpos -> index = i; firstpos -> constraint = lastpos -> constraint = 0x777;
153147/dfa.c
SARD
0
void CWE124_Buffer_Underwrite__char_declare_ncpy_51_bad() char * data ; char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; CWE124_Buffer_Underwrite__char_declare_ncpy_51b_badSink ( data ); void CWE124_Buffer_Underwrite__char_declare_ncpy_51b_badSink(char * data) char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; strncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
74127/CWE124_Buffer_Underwrite__char_declare_ncpy_51b.c
SARD
3
void bad() size_t data ; data = 0; wchar_t * myString ; if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); printWLine ( myString ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( myString );
117441/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_rand_43.cpp
SARD
10
static void goodG2B2() int data ; data = - 1; if ( 5 == 5 ) data = 100 - 1; char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) memmove ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
88112/CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_memmove_03.c
SARD
0
CWE78_OS_Command_Injection__char_connect_socket_w32_spawnv_83_bad::CWE78_OS_Command_Injection__char_connect_socket_w32_spawnv_83_bad(char * dataCopy) data = dataCopy; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 )
118325/CWE78_OS_Command_Injection__char_connect_socket_w32_spawnv_83_bad.cpp
SARD
0
void CWE195_Signed_to_Unsigned_Conversion_Error__connect_socket_malloc_10_bad() if ( globalTrue ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
87447/CWE195_Signed_to_Unsigned_Conversion_Error__connect_socket_malloc_10.c
SARD
0
void CWE244_Heap_Inspection__w32_wchar_t_free_03_bad() if ( 5 == 5 ) wchar_t * password = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ) ; password [ 0 ] = L '\0' if ( fgetws ( password , 100 , stdin ) == NULL ) password [ 0 ] = L '\0' passwordLen = wcslen ( password ); if ( passwordLen > 0 ) password [ passwordLen - 1 ] = L '\0' free ( password );
92036/CWE244_Heap_Inspection__w32_wchar_t_free_03.c
SARD
33
void parse_dir_colors() char * * arg ; char * * c ; char * colors ; char * s ; int i ; if ( Hflag ) if ( getenv ( "TERM" ) == ( ( void * ) 0 ) ) s = getenv ( "TREE_COLORS" ); if ( s == ( ( void * ) 0 ) ) s = getenv ( "LS_COLORS" ); if ( ( s == ( ( void * ) 0 ) || strlen ( s ) == 0 ) && force_color ) s = ":no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.bat=01;32:*.BAT=01;32:*.btm=01;32:*.BTM=01;32:*.cmd=01;32:*.CMD=01;32:*.com=01;32:*.COM=01;32:*.dll=01;32:*.DLL=01;32:*.exe=01;32:*.EXE=01;32:*.arj=01;31:*.bz2=01;31:*.deb=01;31:*.gz=01;31:*.lzh=01;31:*.rpm=01;31:*.tar=01;31:*.taz=01;31:*.tb2=01;31:*.tbz2=01;31:*.tbz=01;31:*.tgz=01;31:*.tz2=01;31:*.z=01;31:*.Z=01;31:*.zip=01;31:*.ZIP=01;31:*.zoo=01;31:*.asf=01;35:*.ASF=01;35:*.avi=01;35:*.AVI=01;35:*.bmp=01;35:*.BMP=01;35:*.flac=01;35:*.FLAC=01;35:*.gif=01;35:*.GIF=01;35:*.jpg=01;35:*.JPG=01;35:*.jpeg=01;35:*.JPEG=01;35:*.m2a=01;35:*.M2a=01;35:*.m2v=01;35:*.M2V=01;35:*.mov=01;35:*.MOV=01;35:*.mp3=01;35:*.MP3=01;35:*.mpeg=01;35:*.MPEG=01;35:*.mpg=01;35:*.MPG=01;35:*.ogg=01;35:*.OGG=01;35:*.ppm=01;35:*.rm=01;35:*.RM=01;35:*.tga=01;35:*.TGA=01;35:*.tif=01;35:*.TIF=01;35:*.wav=01;35:*.WAV=01;35:*.wmv=01;35:*.WMV=01;35:*.xbm=01;35:*.xpm=01;35:"; if ( s == ( ( void * ) 0 ) || ! force_color && ( nocolor || ! isatty ( 1 ) ) ) colors = strcpy ( ( xmalloc ( strlen ( s ) + 1 ) ) , s ); arg = split ( colors , ":" , & n ); char **split(char *str,char *delim,int *nwrds) int n = 128 ; char * * w = ( xmalloc ( sizeof ( char * ) * n ) ) ; w [ * nwrds = 0 ] = strtok ( str , delim ); while ( w [ * nwrds ] ) if ( * nwrds == n - 2 ) w = ( xrealloc ( w , sizeof ( char * ) * ( n += 256 ) ) ); w [ ++ * nwrds ] = strtok ( ( ( void * ) 0 ) , delim ); w [ * nwrds ] = ( ( void * ) 0 ); return w ; for (i = 0; arg[i]; i++) c = split ( arg [ i ] , "=" , & n ); char **split(char *str,char *delim,int *nwrds) int n = 128 ; char * * w = ( xmalloc ( sizeof ( char * ) * n ) ) ; w [ * nwrds = 0 ] = strtok ( str , delim ); while ( w [ * nwrds ] ) if ( * nwrds == n - 2 ) w = ( xrealloc ( w , sizeof ( char * ) * ( n += 256 ) ) ); w [ ++ * nwrds ] = strtok ( ( ( void * ) 0 ) , delim ); w [ * nwrds ] = ( ( void * ) 0 ); return w ; switch ( cmd ( c [ 0 ] ) ) int cmd(char *s) static struct { char * cmd ; char cmdnum ; } cmds [ ] = { { ( "no" ) , ( COL_NORMAL ) } , { ( "fi" ) , ( COL_FILE ) } , { ( "di" ) , ( COL_DIR ) } , { ( "ln" ) , ( COL_LINK ) } , { ( "pi" ) , ( COL_FIFO ) } , { ( "do" ) , ( COL_DOOR ) } , { ( "bd" ) , ( COL_BLK ) } , { ( "cd" ) , ( COL_CHR ) } , { ( "or" ) , ( COL_ORPHAN ) } , { ( "so" ) , ( COL_SOCK ) } , { ( "su" ) , ( COL_SETUID ) } , { ( "sg" ) , ( COL_SETGID ) } , { ( "tw" ) , ( COL_STICKY_OTHER_WRITABLE ) } , { ( "ow" ) , ( COL_OTHER_WRITABLE ) } , { ( "st" ) , ( COL_STICKY ) } , { ( "ex" ) , ( COL_EXEC ) } , { ( "mi" ) , ( COL_MISSING ) } , { ( "lc" ) , ( COL_LEFTCODE ) } , { ( "rc" ) , ( COL_RIGHTCODE ) } , { ( "ec" ) , ( COL_ENDCODE ) } , { ( ( ( void * ) 0 ) ) , ( 0 ) } } ; int i ; for (i = 0; cmds[i] . cmdnum; i++) if ( ! strcmp ( cmds [ i ] . cmd , s ) ) return cmds [ i ] . cmdnum ; if ( s [ 0 ] == '*' ) return DOT_EXTENSION ; return ERROR ; if ( c [ 1 ] ) file_flgs = strcpy ( ( xmalloc ( strlen ( c [ 1 ] ) + 1 ) ) , c [ 1 ] );
151261/color.c
SARD
0
cgiEnvironmentResultType cgiReadEnvironment(char *filename) FILE * in ; in = fopen ( filename , "rb" ); if ( ! cgiReadString ( in , & cgiServerSoftware ) ) if ( ! cgiReadString ( in , & cgiServerName ) ) if ( ! cgiReadString ( in , & cgiGatewayInterface ) ) if ( ! cgiReadString ( in , & cgiServerProtocol ) ) if ( ! cgiReadString ( in , & cgiServerPort ) ) if ( ! cgiReadString ( in , & cgiRequestMethod ) ) if ( ! cgiReadString ( in , & cgiPathInfo ) ) if ( ! cgiReadString ( in , & cgiPathTranslated ) ) if ( ! cgiReadString ( in , & cgiScriptName ) ) if ( ! cgiReadString ( in , & cgiQueryString ) ) if ( ! cgiReadString ( in , & cgiRemoteHost ) ) if ( ! cgiReadString ( in , & cgiRemoteAddr ) ) if ( ! cgiReadString ( in , & cgiAuthType ) ) if ( ! cgiReadString ( in , & cgiRemoteUser ) ) if ( ! cgiReadString ( in , & cgiRemoteIdent ) ) if ( ! cgiReadString ( in , & cgiContentType ) ) if ( ! cgiReadString ( in , & cgiAccept ) ) if ( ! cgiReadString ( in , & cgiUserAgent ) ) if ( ! cgiReadString ( in , & cgiReferrer ) ) if ( ! cgiReadString ( in , & cgiCookie ) ) if ( ! cgiReadInt ( in , & cgiContentLength ) ) while ( 1 ) int fileFlag ; e = ( cgiFormEntry * ) calloc ( 1 , sizeof ( cgiFormEntry ) ); if ( ! e ) memset ( e , 0 , sizeof ( cgiFormEntry ) ); if ( ! cgiReadString ( in , & e -> attr ) ) if ( ! cgiReadString ( in , & e -> value ) ) if ( ! cgiReadString ( in , & e -> fileName ) ) if ( ! cgiReadString ( in , & e -> contentType ) ) if ( ! cgiReadInt ( in , & e -> valueLength ) ) if ( ! cgiReadInt ( in , & fileFlag ) ) if ( fileFlag ) char buffer [ 1024 ] ; FILE * out ; char tfileName [ 1024 ] ; int got ; int len = e -> valueLength ; if ( getTempFileName ( tfileName ) != cgiParseSuccess ) out = fopen ( tfileName , "w+b" ); if ( ! out ) while ( len > 0 ) int tryr = len ; if ( tryr > ( ( int ) sizeof ( buffer ) ) ) tryr = sizeof ( buffer ); got = fread ( buffer , 1 , tryr , in ); if ( got <= 0 ) if ( ( ( int ) fwrite ( buffer , 1 , got , out ) ) != got ) len -= got; e -> tfileName = ( char * ) malloc ( ( int ) strlen ( tfileName ) + 1 ); if ( ! e -> tfileName ) e -> tfileName = ( char * ) malloc ( 1 ); if ( ! e -> tfileName ) e -> tfileName [ 0 ] = '\0'; e -> next = 0; static int cgiReadString(FILE *in, char **s) int len ; if ( ! cgiReadInt ( in , & len ) ) * s = ( char * ) malloc ( len + 1 ); if ( ! ( * s ) ) if ( ( ( int ) fread ( * s , 1 , len , in ) ) != len ) ( * s ) [ len ] = '\0';
149093/cgic.c
SARD
0
static void goodG2B() char * data ; data = new char [ 100 ]; memset ( data , 'A' , 50 - 1 ); data [ 50 - 1 ] = '\0'; dataArray [ 2 ] = data; goodG2BSink ( dataArray ); void goodG2BSink(char * dataArray[]) char * data = dataArray [ 2 ] ; strncpy ( dest , data , strlen ( data ) ); dest [ 50 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
69526/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncpy_66a.cpp
SARD
0
void CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memmove_52_bad() int data ; data = - 1; CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memmove_52b_badSink ( data ); void CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memmove_52b_badSink(int data) CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memmove_52c_badSink ( data ); void CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memmove_52c_badSink(int data) char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) memmove ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
87948/CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memmove_52c.c
SARD
20
struct stonesoup_queue *get_instance (char* file2) static struct stonesoup_queue * ssQ = NULL ; if ( ssQ == NULL ) ssQ = ( struct stonesoup_queue * ) calloc ( 1 , sizeof ( struct stonesoup_queue ) ); pthread_mutex_init ( & ( ssQ -> lock ) , NULL ); pthread_cond_init ( & ( ssQ -> is_empty ) , NULL ); pthread_cond_init ( & ( ssQ -> is_full ) , NULL ); ssQ -> size = 0; ssQ -> capacity = 30; ssQ -> head = NULL; ssQ -> tail = NULL; tracepoint ( stonesoup_trace , variable_address , "ssQ" , ssQ , "CROSSOVER-STATE" ); return ssQ ;
149947/dfa.c
SARD
0
static int file_puts(BIO *bp,const char *str) int n ; int ret ; n = ( strlen ( str ) ); ret = file_write ( bp , str , n ); static int file_write(BIO *b,const char *in,int inl) if ( b -> init && in != ( ( void * ) 0 ) ) if ( b -> flags & 0 ) ret = ( fwrite ( in , ( ( int ) inl ) , 1 , ( ( FILE * ) ( b -> ptr ) ) ) ); if ( ret ) return ret ;
150708/bss_file.c
SARD
0
static void goodB2G() struct _twoIntsStruct * data ; CWE401_Memory_Leak__struct_twoIntsStruct_malloc_34_unionType myUnion ; data = NULL; data = ( struct _twoIntsStruct * ) malloc ( 100 * sizeof ( struct _twoIntsStruct ) ); data [ 0 ] . intOne = 0; data [ 0 ] . intTwo = 0; myUnion . unionFirst = data; struct _twoIntsStruct * data = myUnion . unionSecond ; free ( data );
100497/CWE401_Memory_Leak__struct_twoIntsStruct_malloc_34.c
SARD
0
static void goodB2G() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket );
109208/CWE606_Unchecked_Loop_Condition__wchar_t_connect_socket_66a.c
SARD
0
void parse_loglevel(int argc,char **argv,const OptionDef *options) int idx = locate_option ( argc , argv , options , "loglevel" ) ; int locate_option(int argc,char **argv,const OptionDef *options,const char *optname) const OptionDef * po ; int i ; for (i = 1; i < argc; i++) const char * cur_opt = argv [ i ] ; if ( ( * ( cur_opt ++ ) ) != '-' ) po = find_option ( options , cur_opt ); static const OptionDef *find_option(const OptionDef *po,const char *name) const char * p = ( strchr ( name , ':' ) ) ; int len = ( p ? ( p - name ) : strlen ( name ) ) ; while ( po -> name != ( ( void * ) 0 ) ) if ( ! strncmp ( name , po -> name , len ) && strlen ( po -> name ) == len ) po ++; return po ; if ( ! po -> name && cur_opt [ 0 ] == 'n' && cur_opt [ 1 ] == 'o' ) po = find_option ( options , cur_opt + 2 ); static const OptionDef *find_option(const OptionDef *po,const char *name) const char * p = ( strchr ( name , ':' ) ) ; int len = ( p ? ( p - name ) : strlen ( name ) ) ; while ( po -> name != ( ( void * ) 0 ) ) if ( ! strncmp ( name , po -> name , len ) && strlen ( po -> name ) == len ) po ++; return po ; if ( ! po -> name && ! strcmp ( cur_opt , optname ) || po -> name && ! strcmp ( optname , po -> name ) ) return i ; if ( po -> flags & 0x0001 ) i ++; return 0 ; if ( ! idx ) idx = locate_option ( argc , argv , options , "v" ); int locate_option(int argc,char **argv,const OptionDef *options,const char *optname) const OptionDef * po ; int i ; const char * cur_opt = argv [ i ] ; if ( ( * ( cur_opt ++ ) ) != '-' ) po = find_option ( options , cur_opt ); if ( ! po -> name && cur_opt [ 0 ] == 'n' && cur_opt [ 1 ] == 'o' ) po = find_option ( options , cur_opt + 2 ); if ( ! po -> name && ! strcmp ( cur_opt , optname ) || po -> name && ! strcmp ( optname , po -> name ) ) return i ; if ( po -> flags & 0x0001 ) i ++; return 0 ; if ( idx && argv [ idx + 1 ] ) opt_loglevel ( ( ( void * ) 0 ) , "loglevel" , argv [ idx + 1 ] ); int opt_loglevel(void *optctx,const char *opt,const char *arg) const struct { const char * name ; int level ; } log_levels [ ] = { { "quiet" , ( - 8 ) } , { "panic" , ( 0 ) } , { "fatal" , ( 8 ) } , { "error" , ( 16 ) } , { "warning" , ( 24 ) } , { "info" , ( 32 ) } , { "verbose" , ( 40 ) } , { "debug" , ( 48 ) } } ; int i ; for (i = 0; i < sizeof(log_levels) / sizeof(log_levels[0]); i++) if ( ! strcmp ( log_levels [ i ] . name , arg ) )
151940/cmdutils.c
SARD
0
void CWE124_Buffer_Underwrite__malloc_char_memcpy_68b_badSink() char * data = CWE124_Buffer_Underwrite__malloc_char_memcpy_68_badData ; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memcpy ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
74374/CWE124_Buffer_Underwrite__malloc_char_memcpy_68b.c
SARD
3
void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_rand_63_bad() size_t data ; data = 0; data = rand ( ); CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_rand_63b_badSink ( & data ); void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_rand_63b_badSink(size_t * dataPtr) size_t data = * dataPtr ; wchar_t * myString ; if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); free ( myString );
117450/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_rand_63b.c
SARD
10
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; FILE * pFile ; pFile = fopen ( "passwords.txt" , "r" ); if ( pFile != NULL ) data [ 0 ] = '\0'; CWE256_Plaintext_Storage_of_Password__w32_char_63b_goodB2GSink ( & data ); void CWE256_Plaintext_Storage_of_Password__w32_char_63b_goodB2GSink(char * * dataPtr) char * data = * dataPtr ; char hashData [ 100 ] = HASH_INPUT ; HCRYPTPROV hCryptProv = 0 ; HCRYPTHASH hHash = 0 ; HCRYPTKEY hKey = 0 ; BYTE payload [ ( 100 - 1 ) * sizeof ( char ) ] ; DWORD payloadBytes ; payloadBytes = decodeHexChars ( payload , sizeof ( payload ) , data ); size_t decodeHexChars(unsigned char * bytes, size_t numBytes, const char * hex) size_t numWritten = 0 ; while ( numWritten < numBytes && isxdigit ( hex [ 2 * numWritten ] ) && isxdigit ( hex [ 2 * numWritten + 1 ] ) ) int byte ; bytes [ numWritten ] = ( unsigned char ) byte; return numWritten ; if ( ! CryptAcquireContext ( & hCryptProv , NULL , MS_ENH_RSA_AES_PROV , PROV_RSA_AES , 0 ) ) if ( ! CryptCreateHash ( hCryptProv , CALG_SHA_256 , 0 , 0 , & hHash ) ) if ( ! CryptHashData ( hHash , ( BYTE * ) hashData , strlen ( hashData ) , 0 ) ) if ( ! CryptDeriveKey ( hCryptProv , CALG_AES_256 , hHash , 0 , & hKey ) ) if ( ! CryptDecrypt ( hKey , 0 , 1 , 0 , payload , & payloadBytes ) ) memcpy ( data , payload , payloadBytes ); data [ payloadBytes / sizeof ( char ) ] = '\0'; while ( 0 ) if ( LogonUserA ( username , domain , data , LOGON32_LOGON_NETWORK , LOGON32_PROVIDER_DEFAULT , & pHandle ) != 0 )
93437/CWE256_Plaintext_Storage_of_Password__w32_char_63b.c
SARD
0
void CWE328_Reversible_One_Way_Hash__w32_SHA1_08_bad() if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; UCHAR savedHash [ SHA1_SUM_SIZE ] , calcHash [ SHA1_SUM_SIZE ] ; size_t i ; for (i = 0; i < SHA1_SUM_SIZE; i++) ULONG val ; savedHash [ i ] = ( UCHAR ) val; if ( memcmp ( savedHash , calcHash , SHA1_SUM_SIZE * sizeof ( UCHAR ) ) == 0 )
94555/CWE328_Reversible_One_Way_Hash__w32_SHA1_08.c
SARD
0
void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_connect_socket_07_bad() if ( staticFive == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); printWLine ( myString ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( myString );
117229/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_connect_socket_07.c
SARD
10
void bad() if ( 1 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) dataBytes = data * sizeof ( int ); intPointer = ( int * ) new char [ dataBytes ]; for (i = 0; i < (size_t)data; i++) intPointer [ i ] = 0; printIntLine ( intPointer [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); delete [ ] intPointer
110601/CWE680_Integer_Overflow_to_Buffer_Overflow__new_connect_socket_02.cpp
SARD
3