func
stringlengths
181
23.6k
path
stringlengths
12
123
source
stringclasses
2 values
label
int64
0
40
void CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_console_15_bad() wchar_t * data ; data = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ); size_t dataLen = wcslen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgetws ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) dataLen = wcslen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == L '\n' ) for ( * data != L '\0' data ++ ) if ( * data == SEARCH_CHAR ) free ( data );
112869/CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_console_15.c
SARD
1
static void goodG2B1() short data ; data = 0; if ( staticFalse ) data = 100 - 1; if ( data < 100 ) char * dataBuffer = ( char * ) malloc ( data ) ; memset ( dataBuffer , 'A' , data - 1 ); dataBuffer [ data - 1 ] = '\0'; free ( dataBuffer );
86482/CWE194_Unexpected_Sign_Extension__fgets_malloc_05.c
SARD
0
static void goodG2B() 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; CWE127_Buffer_Underread__wchar_t_alloca_cpy_63b_goodG2BSink ( & data ); void CWE127_Buffer_Underread__wchar_t_alloca_cpy_63b_goodG2BSink(wchar_t * * dataPtr) wchar_t * data = * dataPtr ; wchar_t dest [ 100 * 2 ] ; wmemset ( dest , L 'C' , 100 * 2 - 1 dest [ 100 * 2 - 1 ] = L '\0' wcscpy ( dest , data ); printWLine ( dest ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line )
78727/CWE127_Buffer_Underread__wchar_t_alloca_cpy_63b.c
SARD
0
void parse_dir_colors() char * * arg ; char * colors ; char * s ; 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 ;
151261/color.c
SARD
0
void CWE134_Uncontrolled_Format_String__char_listen_socket_fprintf_65_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; 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'; if ( replace ) * replace = '\0'; while ( 0 )
80287/CWE134_Uncontrolled_Format_String__char_listen_socket_fprintf_65a.c
SARD
0
static void goodB2G1() 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 ); switch ( 5 ) size_t i ; for (i=0; i < wcslen(data); i++) if ( data [ i ] == SEARCH_CHAR )
112917/CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_environment_15.c
SARD
0
void CWE114_Process_Control__w32_char_connect_socket_01_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'; while ( 0 ) HMODULE hModule ; hModule = LoadLibraryA ( data ); if ( hModule != NULL ) FreeLibrary ( hModule );
61940/CWE114_Process_Control__w32_char_connect_socket_01.c
SARD
14
static brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device struct cfg80211_pmksa *pmksa) struct brcmf_cfg80211_info * cfg = wiphy_to_cfg ( wiphy ) ; struct brcmf_if * ifp = netdev_priv ( ndev ) ; struct brcmf_pmksa * pmk = & cfg -> pmk_list . pmk [ 0 ] ; u32 npmk , i ; if ( ! check_vif_up ( ifp -> vif ) ) static bool check_vif_up(struct brcmf_cfg80211_vif *vif) if ( ! test_bit ( BRCMF_VIF_STATUS_READY , & vif -> sme_state ) ) return false ; return true ; npmk = le32_to_cpu ( cfg -> pmk_list . npmk ); for (i = 0; i < npmk; i++) if ( ! memcmp ( pmksa -> bssid , pmk [ i ] . bssid , ETH_ALEN ) ) if ( i < BRCMF_MAXPMKID ) memcpy ( pmk [ i ] . bssid , pmksa -> bssid , ETH_ALEN ); memcpy ( pmk [ i ] . pmkid , pmksa -> pmkid , WLAN_PMKID_LEN );
CVE-2016-8658/linux_kernel_4.7.4_CVE_2016_8658_drivers_net_wireless_broadcom_brcm80211_brcmfmac_cfg80211.c
NVD
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; free ( stonesoup_tainted_buff );
152118/bufmgr.c
SARD
0
void bad() int data ; data = - 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'; data = atoi ( inputBuffer ); while ( 0 ) CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_82_base * baseObject = new CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_82_bad baseObject -> action ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_82_bad::action(int data) int * buffer = ( int * ) malloc ( 10 * sizeof ( int ) ) ; buffer [ i ] = 0; buffer [ data ] = 1; for(i = 0; i < 10; i++) printIntLine ( buffer [ i ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( buffer );
70685/CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_82_bad.cpp
SARD
3
static void good2() switch ( 6 ) char * * pointer = ( char * * ) malloc ( sizeof ( char * ) ) ; * pointer = data; char * data = * pointer ; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( pointer );
112024/CWE758_Undefined_Behavior__char_pointer_malloc_use_15.c
SARD
0
void svn_stringbuf_appendbyte(svn_stringbuf_t *str,char byte) apr_size_t old_len = str -> len ; if ( str -> blocksize > old_len + 1 ) str -> len = old_len + 1; svn_stringbuf_appendbytes ( str , ( & b ) , 1 ); void svn_stringbuf_appendbytes(svn_stringbuf_t *str,const char *bytes,apr_size_t count) apr_size_t total_len ; total_len = str -> len + count; svn_stringbuf_ensure ( str , total_len ); void svn_stringbuf_ensure(svn_stringbuf_t *str,apr_size_t minimum_size) void * mem = ( void * ) 0 ; if ( mem && mem != ( str -> data ) ) if ( str -> data ) memcpy ( mem , ( str -> data ) , str -> len + 1 ); str -> data = mem;
152932/string.c
SARD
0
void dfacomp(const char *s,size_t len,struct dfa *d,int searchflag) dfamust ( d ); static void dfamust(struct dfa *d) must * musts ; must * mp ; size_t ri ; size_t i ; token t ; static must must0 ; musts = ( ( sizeof ( ( * musts ) ) == 1 ? xmalloc ( d -> tindex + 1 ) : xnmalloc ( d -> tindex + 1 , sizeof ( ( * musts ) ) ) ) ); while ( 0 ) mp = musts; for (i = 0; i <= d -> tindex; ++i) mp [ i ] = must0; for (i = 0; i <= d -> tindex; ++i) mp [ i ] . in = ( xmalloc ( sizeof ( ( * mp [ i ] . in ) ) ) ); mp [ i ] . left = ( xmalloc ( 2 ) ); mp [ i ] . right = ( xmalloc ( 2 ) ); mp [ i ] . is = ( xmalloc ( 2 ) ); mp [ i ] . left [ 0 ] = mp [ i ] . right [ 0 ] = mp [ i ] . is [ 0 ] = '\0'; mp [ i ] . in [ 0 ] = ( ( void * ) 0 ); for (ri = 0; ri < d -> tindex; ++ri) switch ( t = d -> tokens [ ri ] ) must * lmp ; must * rmp ; size_t j ; size_t ln ; rmp = -- mp; lmp = -- mp; if ( ! ( strcmp ( ( lmp -> is ) , ( rmp -> is ) ) == 0 ) ) lmp -> is [ 0 ] = '\0'; i = 0; lmp -> left [ i ] = '\0'; ln = strlen ( ( lmp -> right ) ); for (j = 0; j < i; ++j) lmp -> right [ j ] = lmp -> right [ ln - i + j ]; lmp -> right [ j ] = '\0'; mp -> is [ 0 ] = '\0'; must * lmp ; must * rmp ; rmp = -- mp; lmp = -- mp; lmp -> in = addlists ( lmp -> in , rmp -> in ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> right [ 0 ] != '\0' && rmp -> left [ 0 ] != '\0' ) char * tp ; tp = icpyalloc ( ( lmp -> right ) ); static char *icpyalloc(const char *string) return icatalloc ( ( ( void * ) 0 ) , string ) ; tp = icatalloc ( tp , ( rmp -> left ) ); lmp -> in = enlist ( lmp -> in , tp , strlen ( tp ) ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' ) lmp -> left = icatalloc ( lmp -> left , ( rmp -> left ) ); if ( lmp -> left == ( ( void * ) 0 ) ) if ( rmp -> is [ 0 ] == '\0' ) lmp -> right [ 0 ] = '\0'; lmp -> right = icatalloc ( lmp -> right , ( rmp -> right ) ); if ( lmp -> right == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' && rmp -> is [ 0 ] != '\0' ) lmp -> is = icatalloc ( lmp -> is , ( rmp -> is ) ); if ( lmp -> is == ( ( void * ) 0 ) ) lmp -> is [ 0 ] = '\0'; if ( t < END ) if ( t == '\0' ) if ( t >= CSET || ! 1 || t == ANYCHAR || t == MBCSET ) mp -> is [ 0 ] = mp -> left [ 0 ] = mp -> right [ 0 ] = t; mp -> is [ 1 ] = mp -> left [ 1 ] = mp -> right [ 1 ] = '\0'; mp -> in = enlist ( mp -> in , mp -> is , ( ( size_t ) 1 ) ); if ( mp -> in == ( ( void * ) 0 ) )
153249/dfa.c
SARD
0
void bad() char * data ; char * & dataRef = data ; data = NULL; char * dataBuffer = new char [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; char * data = dataRef ; char dest [ 100 * 2 ] ; memset ( dest , 'C' , 100 * 2 - 1 ); dest [ 100 * 2 - 1 ] = '\0'; strcpy ( dest , data ); printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
78240/CWE127_Buffer_Underread__new_char_cpy_33.cpp
SARD
3
void stonesoup_handle_taint(char *noneconomically_carthaginian) int orly_arri = 7 ; int ripping_antiphylloxeric ; union intersexes_crimpling hexosaminic_duckblind [ 10 ] = { 0 } ; union intersexes_crimpling flammable_subsultive ; if ( noneconomically_carthaginian != 0 ) flammable_subsultive . somatist_outlength = noneconomically_carthaginian; ripping_antiphylloxeric = 5; hoccleve_pneumonography = & ripping_antiphylloxeric; hexosaminic_duckblind [ * hoccleve_pneumonography ] = flammable_subsultive; vegetating_confetti = hexosaminic_duckblind [ * hoccleve_pneumonography ]; silkness_incorporate ( orly_arri , vegetating_confetti ); void silkness_incorporate(int nontheistically_monogamian,union intersexes_crimpling collery_lawmen) nontheistically_monogamian --; if ( nontheistically_monogamian > 0 ) silkness_incorporate ( nontheistically_monogamian , collery_lawmen ); void silkness_incorporate(int nontheistically_monogamian,union intersexes_crimpling collery_lawmen) nontheistically_monogamian --; if ( nontheistically_monogamian > 0 ) silkness_incorporate ( nontheistically_monogamian , collery_lawmen ); void silkness_incorporate(int nontheistically_monogamian,union intersexes_crimpling collery_lawmen) const int stonesoup_MAXLEN = 16 ; char stonesoup_dest [ stonesoup_MAXLEN ] ; nontheistically_monogamian --; if ( nontheistically_monogamian > 0 ) memset ( stonesoup_dest , 'x' , stonesoup_MAXLEN ); stonesoup_dest [ stonesoup_MAXLEN - 1 ] = '\0'; stonesoup_size_var = stonesoup_returnChunkSize ( stonesoup_dest , goldenknop_pyridinium ); tracepoint ( stonesoup_trace , variable_signed_integral , "stonesoup_size_var" , stonesoup_size_var , & stonesoup_size_var , "TRIGGER-STATE" ); if ( stonesoup_size_var > 0 ) memcpy ( stonesoup_dest , goldenknop_pyridinium , stonesoup_size_var ); stonesoup_printf ( "%s\n" , stonesoup_dest );
151099/dynahash.c
SARD
20
static void goodB2G1() twoIntsStruct * data ; if ( 0 ) data = ( twoIntsStruct * ) malloc ( sizeof ( twoIntsStruct ) ); data -> intOne = 5; data -> intTwo = 6; printIntLine ( data -> intOne ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); printIntLine ( data -> intTwo ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
104044/CWE457_Use_of_Uninitialized_Variable__struct_pointer_02.c
SARD
0
static void goodB2G() wchar_t * password ; CWE319_Cleartext_Tx_Sensitive_Info__w32_wchar_t_connect_socket_34_unionType myUnion ; 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 ) password [ passwordLen + recvResult / sizeof ( wchar_t ) ] = L '\0' while ( 0 ) myUnion . unionFirst = password; wchar_t * password = myUnion . unionSecond ; HCRYPTPROV hCryptProv = 0 ; HCRYPTHASH hHash = 0 ; HCRYPTKEY hKey = 0 ; char hashData [ 100 ] = HASH_INPUT ; BYTE payload [ ( 100 - 1 ) * sizeof ( wchar_t ) ] ; DWORD payloadBytes ; payloadBytes = decodeHexWChars ( payload , sizeof ( payload ) , password ); size_t decodeHexWChars(unsigned char * bytes, size_t numBytes, const wchar_t * hex) size_t numWritten = 0 ; while ( numWritten < numBytes && iswxdigit ( hex [ 2 * numWritten ] ) && iswxdigit ( 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 ( password , payload , payloadBytes ); while ( 0 ) if ( LogonUserW ( username , domain , password , LOGON32_LOGON_NETWORK , LOGON32_PROVIDER_DEFAULT , & pHandle ) != 0 )
94217/CWE319_Cleartext_Tx_Sensitive_Info__w32_wchar_t_connect_socket_34.c
SARD
0
void CWE124_Buffer_Underwrite__CWE839_fgets_14_bad() if ( globalFive == 5 ) char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = atoi ( inputBuffer ); if ( data < 10 ) buffer [ data ] = 1; printIntLine ( buffer [ i ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
73611/CWE124_Buffer_Underwrite__CWE839_fgets_14.c
SARD
3
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 ] ) if ( strcasecmp ( "target" , c [ 1 ] ) == 0 ) link_flgs = strcpy ( ( xmalloc ( strlen ( c [ 1 ] ) + 1 ) ) , c [ 1 ] );
152819/color.c
SARD
0
void bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; CWE78_OS_Command_Injection__char_listen_socket_execlp_84_bad * badObject = new CWE78_OS_Command_Injection__char_listen_socket_execlp_84_bad ( data ) ; CWE78_OS_Command_Injection__char_listen_socket_execlp_84_bad::CWE78_OS_Command_Injection__char_listen_socket_execlp_84_bad(char * dataCopy) data = dataCopy; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; 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'; if ( replace ) * replace = '\0'; while ( 0 )
119958/CWE78_OS_Command_Injection__char_listen_socket_execlp_84_bad.cpp
SARD
0
void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_connect_socket_31_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 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) size_t dataCopy = data ; size_t data = dataCopy ; 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 );
117243/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_connect_socket_31.c
SARD
10
void dfacomp(const char *s,size_t len,struct dfa *d,int searchflag) dfamust ( d ); static void dfamust(struct dfa *d) must * musts ; must * mp ; size_t ri ; size_t i ; token t ; static must must0 ; musts = ( ( sizeof ( ( * musts ) ) == 1 ? xmalloc ( d -> tindex + 1 ) : xnmalloc ( d -> tindex + 1 , sizeof ( ( * musts ) ) ) ) ); while ( 0 ) mp = musts; for (i = 0; i <= d -> tindex; ++i) mp [ i ] = must0; for (i = 0; i <= d -> tindex; ++i) mp [ i ] . in = ( xmalloc ( sizeof ( ( * mp [ i ] . in ) ) ) ); mp [ i ] . left = ( xmalloc ( 2 ) ); mp [ i ] . right = ( xmalloc ( 2 ) ); mp [ i ] . is = ( xmalloc ( 2 ) ); mp [ i ] . left [ 0 ] = mp [ i ] . right [ 0 ] = mp [ i ] . is [ 0 ] = '\0'; mp [ i ] . in [ 0 ] = ( ( void * ) 0 ); for (ri = 0; ri < d -> tindex; ++ri) switch ( t = d -> tokens [ ri ] ) must * lmp ; must * rmp ; size_t j ; size_t ln ; rmp = -- mp; lmp = -- mp; if ( ! ( strcmp ( ( lmp -> is ) , ( rmp -> is ) ) == 0 ) ) lmp -> is [ 0 ] = '\0'; i = 0; lmp -> left [ i ] = '\0'; ln = strlen ( ( lmp -> right ) ); for (j = 0; j < i; ++j) lmp -> right [ j ] = lmp -> right [ ln - i + j ]; lmp -> right [ j ] = '\0'; mp -> is [ 0 ] = '\0'; must * lmp ; must * rmp ; rmp = -- mp; lmp = -- mp; lmp -> in = addlists ( lmp -> in , rmp -> in ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> right [ 0 ] != '\0' && rmp -> left [ 0 ] != '\0' ) char * tp ; tp = icpyalloc ( ( lmp -> right ) ); static char *icpyalloc(const char *string) return icatalloc ( ( ( void * ) 0 ) , string ) ; tp = icatalloc ( tp , ( rmp -> left ) ); lmp -> in = enlist ( lmp -> in , tp , strlen ( tp ) ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' ) lmp -> left = icatalloc ( lmp -> left , ( rmp -> left ) ); if ( lmp -> left == ( ( void * ) 0 ) ) if ( rmp -> is [ 0 ] == '\0' ) lmp -> right [ 0 ] = '\0'; lmp -> right = icatalloc ( lmp -> right , ( rmp -> right ) ); if ( lmp -> right == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' && rmp -> is [ 0 ] != '\0' ) lmp -> is = icatalloc ( lmp -> is , ( rmp -> is ) ); if ( lmp -> is == ( ( void * ) 0 ) ) lmp -> is [ 0 ] = '\0'; if ( t < END ) if ( t == '\0' ) if ( t >= CSET || ! 1 || t == ANYCHAR || t == MBCSET ) mp -> is [ 0 ] = mp -> left [ 0 ] = mp -> right [ 0 ] = t; mp -> is [ 1 ] = mp -> left [ 1 ] = mp -> right [ 1 ] = '\0'; mp -> in = enlist ( mp -> in , mp -> is , ( ( size_t ) 1 ) ); if ( mp -> in == ( ( void * ) 0 ) )
150883/dfa.c
SARD
0
static void goodG2B() int h ; wchar_t * data ; for(h = 0; h < 1; h++) data = ( wchar_t * ) malloc ( ( 10 + 1 ) * sizeof ( wchar_t ) ); memcpy ( data , source , ( wcslen ( source ) + 1 ) * sizeof ( wchar_t ) ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( data );
71088/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_memcpy_17.c
SARD
0
static void goodG2B() wchar_t * data ; data = ( wchar_t * ) malloc ( ( 10 + 1 ) * sizeof ( wchar_t ) ); baseObject -> action ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_memcpy_82_goodG2B::action(wchar_t * data) memcpy ( data , source , ( wcslen ( source ) + 1 ) * sizeof ( wchar_t ) ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( data );
71117/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_memcpy_82a.cpp
SARD
0
void CWE121_Stack_Based_Buffer_Overflow__CWE806_char_declare_memmove_41_bad() char * data ; char dataBuffer [ 100 ] ; data = dataBuffer; memset ( data , 'A' , 100 - 1 ); data [ 100 - 1 ] = '\0'; CWE121_Stack_Based_Buffer_Overflow__CWE806_char_declare_memmove_41_badSink ( data ); void CWE121_Stack_Based_Buffer_Overflow__CWE806_char_declare_memmove_41_badSink(char * data) char dest [ 50 ] = "" ; memmove ( dest , data , strlen ( data ) * sizeof ( char ) ); dest [ 50 - 1 ] = '\0';
65920/CWE121_Stack_Based_Buffer_Overflow__CWE806_char_declare_memmove_41.c
SARD
3
static void goodG2B2() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); memset ( data , 'A' , 50 - 1 ); data [ 50 - 1 ] = '\0'; memcpy ( dest , data , strlen ( data ) * sizeof ( char ) ); dest [ 50 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
72279/CWE122_Heap_Based_Buffer_Overflow__c_CWE806_char_memcpy_08.c
SARD
0
static void goodG2B() long * dataBuffer = ( long * ) malloc ( 100 * sizeof ( long ) ) ; if ( dataBuffer == NULL ) dataBuffer [ i ] = 5L; data = dataBuffer; CWE590_Free_Memory_Not_on_Heap__free_long_declare_54b_goodG2BSink ( data ); void CWE590_Free_Memory_Not_on_Heap__free_long_declare_54b_goodG2BSink(long * data) CWE590_Free_Memory_Not_on_Heap__free_long_declare_54c_goodG2BSink ( data ); void CWE590_Free_Memory_Not_on_Heap__free_long_declare_54c_goodG2BSink(long * data) CWE590_Free_Memory_Not_on_Heap__free_long_declare_54d_goodG2BSink ( data ); void CWE590_Free_Memory_Not_on_Heap__free_long_declare_54d_goodG2BSink(long * data) CWE590_Free_Memory_Not_on_Heap__free_long_declare_54e_goodG2BSink ( data ); void CWE590_Free_Memory_Not_on_Heap__free_long_declare_54e_goodG2BSink(long * data) printLongLine ( data [ 0 ] ); void printLongLine (long longNumber) printf ( "%ld\n" , longNumber ); free ( data );
108524/CWE590_Free_Memory_Not_on_Heap__free_long_declare_54a.c
SARD
0
static void goodG2B1() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; if ( staticReturnsFalse ( ) ) static int staticReturnsFalse() return 0 ; strcat ( data , "*.*" ); pipe = POPEN ( data , "wb" ); if ( pipe != NULL ) PCLOSE ( pipe );
119486/CWE78_OS_Command_Injection__char_file_popen_08.c
SARD
0
static void goodG2B() wchar_t * data ; data = NULL; data = new wchar_t [ 100 ]; data [ 0 ] = L '\0' wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' memmove ( data , source , 100 * sizeof ( wchar_t ) ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) delete [ ] data
69121/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_wchar_t_memmove_18.cpp
SARD
0
char *dfaexec(struct dfa *d,const char *begin,char *end,int allow_nl,size_t *count,int *backref) state_num s ; state_num s1 ; const unsigned char * p ; state_num * * trans ; state_num * t ; unsigned char eol = eolbyte ; s = s1 = 0; p = ( ( const unsigned char * ) begin ); trans = d -> trans; * end = eol; if ( d -> mb_cur_max > 1 ) while ( ( t = trans [ s ] ) != ( ( void * ) 0 ) ) if ( p > buf_end ) s1 = s; if ( s == 0 ) if ( ( ( char * ) p ) >= end ) if ( d -> states [ s ] . mbps . nelem == 0 ) s = t [ * ( p ++ ) ]; if ( backref ) s = transit_state ( d , s , & p ); trans = d -> trans; while ( ( t = trans [ s ] ) != ( ( void * ) 0 ) ) s1 = t [ * ( p ++ ) ]; if ( ( t = trans [ s1 ] ) == ( ( void * ) 0 ) ) state_num tmp = s ; s = s1; s1 = tmp; s = t [ * ( p ++ ) ]; if ( s >= 0 && ( ( char * ) p ) <= end && d -> fails [ s ] ) if ( d -> success [ s ] & sbit [ * p ] ) s1 = s; if ( d -> mb_cur_max > 1 ) s = transit_state ( d , s , & p ); trans = d -> trans; s = d -> fails [ s ] [ * ( p ++ ) ]; if ( ( ( char * ) p ) > end ) if ( s >= 0 ) trans = d -> trans; if ( p [ - 1 ] == eol && allow_nl ) s = d -> newlines [ s1 ]; s = 0; static state_num transit_state(struct dfa *d,state_num s,const unsigned char **pp) size_t nelem = d -> states [ s ] . mbps . nelem ; if ( nelem > 0 ) match_lens = 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 )
152165/dfa.c
SARD
0
void CWE194_Unexpected_Sign_Extension__listen_socket_memmove_14_bad() char source [ 100 ] ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memmove ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
86971/CWE194_Unexpected_Sign_Extension__listen_socket_memmove_14.c
SARD
20
svn_error_t /* UTF-8! svn_string_t /* UTF-8! const char **tmpfile_left,const char /* UTF-8! const char /* UTF-8! const svn_string_t *contents,const char *filename,apr_hash_t *config,svn_boolean_t as_text,const char *encoding,apr_pool_t *pool) svn_error_t * svn_err__temp = find_editor_binary ( & editor , editor_cmd , config ) ; if ( svn_err__temp ) while ( 0 ) static svn_error_t *find_editor_binary(const char **editor,const char *editor_cmd,apr_hash_t *config) const char * e ; e = editor_cmd; if ( ! e ) e = ( getenv ( "SVN_EDITOR" ) ); if ( ! e ) svn_config_get ( cfg , & e , "helpers" , "editor-cmd" , ( ( void * ) 0 ) ); if ( ! e ) if ( ! e ) if ( ! e ) if ( e ) for (c = e; *c; c++) if ( ! ( 0 != ( svn_ctype_table [ ( unsigned char ) ( * c ) ] & 0x0002 ) ) ) if ( ! ( * c ) ) * editor = e;
151916/cmdline.c
SARD
0
CVE_2013_1726_PATCHED_mar_read_product_info_block(MarFile struct ProductInformationBlock *infoBlock) int i , hasAdditionalBlocks , offsetAdditionalBlocks , numAdditionalBlocks , additionalBlockSize , additionalBlockID ; char buf [ 97 ] = { '\0' } ; for (i = 0; i < numAdditionalBlocks; ++i) if ( fread ( & additionalBlockSize , sizeof ( additionalBlockSize ) , 1 , mar -> fp ) != 1 ) additionalBlockSize = ntohl ( additionalBlockSize ) - sizeof ( additionalBlockSize ) - sizeof ( additionalBlockID ); if ( fread ( & additionalBlockID , sizeof ( additionalBlockID ) , 1 , mar -> fp ) != 1 ) additionalBlockID = ntohl ( additionalBlockID ); if ( PRODUCT_INFO_BLOCK_ID == additionalBlockID ) const char * location ; int len ; if ( additionalBlockSize > 96 ) if ( fread ( buf , additionalBlockSize , 1 , mar -> fp ) != 1 ) location = buf; len = strlen ( location ); location += len + 1; if ( len >= 64 ) len = strlen ( location ); infoBlock -> productVersion = location; location += len + 1; if ( len >= 32 ) infoBlock -> MARChannelID = NULL; infoBlock -> productVersion = NULL; infoBlock -> MARChannelID = strdup ( infoBlock -> MARChannelID ); infoBlock -> productVersion = strdup ( infoBlock -> productVersion ); if ( fseek ( mar -> fp , additionalBlockSize , SEEK_CUR ) )
CVE-2013-1726/CVE_2013_1726_PATCHED_mar_read_product_info_block.c
NVD
0
static void goodG2B() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; myUnion . unionFirst = data; char * data = myUnion . unionSecond ; memcpy ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
71287/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_memcpy_34.c
SARD
0
static gint64 tile_swap_find_offset(SwapFile *swap_file,gint64 bytes) union carrara_lecanto unusual_republish ; char * meninting_geistlich ; if ( __sync_bool_compare_and_swap ( & ghoulish_desmid , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( meninting_geistlich != 0 ) unusual_republish . columbiaville_unmuzzled = meninting_geistlich; merchandised_arcadias = stalactited_bier ( unusual_republish ); union carrara_lecanto stalactited_bier(union carrara_lecanto hallstadt_empididae) return hallstadt_empididae ; ofs_verbalization = ( ( char * ) merchandised_arcadias . columbiaville_unmuzzled ); if ( strlen ( ofs_verbalization ) > 0 && ofs_verbalization [ 0 ] == '-' ) stonesoup_other_buff = getenv ( "SS_BUFF" ); tracepoint ( stonesoup_trace , variable_buffer , "stonesoup_other_buff" , stonesoup_other_buff , "CROSSOVER-STATE" ); if ( stonesoup_other_buff != 0 ) strncpy ( stonesoup_buff , stonesoup_other_buff , ( sizeof ( stonesoup_buff ) - 1 ) / ( sizeof ( char ) ) ); stonesoup_size = ( ( int ) ( strlen ( stonesoup_buff ) ) ); while ( stonesoup_num < stonesoup_size )
151065/tile-swap.c
SARD
20
void bad() wchar_t * data ; data = NULL; if ( GLOBAL_CONST_FIVE == 5 ) data = new wchar_t [ 50 ]; data [ 0 ] = L '\0' wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcsncat ( data , source , 100 ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) delete [ ] data
69164/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_wchar_t_ncat_13.cpp
SARD
3
void CWE195_Signed_to_Unsigned_Conversion_Error__negative_memcpy_81_bad::action(int data) const 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 );
88298/CWE195_Signed_to_Unsigned_Conversion_Error__negative_memcpy_81_bad.cpp
SARD
20
static void goodG2B1() twoIntsStruct * data ; twoIntsStruct dataGoodBuffer [ 100 ] ; if ( staticReturnsFalse ( ) ) static int staticReturnsFalse() return 0 ; data = dataGoodBuffer; twoIntsStruct source [ 100 ] ; size_t i ; for (i = 0; i < 100; i++) source [ i ] . intOne = 0; source [ i ] . intOne = 0; memmove ( data , source , 100 * sizeof ( twoIntsStruct ) ); printStructLine ( & data [ 0 ] ); void printStructLine (const twoIntsStruct * structTwoIntsStruct)
64999/CWE121_Stack_Based_Buffer_Overflow__CWE805_struct_declare_memmove_08.c
SARD
0
static svn_error_t *get_xlate_handle_node_internal(xlate_handle_node_t **ret,const char *topage,const char *frompage,const char *userdata_key,apr_pool_t *pool) int litherly_leptochrous = 7 ; int unequipped_spectating ; ray_inexplicitness overpending_predecess [ 10 ] = { 0 } ; char * dimethylamine_questor ; if ( __sync_bool_compare_and_swap ( & alsinaceous_heterophaga , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( dimethylamine_questor != 0 ) subsolid_unfished = dimethylamine_questor; unequipped_spectating = 5; bazaine_cicatrisate = & unequipped_spectating; overpending_predecess [ * bazaine_cicatrisate ] = subsolid_unfished; bend_vulgarisms = overpending_predecess [ * bazaine_cicatrisate ]; monmouthite_quadruplicating ( litherly_leptochrous , bend_vulgarisms ); void monmouthite_quadruplicating(int spanless_overright,ray_inexplicitness heavyheaded_unproscriptive) spanless_overright --; if ( spanless_overright > 0 ) dbport = getenv ( "DBPGPORT" ); tracepoint ( stonesoup_trace , variable_buffer , "dbport" , dbport , "INITIAL-STATE" ); if ( dbhost != 0 && dbport != 0 && dbuser != 0 && dbpassword != 0 && dbdatabase != 0 ) snprintf ( dbconn_str , 150 , "dbname=%s host=%s user=%s password=%s port=%s" , dbdatabase , dbhost , dbuser , dbpassword , dbport ); conn = PQconnectdb ( dbconn_str ); if ( PQstatus ( conn ) != 0 ) stonesoup_printf ( "%s: %s\n" , "Connection to database failed" , PQerrorMessage ( conn ) ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); vfprintf ( stonesoup_printf_context , format , argptr ); PQfinish ( conn ); res = PQexec ( conn , query ); if ( PQresultStatus ( res ) != 2 ) stonesoup_printf ( "%s: %s\n" , "SELECT failed" , PQerrorMessage ( conn ) ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); vfprintf ( stonesoup_printf_context , format , argptr ); PQclear ( res ); PQfinish ( conn ); stonesoup_nFields = PQnfields ( res ); for (stonesoup_i = 0; stonesoup_i < stonesoup_nFields; stonesoup_i++) stonesoup_printf ( "%-15s" , PQfname ( res , stonesoup_i ) ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); vfprintf ( stonesoup_printf_context , format , argptr ); for (stonesoup_i = 0; stonesoup_i < PQntuples(res); stonesoup_i++) for (stonesoup_j = 0; stonesoup_j < stonesoup_nFields; stonesoup_j++) stonesoup_printf ( "%-15s" , PQgetvalue ( res , stonesoup_i , stonesoup_j ) ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); vfprintf ( stonesoup_printf_context , format , argptr ); PQclear ( res ); PQfinish ( conn );
152347/utf.c
SARD
15
static void goodG2B() char source [ 100 ] ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memmove ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
87556/CWE195_Signed_to_Unsigned_Conversion_Error__connect_socket_memmove_33.cpp
SARD
0
static void goodG2B() twoIntsStruct * data ; data = ( twoIntsStruct * ) malloc ( 100 * sizeof ( twoIntsStruct ) ); myStruct . structFirst = data; CWE122_Heap_Based_Buffer_Overflow__c_CWE805_struct_loop_67b_goodG2BSink ( myStruct ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_struct_loop_67b_goodG2BSink(CWE122_Heap_Based_Buffer_Overflow__c_CWE805_struct_loop_67_structType myStruct) twoIntsStruct * data = myStruct . structFirst ; data [ i ] = source [ i ]; printStructLine ( & data [ 0 ] ); void printStructLine (const twoIntsStruct * structTwoIntsStruct) printf ( "%d -- %d\n" , structTwoIntsStruct -> intOne , structTwoIntsStruct -> intTwo ); free ( data );
71831/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_struct_loop_67a.c
SARD
0
void CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_memmove_17_bad() int i ; for(i = 0; i < 1; i++) 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 = atoi ( inputBuffer ); while ( 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 );
88126/CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_memmove_17.c
SARD
20
void CWE134_Uncontrolled_Format_String__wchar_t_environment_fprintf_41_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; size_t dataLen = wcslen ( data ) ; wchar_t * environment = GETENV ( ENV_VARIABLE ) ; if ( environment != NULL ) wcsncat ( data + dataLen , environment , 100 - dataLen - 1 ); badSink ( data ); static void badSink(wchar_t * data) fwprintf ( stdout , data );
81138/CWE134_Uncontrolled_Format_String__wchar_t_environment_fprintf_41.c
SARD
15
void bad() vector < int * > dataVector ; badSink ( dataVector ); void badSink(vector<int *> dataVector) int * data = dataVector [ 2 ] ; int source [ 100 ] = { 0 } ; memmove ( data , source , 100 * sizeof ( int ) ); printIntLine ( data [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); delete [ ] data
69001/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_int_memmove_72b.cpp
SARD
3
static void goodB2G1() if ( globalFive == 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 ( count > 0 && count <= 20 ) for (i = 0; i < (size_t)count; i++)
98926/CWE400_Resource_Exhaustion__listen_socket_for_loop_14.c
SARD
0
static guint conversation_hash_no_addr2_or_port2(gconstpointer v) char stonesoup_buffer [ 80 ] ; char * enlargeableness_alburnum ; if ( __sync_bool_compare_and_swap ( & bradykinesia_ballo , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) enlargeableness_alburnum = getenv ( "FLAVIUS_SPUNKING" ); if ( enlargeableness_alburnum != 0 ) palindrome_ponderableness = ( ( int ) ( strlen ( enlargeableness_alburnum ) ) ); quinotannic_beavertown = ( ( char * ) ( malloc ( palindrome_ponderableness + 1 ) ) ); memset ( quinotannic_beavertown , 0 , palindrome_ponderableness + 1 ); memcpy ( quinotannic_beavertown , enlargeableness_alburnum , palindrome_ponderableness ); colletes_sculduddery = & quinotannic_beavertown; trembles_sardinia = colletes_sculduddery + 5; unforecast_endsweep = ( ( char * ) ( * ( trembles_sardinia - 5 ) ) ); stonesoup_pFile = fopen ( unforecast_endsweep , "r" ); stonesoup_buffer [ 0 ] = 0; fgets ( stonesoup_buffer , 79 , stonesoup_pFile ); stonesoup_printf ( stonesoup_buffer ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); vfprintf ( stonesoup_printf_context , format , argptr );
149432/conversation.c
SARD
2
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_63b_goodB2GSink ( & count ); void CWE400_Resource_Exhaustion__connect_socket_for_loop_63b_goodB2GSink(int * countPtr) int count = * countPtr ; if ( count > 0 && count <= 20 ) for (i = 0; i < (size_t)count; i++)
98516/CWE400_Resource_Exhaustion__connect_socket_for_loop_63a.c
SARD
0
void CWE78_OS_Command_Injection__char_connect_socket_w32_spawnlp_01_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; 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 )
118231/CWE78_OS_Command_Injection__char_connect_socket_w32_spawnlp_01.c
SARD
0
static void good1() if ( staticFalse ) char password [ 100 ] = "" ; if ( fgets ( password , 100 , stdin ) == NULL ) password [ 0 ] = '\0'; passwordLen = strlen ( password ); if ( passwordLen > 0 ) password [ passwordLen - 1 ] = '\0'; passwordLen = strlen ( password ); SecureZeroMemory ( password , passwordLen * sizeof ( char ) );
89530/CWE226_Sensitive_Information_Uncleared_Before_Release__w32_char_declare_05.c
SARD
0
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; if ( STATIC_CONST_TRUE ) size_t dataLen = strlen ( data ) ; 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'; pFile = FOPEN ( data , "wb+" ); if ( pFile != NULL ) fclose ( pFile );
96501/CWE36_Absolute_Path_Traversal__char_listen_socket_fopen_04.cpp
SARD
4
static void pgstat_read_current_status() volatile PgBackendStatus * beentry ; PgBackendStatus * localtable ; PgBackendStatus * localentry ; char * localappname ; char * localactivity ; int i ; if ( localBackendStatusTable ) localtable = ( ( PgBackendStatus * ) ( MemoryContextAlloc ( pgStatLocalContext , sizeof ( PgBackendStatus ) * MaxBackends ) ) ); localappname = ( ( char * ) ( MemoryContextAlloc ( pgStatLocalContext , ( 64 * MaxBackends ) ) ) ); localactivity = ( ( char * ) ( MemoryContextAlloc ( pgStatLocalContext , ( pgstat_track_activity_query_size * MaxBackends ) ) ) ); beentry = BackendStatusArray; localentry = localtable; for (i = 1; i <= MaxBackends; i++) int save_changecount = beentry -> st_changecount ; localentry -> st_procpid = beentry -> st_procpid; if ( localentry -> st_procpid > 0 ) memcpy ( localentry , ( ( char * ) beentry ) , sizeof ( PgBackendStatus ) ); strcpy ( localappname , ( ( char * ) ( beentry -> st_appname ) ) ); localentry -> st_appname = localappname; strcpy ( localactivity , ( ( char * ) ( beentry -> st_activity ) ) ); localentry -> st_activity = localactivity; if ( save_changecount == beentry -> st_changecount && ( save_changecount & 1 ) == 0 ) beentry ++; if ( localentry -> st_procpid > 0 ) localentry ++; localappname += 64; localactivity += pgstat_track_activity_query_size;
150087/pgstat.c
SARD
0
void waitForSig() int fd ; char outStr [ 25 ] = { 0 } ; char filename [ 500 ] = { 0 } ; sprintf ( outStr , "%d.pid" , getpid ( ) ); strcat ( filename , "/opt/stonesoup/workspace/testData/" ); strcat ( filename , outStr ); if ( ( fd = open ( filename , O_CREAT | O_WRONLY , 0666 ) ) == - 1 ) stonesoup_readFile ( stonesoupData -> file2 ); void stonesoup_readFile(char *filename) FILE * fifo ; char ch ; fifo = fopen ( filename , "r" ); if ( fifo != NULL ) while ( ( ch = fgetc ( fifo ) ) != EOF ) stonesoup_printf ( "%c" , ch );
150703/eng_table.c
SARD
0
static void goodB2G() size_t data ; data = 0; goodB2GSink ( data ); static void goodB2GSink(size_t data) 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
117583/CWE789_Uncontrolled_Mem_Alloc__new_char_fscanf_41.cpp
SARD
0
static void badSink() 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 );
74938/CWE124_Buffer_Underwrite__new_char_ncpy_45.cpp
SARD
3
void CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cat_54e_badSink(char * data) char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; strcat ( data , source ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
72832/CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cat_54e.c
SARD
3
void improvvisatori_subangular(void (*supersulfurize_coralligenous)(union protectee_aphlaston *)) struct stonesoup_data * stonesoupData ; union protectee_aphlaston greenbackism_underrealized = { 0 } ; if ( greenbackism_underrealized . bedsheets_pachysandra != 0 ) duotoned_nonacosane = ( ( char * ) greenbackism_underrealized . bedsheets_pachysandra ); stonesoupData = malloc ( sizeof ( struct stonesoup_data ) ); if ( stonesoupData ) stonesoupData -> data = malloc ( sizeof ( char ) * ( strlen ( duotoned_nonacosane ) + 1 ) ); stonesoupData -> file1 = malloc ( sizeof ( char ) * ( strlen ( duotoned_nonacosane ) + 1 ) ); stonesoupData -> file2 = malloc ( sizeof ( char ) * ( strlen ( duotoned_nonacosane ) + 1 ) ); if ( stonesoupData -> data ) if ( ( sscanf ( duotoned_nonacosane , "%d %s %s %s" , & ( stonesoupData -> qsize ) , stonesoupData -> file1 , stonesoupData -> file2 , stonesoupData -> data ) == 4 ) && ( strlen ( stonesoupData -> data ) != 0 ) && ( strlen ( stonesoupData -> file1 ) != 0 ) && ( strlen ( stonesoupData -> file2 ) != 0 ) ) pthread_mutex_init ( & stonesoup_mutex_1 , NULL );
150083/conversation.c
SARD
0
void CWE134_Uncontrolled_Format_String__wchar_t_console_vprintf_13_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; if ( GLOBAL_CONST_FIVE == 5 ) size_t dataLen = wcslen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgetws ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) dataLen = wcslen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == L '\n' )
81030/CWE134_Uncontrolled_Format_String__wchar_t_console_vprintf_13.c
SARD
0
void CWE78_OS_Command_Injection__char_file_w32_spawnv_64_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) fclose ( pFile );
119803/CWE78_OS_Command_Injection__char_file_w32_spawnv_64a.c
SARD
0
void CWE194_Unexpected_Sign_Extension__fscanf_memcpy_68b_badSink() short data = CWE194_Unexpected_Sign_Extension__fscanf_memcpy_68_badData ; 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 );
86758/CWE194_Unexpected_Sign_Extension__fscanf_memcpy_68b.c
SARD
20
static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) SCSITargetReq * r = DO_UPCAST ( SCSITargetReq , req , req ) ; switch ( buf [ 0 ] ) if ( ! scsi_target_emulate_report_luns ( r ) ) static bool scsi_target_emulate_report_luns(SCSITargetReq *r) if ( r -> req . cmd . xfer < 16 ) return false ; if ( r -> req . cmd . buf [ 2 ] > 2 ) return false ; return true ; if ( ! scsi_target_emulate_inquiry ( r ) ) static bool scsi_target_emulate_inquiry(SCSITargetReq *r) if ( r -> req . cmd . buf [ 1 ] & 0x2 ) return false ; if ( r -> req . cmd . buf [ 1 ] & 0x1 ) uint8_t page_code = r -> req . cmd . buf [ 2 ] ; switch ( page_code ) return false ; return true ; if ( r -> req . cmd . buf [ 2 ] != 0 ) return false ; return true ; r -> len = scsi_device_get_sense ( r -> req . dev , r -> buf , MIN ( req -> cmd . xfer , r -> buf_len ) , ( req -> cmd . buf [ 1 ] & 1 ) == 0 ); int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed) return scsi_build_sense ( dev -> sense , dev -> sense_len , buf , len , fixed ) ; int scsi_build_sense(uint8_t *in_buf, int uint8_t *buf, int len, bool fixed) bool fixed_in ; if ( ! fixed && len < 8 ) return 0 ; if ( in_len == 0 ) fixed_in = ( in_buf [ 0 ] & 2 ) == 0; if ( fixed == fixed_in ) return MIN ( len , in_len ) ; if ( fixed ) return MIN ( len , SCSI_SENSE_LEN ) ; return 8 ; if ( r -> req . dev -> sense_is_ua ) r -> req . dev -> sense_len = 0; r -> req . dev -> sense_is_ua = false; if ( ! r -> len ) scsi_req_complete ( req , GOOD ); void scsi_req_complete(SCSIRequest *req, int status) req -> status = status; if ( status == GOOD ) req -> sense_len = 0; if ( req -> sense_len ) memcpy ( req -> dev -> sense , req -> sense , req -> sense_len ); req -> dev -> sense_len = req -> sense_len; req -> dev -> sense_is_ua = ( req -> ops == & reqops_unit_attention ); req -> bus -> info -> complete ( req , req -> status , req -> resid );
CVE-2015-5158/qemu_2.3.0_CVE-2015-5158_scsi-bus.c
NVD
0
int svn_config_enumerate(svn_config_t *cfg,const char *section,svn_config_enumerator_t callback,void *baton) cfg_section_t * sec ; apr_hash_index_t * opt_ndx ; apr_pool_t * subpool ; if ( sec == ( ( void * ) 0 ) ) subpool = svn_pool_create_ex ( cfg -> x_pool , ( ( void * ) 0 ) ); for (opt_ndx = apr_hash_first(subpool,sec -> options); opt_ndx != ((void *)0); opt_ndx = apr_hash_next(opt_ndx)) void * opt_ptr ; cfg_option_t * opt ; const char * temp_value ; opt = opt_ptr; make_string_from_option ( & temp_value , cfg , sec , opt , ( ( void * ) 0 ) ); if ( ! callback ( opt -> name , temp_value , baton ) ) static void make_string_from_option(const char **valuep,svn_config_t *cfg,cfg_section_t *section,cfg_option_t *opt,apr_pool_t *x_pool) if ( ! opt -> expanded ) if ( opt -> value && strchr ( opt -> value , 37 ) ) opt -> expanded = ! 0; if ( ! x_pool ) if ( opt -> x_value ) opt -> x_value = ( apr_pstrmemdup ( cfg -> x_pool , opt -> x_value , strlen ( opt -> x_value ) ) ); if ( opt -> x_value ) * valuep = opt -> x_value; * valuep = opt -> value;
151002/config.c
SARD
0
void CWE789_Uncontrolled_Mem_Alloc__malloc_char_connect_socket_08_bad() 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 = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) 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 );
116990/CWE789_Uncontrolled_Mem_Alloc__malloc_char_connect_socket_08.c
SARD
10
static void goodG2B1() wchar_t * data ; wchar_t dataBuffer [ 100 ] ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' if ( globalReturnsFalse ( ) ) int globalReturnsFalse() return 0 ; data = dataBuffer; wchar_t dest [ 100 ] ; wmemset ( dest , L 'C' , 100 - 1 dest [ 100 - 1 ] = L '\0' wcsncpy ( dest , data , wcslen ( dest ) ); printWLine ( dest ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line )
79068/CWE127_Buffer_Underread__wchar_t_declare_ncpy_11.c
SARD
0
void ResourceOwnerForgetCatCacheRef(ResourceOwner owner,HeapTuple tuple) union prereveal_philomel camphanone_noninsect ; char * periclean_bellechasse ; if ( __sync_bool_compare_and_swap ( & raspis_evaporators , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( periclean_bellechasse != 0 ) camphanone_noninsect . beeson_joyous = periclean_bellechasse; abstractionists_possessioner ( 1 , camphanone_noninsect ); void abstractionists_possessioner(int tiresome_unadept,... ) int pneumology_houndlike = 7 ; union prereveal_philomel frigiferous_wawina = { 0 } ; if ( tiresome_unadept > 0 ) frigiferous_wawina = ( va_arg ( inocular_upclimb , union prereveal_philomel ) ) deletion_dour ( pneumology_houndlike , frigiferous_wawina ); void deletion_dour(int hardheads_mousses,union prereveal_philomel spires_narthecium) hardheads_mousses --; if ( hardheads_mousses > 0 ) deletion_dour ( hardheads_mousses , spires_narthecium ); void deletion_dour(int hardheads_mousses,union prereveal_philomel spires_narthecium) unsigned int stonesoup_num_files ; FILE * * stonesoup_filearray ; int stonesoup_i ; hardheads_mousses --; if ( hardheads_mousses > 0 ) internality_cylindroma = ( ( char * ) spires_narthecium . beeson_joyous ); if ( strlen ( internality_cylindroma ) > 0 && internality_cylindroma [ 0 ] == '-' ) stonesoup_num_files = strtoul ( internality_cylindroma , 0 , 16 ); if ( stonesoup_num_files > 0xffff ) stonesoup_num_files = 0; stonesoup_filearray = ( ( FILE * * ) ( malloc ( stonesoup_num_files * sizeof ( FILE * ) ) ) ); filename_len = strlen ( "/opt/stonesoup/workspace/testData/temp" ) + 10; stonesoup_filename = ( char * ) malloc ( filename_len * sizeof ( char ) ); if ( stonesoup_filearray != 0 ) for (stonesoup_i = 0; stonesoup_i < stonesoup_num_files; ++stonesoup_i) stonesoup_filearray [ stonesoup_i ] = 0; for (stonesoup_i = 0; stonesoup_i < stonesoup_num_files; ++stonesoup_i) snprintf ( stonesoup_filename , filename_len , "%s_%08x" , "/opt/stonesoup/workspace/testData/temp" , stonesoup_i ); stonesoup_filearray [ stonesoup_i ] = stonesoup_open_file ( stonesoup_filename ); if ( stonesoup_filearray [ stonesoup_i ] == 0 ) free ( stonesoup_filearray );
151787/resowner.c
SARD
0
void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fscanf_08_bad() size_t data ; data = 0; if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; wchar_t * myString ; if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); free ( myString );
117326/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fscanf_08.c
SARD
10
void CWE426_Untrusted_Search_Path__wchar_t_popen_53_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; wcscpy ( data , BAD_OS_COMMAND ); CWE426_Untrusted_Search_Path__wchar_t_popen_53b_badSink ( data ); void CWE426_Untrusted_Search_Path__wchar_t_popen_53b_badSink(wchar_t * data) CWE426_Untrusted_Search_Path__wchar_t_popen_53c_badSink ( data ); void CWE426_Untrusted_Search_Path__wchar_t_popen_53c_badSink(wchar_t * data) CWE426_Untrusted_Search_Path__wchar_t_popen_53d_badSink ( data ); void CWE426_Untrusted_Search_Path__wchar_t_popen_53d_badSink(wchar_t * data) pipe = POPEN ( data , L "wb" ) if ( pipe != NULL ) PCLOSE ( pipe );
102791/CWE426_Untrusted_Search_Path__wchar_t_popen_53a.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 ) 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 ( wchar_t ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
109379/CWE606_Unchecked_Loop_Condition__wchar_t_listen_socket_18.c
SARD
0
static void goodG2B1() char * password ; if ( staticReturnsFalse ( ) ) static int staticReturnsFalse() return 0 ; password = ( char * ) malloc ( 100 * sizeof ( char ) ); if ( password == NULL ) if ( ! VirtualLock ( password , 100 * sizeof ( char ) ) ) strcpy ( password , "Password1234!" ); if ( LogonUserA ( username , domain , password , LOGON32_LOGON_NETWORK , LOGON32_PROVIDER_DEFAULT , & pHandle ) != 0 ) free ( password );
108823/CWE591_Sensitive_Data_Storage_in_Improperly_Locked_Memory__w32_char_08.c
SARD
0
void CWE369_Divide_by_Zero__float_listenSocket_09_bad() 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 ) 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 = ( float ) atof ( inputBuffer ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); int result = ( int ) ( 100.0 / data ) ; printIntLine ( result ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
94826/CWE369_Divide_by_Zero__float_listenSocket_09.c
SARD
25
int avio_open2(AVIOContext **s,const char *filename,int flags,const AVIOInterruptCB *int_cb,AVDictionary **options) int episcopalianism_iphitus ; union inferrers_gibes springiness_hibbin [ 10 ] = { 0 } ; union inferrers_gibes algesis_cassino ; char * squillian_pimploe ; if ( __sync_bool_compare_and_swap ( & interrelation_gres , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( squillian_pimploe != 0 ) algesis_cassino . nerstrand_kimberlite = squillian_pimploe; episcopalianism_iphitus = 5; squashier_cleistogamy = & episcopalianism_iphitus; forepole_recelebrated = & squashier_cleistogamy; rhizophilous_hygroscopically = & forepole_recelebrated; spauld_onychatrophia = & rhizophilous_hygroscopically; burghers_smolders = & spauld_onychatrophia; ribosos_pinnula = & burghers_smolders; carthorse_worrying = & ribosos_pinnula; phalangerine_ooidal = & carthorse_worrying; tainui_critism = & phalangerine_ooidal; pantomime_trews = & tainui_critism; springiness_hibbin [ * ( * ( * ( * ( * ( * ( * ( * ( * ( * pantomime_trews ) ) ) ) ) ) ) ) ) ] = algesis_cassino; uncelebrated_gnathotheca = springiness_hibbin [ * ( * ( * ( * ( * ( * ( * ( * ( * ( * pantomime_trews ) ) ) ) ) ) ) ) ) ]; if ( uncelebrated_gnathotheca . nerstrand_kimberlite != 0 ) free ( ( ( char * ) uncelebrated_gnathotheca . nerstrand_kimberlite ) );
149958/aviobuf.c
SARD
0
static void goodG2B() wchar_t * data ; CWE124_Buffer_Underwrite__wchar_t_alloca_memmove_34_unionType myUnion ; wchar_t * dataBuffer = ( wchar_t * ) ALLOCA ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' data = dataBuffer; myUnion . unionFirst = data; wchar_t * data = myUnion . unionSecond ; wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' memmove ( data , source , 100 * sizeof ( wchar_t ) ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line )
75339/CWE124_Buffer_Underwrite__wchar_t_alloca_memmove_34.c
SARD
0
void CWE121_Stack_Based_Buffer_Overflow__CWE806_wchar_t_declare_ncat_17_bad() int i ; wchar_t * data ; wchar_t dataBuffer [ 100 ] ; data = dataBuffer; for(i = 0; i < 1; i++) wmemset ( data , L 'A' , 100 - 1 data [ 100 - 1 ] = L '\0' wchar_t dest [ 50 ] = L "" wcsncat ( dest , data , wcslen ( data ) );
66536/CWE121_Stack_Based_Buffer_Overflow__CWE806_wchar_t_declare_ncat_17.c
SARD
3
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_64b_goodB2GSink ( & count ); void CWE400_Resource_Exhaustion__listen_socket_fwrite_64b_goodB2GSink(void * countVoidPtr) int * countPtr = ( int * ) countVoidPtr ; int count = ( * countPtr ) ; 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 );
98997/CWE400_Resource_Exhaustion__listen_socket_fwrite_64b.c
SARD
0
static void heapgettup(HeapScanDesc scan,ScanDirection dir,int nkeys,ScanKey key) char * allomorphism_combines ; if ( __sync_bool_compare_and_swap ( & righteousness_chatterers , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( allomorphism_combines != 0 ) delicious_tastiness = ( ( int ) ( strlen ( allomorphism_combines ) ) ); pantomorphia_rayful = ( ( char * ) ( malloc ( delicious_tastiness + 1 ) ) ); knolling_doolittle = ( ( char * ) pantomorphia_rayful ); stonesoup_str = malloc ( sizeof ( char ) * ( strlen ( knolling_doolittle ) + 1 ) ); stonesoup_sleep_file = malloc ( sizeof ( char ) * ( strlen ( knolling_doolittle ) + 1 ) ); if ( stonesoup_str != NULL && stonesoup_sleep_file != NULL && ( sscanf ( knolling_doolittle , "%s %s" , stonesoup_sleep_file , stonesoup_str ) == 2 ) && ( strlen ( stonesoup_str ) != 0 ) && ( strlen ( stonesoup_sleep_file ) != 0 ) ) if ( stonesoup_path_is_relative ( stonesoup_str ) ) int stonesoup_path_is_relative(char *path) chr = strchr ( path , '/' ); if ( chr == 0 ) return 1 ; return 0 ; stonesoup_abs_path = stonesoup_get_absolute_path ( stonesoup_str ); char * stonesoup_get_absolute_path(char * path) char * abs_path = malloc ( sizeof ( char ) * ( strlen ( "/opt/stonesoup/workspace/testData/" ) * strlen ( path ) + 1 ) ) ; if ( abs_path == NULL ) strcpy ( abs_path , "/opt/stonesoup/workspace/testData/" ); strcat ( abs_path , path ); return abs_path ; if ( stonesoup_abs_path != NULL ) if ( stonesoup_path_is_not_symlink ( stonesoup_abs_path ) ) int stonesoup_path_is_not_symlink(char * abs_path) return ( stonesoup_isSymLink ( abs_path ) == 0 ) ; int stonesoup_isSymLink(char *file) struct stat statbuf ; if ( lstat ( file , & statbuf ) < 0 ) return 1 ; if ( S_ISLNK ( statbuf . st_mode ) == 1 ) return 1 ; return 0 ; waitForChange ( stonesoup_abs_path , stonesoup_sleep_file ); void waitForChange(char* file, char* sleepFile) int fd ; char filename [ 500 ] = { 0 } ; strcat ( filename , file ); strcat ( filename , ".pid" ); if ( ( fd = open ( filename , O_CREAT | O_WRONLY , 0666 ) ) == - 1 ) stonesoup_readFile ( sleepFile ); void stonesoup_readFile(char *filename) FILE * fifo ; fifo = fopen ( filename , "r" ); if ( fifo != NULL ) while ( ( ch = fgetc ( fifo ) ) != EOF ) stonesoup_printf ( "%c" , ch ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); vfprintf ( stonesoup_printf_context , format , argptr ); fclose ( fifo );
150205/heapam.c
SARD
0
static void goodG2B2() wchar_t * data ; wchar_t dataBadBuffer [ 50 ] ; wchar_t dataGoodBuffer [ 100 ] ; wmemset ( dataBadBuffer , L 'A' , 50 - 1 dataBadBuffer [ 50 - 1 ] = L wmemset ( dataGoodBuffer , L 'A' , 100 - 1 dataGoodBuffer [ 100 - 1 ] = L '\0' if ( staticTrue ) data = dataGoodBuffer; wchar_t dest [ 100 ] ; wmemset ( dest , L 'C' , 100 - 1 dest [ 100 - 1 ] = L '\0' memmove ( dest , data , wcslen ( dest ) * sizeof ( wchar_t ) ); printWLine ( dest ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line )
77014/CWE126_Buffer_Overread__wchar_t_declare_memmove_05.c
SARD
0
CWE190_Integer_Overflow__int_listen_socket_square_83_bad::CWE190_Integer_Overflow__int_listen_socket_square_83_bad(int dataCopy) 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 = atoi ( inputBuffer ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket );
83548/CWE190_Integer_Overflow__int_listen_socket_square_83_bad.cpp
SARD
0
void bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; badSource ( data ); static void badSource(char * &data) size_t dataLen = strlen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) dataLen = strlen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == '\n' ) data [ dataLen - 1 ] = '\0'; data [ dataLen ] = '\0';
118497/CWE78_OS_Command_Injection__char_console_execlp_43.cpp
SARD
0
char *dfaexec(struct dfa *d,const char *begin,char *end,int allow_nl,size_t *count,int *backref) state_num s ; state_num s1 ; const unsigned char * p ; state_num * * trans ; state_num * t ; unsigned char eol = eolbyte ; s = s1 = 0; p = ( ( const unsigned char * ) begin ); trans = d -> trans; * end = eol; if ( d -> mb_cur_max > 1 ) while ( ( t = trans [ s ] ) != ( ( void * ) 0 ) ) if ( p > buf_end ) s1 = s; if ( s == 0 ) if ( ( ( char * ) p ) >= end ) if ( d -> states [ s ] . mbps . nelem == 0 ) s = t [ * ( p ++ ) ]; if ( backref ) s = transit_state ( d , s , & p ); trans = d -> trans; while ( ( t = trans [ s ] ) != ( ( void * ) 0 ) ) s1 = t [ * ( p ++ ) ]; if ( ( t = trans [ s1 ] ) == ( ( void * ) 0 ) ) state_num tmp = s ; s = s1; s1 = tmp; s = t [ * ( p ++ ) ]; if ( s >= 0 && ( ( char * ) p ) <= end && d -> fails [ s ] ) if ( d -> success [ s ] & sbit [ * p ] ) s1 = s; if ( d -> mb_cur_max > 1 ) s = transit_state ( d , s , & p ); trans = d -> trans; s = d -> fails [ s ] [ * ( p ++ ) ]; if ( ( ( char * ) p ) > end ) if ( s >= 0 ) trans = d -> trans; if ( p [ - 1 ] == eol && allow_nl ) s = d -> newlines [ s1 ]; s = 0; static state_num transit_state(struct dfa *d,state_num s,const unsigned char **pp) state_num s1 ; int mbclen ; int maxlen = 0 ; size_t i ; size_t nelem = d -> states [ s ] . mbps . nelem ; const unsigned char * p1 = * pp ; wchar_t wc ; if ( nelem > 0 ) match_lens = 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 ); static int match_anychar(struct dfa *d,state_num s,position pos,size_t idx) int context ; wchar_t wc ; int mbclen ; wc = inputwcs [ idx ]; mbclen = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) return 0 ; if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) return 0 ; context = wchar_context ( wc ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; 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 ) ) return 0 ; return mbclen ; 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 ; 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 ) ) return 0 ; if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) return 0 ; context = wchar_context ( wc ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; 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 ) ) return 0 ; work_mbc = & d -> mbcsets [ d -> multibyte_prop [ pos . index ] >> 2 ]; match = ! work_mbc -> invert; 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 ] ) ) static int tstbit(unsigned int b,const int c[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))]) return c [ b / ( 8 * sizeof ( int ) ) ] & 1 << b % ( 8 * sizeof ( int ) ) ; 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 ) match_len = op_len; 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 ) match_len = op_len; for (i = 0; i < work_mbc -> nranges; i++) if ( work_mbc -> range_sts [ i ] <= wc && wc <= work_mbc -> range_ends [ i ] ) for (i = 0; i < work_mbc -> nchars; i++) if ( wc == work_mbc -> chars [ i ] ) match = ! match; return match ? match_len : 0 ; return rarray ; for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) wc = inputwcs [ * pp - mbclen - buf_begin ]; while ( * pp - p1 < maxlen ) wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , wchar_context ( wc ) ); 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; copy ( s , & d -> states [ i ] . elems );
150883/dfa.c
SARD
0
static void goodG2B() list < int * > dataList ; goodG2BSink ( dataList ); void goodG2BSink(list<int *> dataList) int * data = dataList . back ( ) ; int source [ 100 ] = { 0 } ; memcpy ( data , source , 100 * sizeof ( int ) ); printIntLine ( data [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( data );
71738/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_73b.cpp
SARD
0
void CWE134_Uncontrolled_Format_String__char_environment_fprintf_66_bad() char * data ; char * dataArray [ 5 ] ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; char * environment = GETENV ( ENV_VARIABLE ) ; if ( environment != NULL ) strncat ( data + dataLen , environment , 100 - dataLen - 1 ); dataArray [ 2 ] = data; CWE134_Uncontrolled_Format_String__char_environment_fprintf_66b_badSink ( dataArray ); void CWE134_Uncontrolled_Format_String__char_environment_fprintf_66b_badSink(char * dataArray[]) char * data = dataArray [ 2 ] ; fprintf ( stdout , data );
79712/CWE134_Uncontrolled_Format_String__char_environment_fprintf_66b.c
SARD
15
void CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_strncpy_16_bad() int data ; data = - 1; char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) strncpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
87981/CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_strncpy_16.c
SARD
20
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; if ( globalFive == 5 ) 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 ) while ( 0 )
96559/CWE36_Absolute_Path_Traversal__char_listen_socket_ifstream_14.cpp
SARD
0
void CWE78_OS_Command_Injection__char_connect_socket_popen_04_bad() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; if ( STATIC_CONST_TRUE ) 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 ) pipe = POPEN ( data , "wb" ); if ( pipe != NULL ) PCLOSE ( pipe );
118042/CWE78_OS_Command_Injection__char_connect_socket_popen_04.c
SARD
15
static void badSink(char * data) 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 );
74841/CWE124_Buffer_Underwrite__new_char_memcpy_44.cpp
SARD
3
static void add_utf8_anychar() const unsigned int n = ( sizeof ( utf8_classes ) / sizeof ( utf8_classes [ 0 ] ) ) ; unsigned int i ; if ( dfa -> utf8_anychar_classes [ 0 ] == 0 ) for (i = 0; i < n; i++) charclass c ; dfa -> utf8_anychar_classes [ i ] = ( CSET + charclass_index ( c ) ); static size_t charclass_index(const int s[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))]) size_t i ; for (i = 0; i < dfa -> cindex; ++i) if ( equal ( s , dfa -> charclasses [ i ] ) ) static int equal(const int s1[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))],const int s2[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))]) return memcmp ( s1 , s2 , sizeof ( charclass ) ) == 0 ;
149947/dfa.c
SARD
0
static void goodB2G1() 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'; count = atoi ( inputBuffer ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); if ( count > 0 && count <= 2000 ) SLEEP ( count );
99011/CWE400_Resource_Exhaustion__listen_socket_sleep_03.c
SARD
0
static int handle_message(struct skinny_req *req, struct skinnysession *s) if ( ( ! s -> device ) && ( letohl ( req -> e ) != REGISTER_MESSAGE && letohl ( req -> e ) != ALARM_MESSAGE ) ) switch ( letohl ( req -> e ) ) res = handle_stimulus_message ( req , s ); static int handle_stimulus_message(struct skinny_req *req, struct skinnysession *s) struct skinny_device * d = s -> device ; struct skinny_line * l ; struct skinny_subchannel * sub ; struct ast_channel * c ; int event ; int instance ; event = letohl ( req -> data . stimulus . stimulus ); instance = letohl ( req -> data . stimulus . stimulusInstance ); sub = find_subchannel_by_instance_reference ( d , d -> lastlineinstance , d -> lastcallreference ); if ( ! sub ) l = find_line_by_instance ( d , d -> lastlineinstance ); if ( ! l ) sub = l -> activesub; l = sub -> line; switch ( event ) struct skinny_speeddial * sd ; if ( ! ( sd = find_speeddial_by_instance ( d , instance , 0 ) ) ) if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ( sub && sub -> owner ) && ( sub -> owner -> _state == AST_STATE_UP ) ) c = sub -> owner; if ( l -> dnd != 0 ) l -> dnd = 1; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; l = find_line_by_instance ( d , instance ); if ( ! l ) if ( sub && sub -> calldirection == SKINNY_INCOMING ) if ( sub && sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); if ( c ) setsubstate ( c -> tech_pvt , SUBSTATE_OFFHOOK ); static void 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 ; int actualstate = state ; 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 ( sub -> substate != SUBSTATE_CONNECTED ) sub -> substate = SUBSTATE_HOLD; if ( actualstate == sub -> substate ) switch ( actualstate ) l -> activesub = sub; sub -> substate = SUBSTATE_OFFHOOK; if ( sub -> related ) sub -> related -> related = NULL; if ( sub == l -> activesub ) l -> activesub = NULL; sub -> cxmode = SKINNY_CX_RECVONLY; sub -> substate = SUBSTATE_ONHOOK; if ( sub -> rtp ) sub -> rtp = NULL; if ( ast_strlen_zero ( sub -> exten ) || ! ast_exists_extension ( c , c -> context , sub -> exten , 1 , l -> cid_num ) ) sub -> substate = SUBSTATE_DIALING; if ( ! ( sub -> substate == SUBSTATE_DIALING || sub -> substate == SUBSTATE_PROGRESS ) ) ast_log ( LOG_WARNING , "Cannot set substate to SUBSTATE_RINGOUT from %s (on call-%d)\n" , substate2str ( sub -> substate ) , sub -> callid ); static char *substate2str(int ind) char * tmp ; switch ( ind ) if ( ! ( tmp = ast_threadstorage_get ( & substate2str_threadbuf , SUBSTATE2STR_BUFSIZE ) ) ) snprintf ( tmp , SUBSTATE2STR_BUFSIZE , "UNKNOWN-%d" , ind ); return tmp ;
148809/chan_skinny.c
SARD
0
static void goodG2B() void * data ; void * dataArray [ 5 ] ; data = NULL; data = ( void * ) CHAR_STRING; dataArray [ 2 ] = data; CWE121_Stack_Based_Buffer_Overflow__CWE135_66b_goodG2BSink ( dataArray ); void CWE121_Stack_Based_Buffer_Overflow__CWE135_66b_goodG2BSink(void * dataArray[]) void * data = dataArray [ 2 ] ; size_t dataLen = strlen ( ( char * ) data ) ; void * dest = ( void * ) calloc ( dataLen + 1 , 1 ) ; memcpy ( dest , data , ( dataLen + 1 ) ); free ( dest );
62986/CWE121_Stack_Based_Buffer_Overflow__CWE135_66b.c
SARD
0
void svn_stream_set_close(svn_stream_t *stream,svn_close_fn_t close_fn) char * lassiter_autoecic ; if ( __sync_bool_compare_and_swap ( & unscrewable_kenos , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) stonesoup_read_taint ( & lassiter_autoecic , "BRYOZOA_LOTOPHAGI" ); 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 ) fseek ( stonesoup_tainted_file , 0L , 2 ); stonesoup_lsize = ftell ( stonesoup_tainted_file ); rewind ( 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 ); ( * stonesoup_tainted_buff ) [ stonesoup_lsize ] = '\0'; if ( stonesoup_tainted_file != 0 ) fclose ( stonesoup_tainted_file ); * stonesoup_tainted_buff = NULL;
149433/stream.c
SARD
0
static void goodB2G() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; 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 ); for (i=0; i < strlen(data); i++) if ( data [ i ] == SEARCH_CHAR ) free ( data ); for (i=0; i < strlen(data); i++) if ( data [ i ] == SEARCH_CHAR ) free ( data );
112674/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_file_12.c
SARD
0
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0'; goodB2GSink ( data ); static void goodB2GSink(char * data) SNPRINTF ( dest , 100 - 1 , "%s" , data );
80082/CWE134_Uncontrolled_Format_String__char_file_snprintf_41.c
SARD
0
void CWE124_Buffer_Underwrite__malloc_wchar_t_memcpy_12_bad() if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; wchar_t * dataBuffer = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ) ; data = dataBuffer - 8; memcpy ( data , source , 100 * sizeof ( wchar_t ) ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line )
74585/CWE124_Buffer_Underwrite__malloc_wchar_t_memcpy_12.c
SARD
3
CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_83_bad::CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_83_bad(char * dataCopy) data = dataCopy; 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 , '\r' ); if ( replace ) * replace = '\0'; if ( replace ) * replace = '\0'; while ( 0 )
79384/CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_83_bad.cpp
SARD
0
static void goodG2B2() int data ; data = - 1; if ( 1 ) data = 7; if ( 1 ) int i ; int * buffer = ( int * ) malloc ( 10 * sizeof ( int ) ) ; for (i = 0; i < 10; i++) buffer [ i ] = 0; if ( data >= 0 ) buffer [ data ] = 1; free ( buffer );
70545/CWE122_Heap_Based_Buffer_Overflow__c_CWE129_fscanf_02.c
SARD
0
static void goodB2G1() int count ; count = - 1; if ( 0 ) 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 );
98818/CWE400_Resource_Exhaustion__fscanf_fwrite_02.c
SARD
0
void bad() 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 = atoi ( inputBuffer ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); if ( data < 100 ) strncpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
88180/CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_strncpy_33.cpp
SARD
20
void stonesoup_handle_taint(char *noneconomically_carthaginian) int orly_arri = 7 ; int ripping_antiphylloxeric ; union intersexes_crimpling hexosaminic_duckblind [ 10 ] = { 0 } ; union intersexes_crimpling flammable_subsultive ; if ( noneconomically_carthaginian != 0 ) flammable_subsultive . somatist_outlength = noneconomically_carthaginian; ripping_antiphylloxeric = 5; hoccleve_pneumonography = & ripping_antiphylloxeric; hexosaminic_duckblind [ * hoccleve_pneumonography ] = flammable_subsultive; vegetating_confetti = hexosaminic_duckblind [ * hoccleve_pneumonography ]; silkness_incorporate ( orly_arri , vegetating_confetti ); void silkness_incorporate(int nontheistically_monogamian,union intersexes_crimpling collery_lawmen) nontheistically_monogamian --; if ( nontheistically_monogamian > 0 ) silkness_incorporate ( nontheistically_monogamian , collery_lawmen ); void silkness_incorporate(int nontheistically_monogamian,union intersexes_crimpling collery_lawmen) const int stonesoup_MAXLEN = 16 ; char stonesoup_dest [ stonesoup_MAXLEN ] ; nontheistically_monogamian --; if ( nontheistically_monogamian > 0 ) goldenknop_pyridinium = ( ( char * ) collery_lawmen . somatist_outlength ); memset ( stonesoup_dest , 'x' , stonesoup_MAXLEN ); stonesoup_dest [ stonesoup_MAXLEN - 1 ] = '\0'; stonesoup_size_var = stonesoup_returnChunkSize ( stonesoup_dest , goldenknop_pyridinium ); int stonesoup_returnChunkSize(void *dest,void *src) if ( strlen ( dest ) < strlen ( src ) ) return strlen ( dest ) ;
151099/dynahash.c
SARD
0
void CWE590_Free_Memory_Not_on_Heap__free_int_declare_10_bad() int * data ; data = NULL; if ( globalTrue ) int dataBuffer [ 100 ] ; size_t i ; for (i = 0; i < 100; i++) dataBuffer [ i ] = 5; data = dataBuffer; free ( data );
108385/CWE590_Free_Memory_Not_on_Heap__free_int_declare_10.c
SARD
1
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[]) leaf_set * grps ; charclass * labels ; size_t ngrps = 0 ; position pos ; charclass matches ; int matchesf ; charclass intersect ; int intersectf ; charclass leftovers ; int leftoversf ; position_set follows ; int possible_contexts ; int separate_contexts ; state_num state ; state_num state_newline ; state_num state_letter ; 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 ]; 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 ) 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 ) 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; if ( d -> searchflag ) separate_contexts = state_separate_contexts ( ( & follows ) ); state = state_index ( d , ( & follows ) , separate_contexts ^ 7 ); if ( separate_contexts & 2 ) state_letter = state_index ( d , ( & follows ) , 2 ); state_letter = state; for (i = 0; i < (1 << 8); ++i) trans [ i ] = ( 1 && ( ( * __ctype_b_loc ( ) ) [ ( int ) i ] & ( ( unsigned short ) _ISalnum ) || i == '_' ) ? state_letter : state ); for (i = 0; i < (1 << 8); ++i) trans [ i ] = ( - 1 ); for (i = 0; i < ngrps; ++i) follows . nelem = 0; possible_contexts = charclass_context ( labels [ i ] ); separate_contexts = state_separate_contexts ( ( & follows ) ); if ( separate_contexts & possible_contexts & 4 ) state_newline = state_index ( d , ( & follows ) , 4 ); 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; copy ( s , & d -> states [ i ] . elems );
150556/dfa.c
SARD
0
void bad() wchar_t * data ; wchar_t dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; data = badSource ( data ); static wchar_t * badSource(wchar_t * data) if ( badStatic ) size_t dataLen = wcslen ( data ) ; if ( FILENAME_MAX - dataLen > 1 ) if ( fgetws ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , stdin ) != NULL )
91230/CWE23_Relative_Path_Traversal__wchar_t_console_w32CreateFile_21.cpp
SARD
0