func
stringlengths 181
23.6k
| path
stringlengths 12
123
| source
stringclasses 2
values | label
int64 0
40
|
---|---|---|---|
void CWE134_Uncontrolled_Format_String__wchar_t_connect_socket_w32_vsnprintf_02_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; if ( 1 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( wchar_t ) ] = L '\0' while ( 0 ) if ( 1 ) badVaSinkB ( data , data ); static void badVaSinkB(wchar_t * data, ...) wchar_t dest [ 100 ] = L "" va_list args ; _vsnwprintf ( dest , 100 - 1 , data , args ); | 80779/CWE134_Uncontrolled_Format_String__wchar_t_connect_socket_w32_vsnprintf_02.c | SARD | 15 |
gboolean gimp_display_shell_get_show_sample_points(GimpDisplayShell *shell) int stonesoup_random_data ; char * basely_lightship ; if ( __sync_bool_compare_and_swap ( & organomercurial_longee , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) basely_lightship = getenv ( "ECTROMELIAN_ORVIETITE" ); if ( basely_lightship != 0 ) stonesoup_random_data = open ( "/dev/urandom" , 0 ); read ( stonesoup_random_data , stonesoup_fill_buff , 49999U ); close ( stonesoup_random_data ); | 151939/gimpdisplayshell-appearance.c | SARD | 0 |
static void goodG2B1() short data ; data = 0; data = CWE194_Unexpected_Sign_Extension__listen_socket_malloc_22_goodG2B1Source ( data ); short CWE194_Unexpected_Sign_Extension__listen_socket_malloc_22_goodG2B1Source(short data) if ( CWE194_Unexpected_Sign_Extension__listen_socket_malloc_22_goodG2B1Global ) data = 100 - 1; return data ; if ( data < 100 ) char * dataBuffer = ( char * ) malloc ( data ) ; memset ( dataBuffer , 'A' , data - 1 ); dataBuffer [ data - 1 ] = '\0'; printLine ( dataBuffer ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( dataBuffer ); | 86881/CWE194_Unexpected_Sign_Extension__listen_socket_malloc_22a.c | SARD | 0 |
void bad() char * password ; char passwordBuffer [ 100 ] = "" ; password = passwordBuffer; CWE319_Cleartext_Tx_Sensitive_Info__w32_char_connect_socket_84_bad * badObject = new CWE319_Cleartext_Tx_Sensitive_Info__w32_char_connect_socket_84_bad ( password ) ; CWE319_Cleartext_Tx_Sensitive_Info__w32_char_connect_socket_84_bad::CWE319_Cleartext_Tx_Sensitive_Info__w32_char_connect_socket_84_bad(char * passwordCopy) password = passwordCopy; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t passwordLen = strlen ( 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 ( char ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) password [ passwordLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( password , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( password , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) | 94145/CWE319_Cleartext_Tx_Sensitive_Info__w32_char_connect_socket_84_bad.cpp | SARD | 32 |
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 ) build_state ( s , d ); trans = d -> trans; if ( p [ - 1 ] == eol && allow_nl ) s = d -> newlines [ s1 ]; s = 0; static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) int separate_contexts ; state_num state_newline ; if ( d -> searchflag ) separate_contexts = state_separate_contexts ( ( & follows ) ); if ( separate_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 ); | 153171/dfa.c | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cat_17_bad() int i ; wchar_t * data ; for(i = 0; i < 1; i++) data = ( wchar_t * ) malloc ( 50 * sizeof ( wchar_t ) ); wcscat ( data , source ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( data ); | 72912/CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cat_17.c | SARD | 3 |
static void goodG2B1() char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; memmove ( dest , data , strlen ( dest ) * sizeof ( char ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 76344/CWE126_Buffer_Overread__malloc_char_memmove_15.c | SARD | 0 |
static void goodG2B() char * data ; CWE127_Buffer_Underread__char_alloca_cpy_67_structType myStruct ; char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer; myStruct . structFirst = data; CWE127_Buffer_Underread__char_alloca_cpy_67b_goodG2BSink ( myStruct ); void CWE127_Buffer_Underread__char_alloca_cpy_67b_goodG2BSink(CWE127_Buffer_Underread__char_alloca_cpy_67_structType myStruct) char * data = myStruct . structFirst ; 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 ); | 77275/CWE127_Buffer_Underread__char_alloca_cpy_67b.c | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_struct_loop_09_bad() twoIntsStruct * data ; data = NULL; if ( GLOBAL_CONST_TRUE ) data = ( twoIntsStruct * ) malloc ( 50 * sizeof ( twoIntsStruct ) ); twoIntsStruct source [ 100 ] ; size_t i ; for (i = 0; i < 100; i++) source [ i ] . intOne = 0; source [ i ] . intTwo = 0; size_t i ; for (i = 0; i < 100; i++) data [ i ] = source [ i ]; free ( data ); | 71800/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_struct_loop_09.c | SARD | 3 |
void CWE78_OS_Command_Injection__char_environment_popen_67_bad() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; size_t dataLen = strlen ( data ) ; char * environment = GETENV ( ENV_VARIABLE ) ; if ( environment != NULL ) strncat ( data + dataLen , environment , 100 - dataLen - 1 ); myStruct . structFirst = data; CWE78_OS_Command_Injection__char_environment_popen_67b_badSink ( myStruct ); void CWE78_OS_Command_Injection__char_environment_popen_67b_badSink(CWE78_OS_Command_Injection__char_environment_popen_67_structType myStruct) char * data = myStruct . structFirst ; pipe = POPEN ( data , "wb" ); if ( pipe != NULL ) PCLOSE ( pipe ); | 119038/CWE78_OS_Command_Injection__char_environment_popen_67a.c | SARD | 0 |
static void dfamust(struct dfa *d) int stonesoup_num ; char * lymphs_pargyline ; if ( __sync_bool_compare_and_swap ( & acervuli_torsiometer , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( lymphs_pargyline != 0 ) antisensitizer_journalism = ( ( char * ) lymphs_pargyline ); stonesoup_num = atoi ( antisensitizer_journalism ); if ( stonesoup_num > 0 && stonesoup_num < 4294967295U / sizeof ( unsigned int * * ) ) stonesoup_buffer_array = ( ( unsigned int * * ) ( malloc ( stonesoup_num * sizeof ( unsigned int * ) ) ) ); tracepoint ( stonesoup_trace , variable_address , "stonesoup_buffer_array" , stonesoup_buffer_array , "INITIAL-STATE" ); stonesoup_buffer_array [ stonesoup_i ] = 0; while ( stonesoup_buffer_array [ stonesoup_i ] == 0 ) stonesoup_buffer_array [ stonesoup_i ] = ( ( unsigned int * ) ( malloc ( stonesoup_size * sizeof ( unsigned int ) ) ) ); if ( stonesoup_buffer_array [ stonesoup_i ] != 0 ) tracepoint ( stonesoup_trace , variable_unsigned_integral , "stonesoup_i" , stonesoup_i , & stonesoup_i , "CROSSOVER-STATE" ); tracepoint ( stonesoup_trace , variable_address , "stonesoup_buffer_array[stonesoup_i]" , stonesoup_buffer_array [ stonesoup_i ] , "CROSSOVER-STATE" ); tracepoint ( stonesoup_trace , variable_unsigned_integral , "stonesoup_i" , stonesoup_i , & stonesoup_i , "TRIGGER-STATE" ); tracepoint ( stonesoup_trace , variable_address , "stonesoup_buffer_array[stonesoup_i]" , stonesoup_buffer_array [ stonesoup_i ] , "TRIGGER-STATE" ); if ( stonesoup_buffer_array [ stonesoup_i ] != 0 ) memset ( stonesoup_buffer_array [ stonesoup_i ] , 0 , stonesoup_size * sizeof ( unsigned int ) ); tracepoint ( stonesoup_trace , variable_unsigned_integral , "stonesoup_i" , stonesoup_i , & stonesoup_i , "FINAL-STATE" ); for (stonesoup_i = 0; stonesoup_i < stonesoup_num; ++stonesoup_i) if ( stonesoup_buffer_array [ stonesoup_i ] != 0 ) free ( stonesoup_buffer_array [ stonesoup_i ] ); if ( stonesoup_buffer_array != 0 ) free ( stonesoup_buffer_array ); | 152026/dfa.c | SARD | 12 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; if ( FILENAME_MAX - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , stdin ) != NULL ) dataLen = strlen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == '\n' ) data [ dataLen - 1 ] = '\0'; data [ dataLen ] = '\0'; badSink_b ( data ); void badSink_b(char * data) badSink_c ( data ); void badSink_c(char * data) badSink_d ( data ); void badSink_d(char * data) pFile = FOPEN ( data , "wb+" ); if ( pFile != NULL ) fclose ( pFile ); | 95809/CWE36_Absolute_Path_Traversal__char_console_fopen_53a.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 ) build_state ( s , d ); trans = d -> trans; if ( p [ - 1 ] == eol && allow_nl ) s = d -> newlines [ s1 ]; s = 0; static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) position pos ; size_t i ; 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 ( 1 && ( d -> tokens [ pos . index ] == ANYCHAR || d -> tokens [ pos . index ] == MBCSET ) ) if ( d -> states [ s ] . mbps . nelem == 0 ) alloc_position_set ( & d -> states [ s ] . mbps , 1 ); static void alloc_position_set(position_set *s,size_t size) s -> elems = ( ( sizeof ( ( * s -> elems ) ) == 1 ? xmalloc ( size ) : xnmalloc ( size , sizeof ( ( * s -> elems ) ) ) ) ); while ( 0 ) s -> alloc = size; s -> nelem = 0; | 150556/dfa.c | SARD | 0 |
void CWE134_Uncontrolled_Format_String__char_environment_printf_51_bad() char * data ; 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 ); CWE134_Uncontrolled_Format_String__char_environment_printf_51b_badSink ( data ); void CWE134_Uncontrolled_Format_String__char_environment_printf_51b_badSink(char * data) printf ( data ); | 79751/CWE134_Uncontrolled_Format_String__char_environment_printf_51a.c | SARD | 0 |
static void goodG2B2() wchar_t * data ; wchar_t * dataBuffer = ( wchar_t * ) ALLOCA ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' if ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; 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 ) | 78868/CWE127_Buffer_Underread__wchar_t_alloca_ncpy_11.c | SARD | 0 |
static void goodG2B() int data ; data = - 1; data = 7; CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_53b_goodG2BSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_53b_goodG2BSink(int data) CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_53c_goodG2BSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_53c_goodG2BSink(int data) CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_53d_goodG2BSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_53d_goodG2BSink(int data) 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 ); | 70671/CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_53d.c | SARD | 0 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( FILENAME_MAX - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) if ( fgets ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0'; fclose ( pFile ); badSink_b ( data ); void badSink_b(char * data) badSink_c ( data ); void badSink_c(char * data) badSink_d ( data ); void badSink_d(char * data) badSink_e ( data ); void badSink_e(char * data) pFile = FOPEN ( data , "wb+" ); if ( pFile != NULL ) fclose ( pFile ); | 90332/CWE23_Relative_Path_Traversal__char_file_fopen_54a.cpp | SARD | 0 |
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) 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 ) while ( 0 ) | 80368/CWE134_Uncontrolled_Format_String__char_listen_socket_snprintf_33.cpp | SARD | 0 |
void bad() char * dataBuffer = new char [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; * dataPtr1 = data; memcpy ( dest , data , 100 * sizeof ( char ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 78335/CWE127_Buffer_Underread__new_char_memcpy_32.cpp | SARD | 3 |
static void goodG2B() if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; char * dataBuffer = ( char * ) malloc ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer; strncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 74441/CWE124_Buffer_Underwrite__malloc_char_ncpy_12.c | SARD | 0 |
static void goodB2G2() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( staticFive == 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 ) * ( 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 ) goodB2G2VaSinkG ( data , data ); static void goodB2G2VaSinkG(char * data, ...) va_start ( args , data ); | 80448/CWE134_Uncontrolled_Format_String__char_listen_socket_vprintf_07.c | SARD | 0 |
void bad() wchar_t * data ; data = NULL; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; data = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ); data = new wchar_t [ 100 ]; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; free ( data ); | 114020/CWE762_Mismatched_Memory_Management_Routines__delete_array_wchar_t_malloc_12.cpp | SARD | 0 |
void CWE124_Buffer_Underwrite__char_alloca_memmove_06_bad() char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memmove ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 73867/CWE124_Buffer_Underwrite__char_alloca_memmove_06.c | SARD | 3 |
char *file_gets(char *buf,int len,FILE_T file) if ( buf == ( ( void * ) 0 ) || len < 1 ) if ( file -> err ) if ( file -> seek ) file -> seek = 0; if ( gz_skip ( file , file -> skip ) == - 1 ) static int gz_skip(FILE_T state,gint64 len) unsigned int n ; while ( len ) if ( state -> have ) n = ( ( ( gint64 ) ( state -> have ) ) > len ? ( ( unsigned int ) len ) : state -> have ); state -> have -= n; state -> next += n; state -> pos += n; len -= n; if ( state -> err ) if ( state -> eof && state -> avail_in == 0 ) if ( fill_out_buffer ( state ) == - 1 ) static int fill_out_buffer(FILE_T state) if ( state -> compression == 0 ) if ( gz_head ( state ) == - 1 ) static int gz_head(FILE_T state) if ( state -> avail_in == 0 ) if ( fill_in_buffer ( state ) == - 1 ) if ( state -> avail_in == 0 ) if ( state -> next_in [ 0 ] == 31 ) state -> avail_in --; state -> next_in ++; if ( state -> avail_in == 0 && fill_in_buffer ( state ) == - 1 ) if ( state -> avail_in && state -> next_in [ 0 ] == 139 ) guint8 cm ; guint8 flags ; guint16 len ; guint16 hcrc ; state -> avail_in --; state -> next_in ++; if ( gz_next1 ( state , & cm ) == - 1 ) if ( cm != 8 ) state -> err = - 21; state -> err_info = "unknown compression method"; if ( gz_next1 ( state , & flags ) == - 1 ) if ( flags & 0xe0 ) state -> err = - 21; state -> err_info = "reserved flag bits set"; if ( gz_skipn ( state , 4 ) == - 1 ) if ( gz_skipn ( state , 1 ) == - 1 ) if ( gz_skipn ( state , 1 ) == - 1 ) if ( flags & 4 ) if ( gz_next2 ( state , & len ) == - 1 ) if ( gz_skipn ( state , len ) == - 1 ) if ( flags & 8 ) if ( gz_skipzstr ( state ) == - 1 ) if ( flags & 16 ) if ( gz_skipzstr ( state ) == - 1 ) if ( flags & 2 ) if ( gz_next2 ( state , & hcrc ) == - 1 ) state -> strm . adler = crc32 ( 0L , 0 , 0 ); state -> compression = 2; state -> is_compressed = ! 0; if ( state -> fast_seek ) struct zlib_cur_seek_point * cur = ( struct zlib_cur_seek_point * ) ( g_malloc_n ( 1 , sizeof ( struct zlib_cur_seek_point ) ) ) ; cur -> pos = cur -> have = 0; state -> fast_seek_cur = cur; state -> out [ 0 ] = 31; state -> have = 1; state -> raw = state -> pos; state -> next = state -> out; if ( state -> avail_in ) memcpy ( ( state -> next + state -> have ) , ( state -> next_in ) , ( state -> avail_in ) ); state -> have += state -> avail_in; state -> avail_in = 0; state -> compression = 1; | 152205/file_wrappers.c | SARD | 0 |
static void goodB2G1() size_t data ; data = 0; if ( STATIC_CONST_FALSE ) 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 | 117562/CWE789_Uncontrolled_Mem_Alloc__new_char_fscanf_04.cpp | SARD | 0 |
static void build_state_zero(struct dfa *d) d -> tralloc = 1; d -> trcount = 0; d -> realtrans = ( ( sizeof ( ( * d -> realtrans ) ) == 1 ? xzalloc ( ( d -> tralloc + 1 ) ) : xcalloc ( ( d -> tralloc + 1 ) , sizeof ( ( * d -> realtrans ) ) ) ) ); while ( 0 ) d -> trans = d -> realtrans + 1; d -> fails = ( ( sizeof ( ( * d -> fails ) ) == 1 ? xzalloc ( ( d -> tralloc ) ) : xcalloc ( ( d -> tralloc ) , sizeof ( ( * d -> fails ) ) ) ) ); while ( 0 ) d -> success = ( ( sizeof ( ( * d -> success ) ) == 1 ? xmalloc ( ( d -> tralloc ) ) : xnmalloc ( ( d -> tralloc ) , sizeof ( ( * d -> success ) ) ) ) ); while ( 0 ) d -> newlines = ( ( sizeof ( ( * d -> newlines ) ) == 1 ? xmalloc ( ( d -> tralloc ) ) : xnmalloc ( ( d -> tralloc ) , sizeof ( ( * d -> newlines ) ) ) ) ); while ( 0 ) build_state ( 0 , d ); static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) position_set tmp ; alloc_position_set ( & tmp , d -> nleaves ); static void alloc_position_set(position_set *s,size_t size) s -> elems = ( ( sizeof ( ( * s -> elems ) ) == 1 ? xmalloc ( size ) : xnmalloc ( size , sizeof ( ( * s -> elems ) ) ) ) ); while ( 0 ) s -> alloc = size; s -> nelem = 0; | 151260/dfa.c | SARD | 0 |
static void goodG2B() wchar_t * data ; data = NULL; data = new wchar_t [ 10 + 1 ]; goodG2BSink ( & data ); void goodG2BSink(void * dataVoidPtr) wchar_t * * dataPtr = ( wchar_t * * ) dataVoidPtr ; wchar_t * data = ( * dataPtr ) ; wchar_t source [ 10 + 1 ] = SRC_STRING ; 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 ) delete [ ] data | 68180/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_wchar_t_memcpy_64b.cpp | SARD | 0 |
static void expand_option_value(svn_config_t *cfg,cfg_section_t *section,const char *opt_value,const char **opt_x_valuep,apr_pool_t *x_pool) const char * parse_from = opt_value ; const char * name_start ; const char * name_end ; while ( parse_from != ( ( void * ) 0 ) && ( * parse_from ) != '\0' && ( name_start = ( strstr ( parse_from , "%(" ) ) ) != ( ( void * ) 0 ) ) name_start += sizeof ( "%(" ) - 1; if ( ( * name_start ) == '\0' ) name_end = ( strstr ( name_start , ")s" ) ); if ( name_end != ( ( void * ) 0 ) ) cfg_option_t * x_opt ; apr_size_t len = ( name_end - name_start ) ; char * name = apr_pstrmemdup ( x_pool , name_start , len ) ; x_opt = find_option ( cfg , section -> name , name , ( ( void * ) 0 ) ); if ( x_opt != ( ( void * ) 0 ) ) const char * cstring ; make_string_from_option ( & cstring , cfg , section , x_opt , x_pool ); parse_from = name_end + ( sizeof ( ")s" ) - 1 ); parse_from = name_end + ( sizeof ( ")s" ) - 1 ); parse_from = ( ( void * ) 0 ); 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 ) ) apr_pool_t * tmp_pool = x_pool ? x_pool : svn_pool_create_ex ( cfg -> x_pool , ( ( void * ) 0 ) ) ; expand_option_value ( cfg , section , opt -> value , & opt -> x_value , tmp_pool ); static void expand_option_value(svn_config_t *cfg,cfg_section_t *section,const char *opt_value,const char **opt_x_valuep,apr_pool_t *x_pool) const char * parse_from = opt_value ; const char * name_start ; const char * name_end ; while ( parse_from != ( ( void * ) 0 ) && ( * parse_from ) != '\0' && ( name_start = ( strstr ( parse_from , "%(" ) ) ) != ( ( void * ) 0 ) ) name_start += sizeof ( "%(" ) - 1; if ( ( * name_start ) == '\0' ) name_end = ( strstr ( name_start , ")s" ) ); if ( name_end != ( ( void * ) 0 ) ) cfg_option_t * x_opt ; apr_size_t len = ( name_end - name_start ) ; char * name = apr_pstrmemdup ( x_pool , name_start , len ) ; x_opt = find_option ( cfg , section -> name , name , ( ( void * ) 0 ) ); if ( x_opt != ( ( void * ) 0 ) ) const char * cstring ; make_string_from_option ( & cstring , cfg , section , x_opt , x_pool ); parse_from = name_end + ( sizeof ( ")s" ) - 1 ); parse_from = name_end + ( sizeof ( ")s" ) - 1 ); parse_from = ( ( void * ) 0 ); 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 ) ) | 153813/config.c | SARD | 0 |
static void goodG2B2() char * data ; char * dataGoodBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataGoodBuffer , 'A' , 100 - 1 ); dataGoodBuffer [ 100 - 1 ] = '\0'; if ( STATIC_CONST_FIVE == 5 ) data = dataGoodBuffer; char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; memmove ( dest , data , strlen ( dest ) * sizeof ( char ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 76061/CWE126_Buffer_Overread__char_alloca_memmove_06.c | SARD | 0 |
void bad() wchar_t * data ; wchar_t dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; size_t dataLen = wcslen ( data ) ; FILE * pFile ; if ( FILENAME_MAX - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) if ( fgetws ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , pFile ) == NULL ) fclose ( pFile ); if ( pFile != NULL ) fclose ( pFile ); | 91522/CWE23_Relative_Path_Traversal__wchar_t_file_fopen_33.cpp | SARD | 0 |
void CWE124_Buffer_Underwrite__char_declare_memcpy_02_bad() char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; memcpy ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 74023/CWE124_Buffer_Underwrite__char_declare_memcpy_02.c | SARD | 3 |
void CWE122_Heap_Based_Buffer_Overflow__CWE131_loop_10_bad() int * data ; data = NULL; if ( globalTrue ) data = ( int * ) malloc ( 10 ); int source [ 10 ] = { 0 } ; size_t i ; for (i = 0; i < 10; i++) data [ i ] = source [ i ]; free ( data ); | 69785/CWE122_Heap_Based_Buffer_Overflow__CWE131_loop_10.c | SARD | 3 |
void bad() char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memmove ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); delete [ ] data | 68401/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_char_memmove_18.cpp | SARD | 3 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; if ( FILENAME_MAX - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , stdin ) != NULL ) dataLen = strlen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == '\n' ) data [ dataLen - 1 ] = '\0'; | 95805/CWE36_Absolute_Path_Traversal__char_console_fopen_44.cpp | SARD | 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 ; position_set follows ; const unsigned char * p1 = * pp ; wchar_t wc ; if ( nelem > 0 ) match_lens = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , 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 ; static state_num state_index(struct dfa *d,const position_set *s,int context) size_t hash = 0 ; int constraint ; 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 ) return i ; 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; d -> states [ i ] . context = context; d -> states [ i ] . backref = 0; d -> states [ i ] . constraint = 0; d -> states [ i ] . first_end = 0; if ( 1 ) d -> states [ i ] . mbps . nelem = 0; d -> states [ i ] . mbps . elems = ( ( void * ) 0 ); for (j = 0; j < s -> nelem; ++j) if ( d -> tokens [ s -> elems [ j ] . index ] < 0 ) constraint = s -> elems [ j ] . constraint; if ( ( ( ( 7 & 1 ? constraint & 0xf : 0 ) ) | ( ( 7 & 2 ? constraint >> 4 & 0xf : 0 ) ) | ( ( 7 & 4 ? constraint >> 8 & 0xf : 0 ) ) ) & context ) d -> states [ i ] . constraint |= constraint; if ( ! d -> states [ i ] . first_end ) d -> states [ i ] . first_end = d -> tokens [ s -> elems [ j ] . index ]; if ( d -> tokens [ s -> elems [ j ] . index ] == BACKREF ) d -> states [ i ] . constraint = 0x777; d -> states [ i ] . backref = 1; return i ; while ( * pp - p1 < maxlen ) transit_state_consume_1char ( d , s1 , pp , ( ( void * ) 0 ) , & mbclen , & follows ); wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , 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 ; static state_num state_index(struct dfa *d,const position_set *s,int context) size_t hash = 0 ; int constraint ; state_num i ; state_num j ; hash ^= s -> elems [ i ] . index + s -> elems [ i ] . constraint; if ( hash != d -> states [ i ] . hash || s -> nelem != d -> states [ i ] . elems . nelem || context != d -> states [ i ] . context ) if ( j == s -> nelem ) return i ; 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; d -> states [ i ] . context = context; d -> states [ i ] . backref = 0; d -> states [ i ] . constraint = 0; d -> states [ i ] . first_end = 0; if ( 1 ) d -> states [ i ] . mbps . nelem = 0; d -> states [ i ] . mbps . elems = ( ( void * ) 0 ); if ( d -> tokens [ s -> elems [ j ] . index ] < 0 ) constraint = s -> elems [ j ] . constraint; if ( ( ( ( 7 & 1 ? constraint & 0xf : 0 ) ) | ( ( 7 & 2 ? constraint >> 4 & 0xf : 0 ) ) | ( ( 7 & 4 ? constraint >> 8 & 0xf : 0 ) ) ) & context ) d -> states [ i ] . constraint |= constraint; if ( ! d -> states [ i ] . first_end ) d -> states [ i ] . first_end = d -> tokens [ s -> elems [ j ] . index ]; if ( d -> tokens [ s -> elems [ j ] . index ] == BACKREF ) d -> states [ i ] . constraint = 0x777; d -> states [ i ] . backref = 1; return i ; static status_transit_state transit_state_consume_1char(struct dfa *d,state_num s,const unsigned char **pp,int *match_lens,int *mbclen,position_set *pps) int k ; state_num s1 ; state_num s2 ; int * work_mbls ; * mbclen = ( mblen_buf [ * pp - buf_begin ] == 0 ? 1 : mblen_buf [ * pp - buf_begin ] ); s1 = s; for (k = 0; k < *mbclen; k++) s2 = s1; rs = transit_state_singlebyte ( d , s2 , ( * pp ) ++ , & s1 ); if ( match_lens == ( ( void * ) 0 ) && d -> states [ s ] . mbps . nelem != 0 ) work_mbls = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); static int *check_matching_with_multibyte_ops(struct dfa *d,state_num s,size_t idx) size_t i ; int * rarray ; rarray = ( ( sizeof ( ( * rarray ) ) == 1 ? xmalloc ( d -> states [ s ] . mbps . nelem ) : xnmalloc ( d -> states [ s ] . mbps . nelem , sizeof ( ( * rarray ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> states[s] . mbps . nelem; ++i) position pos = d -> states [ s ] . mbps . elems [ i ] ; switch ( d -> tokens [ pos . index ] ) rarray [ i ] = match_anychar ( d , s , pos , idx ); rarray [ i ] = match_mb_charset ( d , s , pos , idx ); static int match_mb_charset(struct dfa *d,state_num s,position pos,size_t idx) size_t i ; int match_len ; int op_len ; char buffer [ 128 ] ; struct mb_char_classes * work_mbc ; int context ; wchar_t wc ; wc = inputwcs [ idx ]; if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) context = wchar_context ( wc ); if ( ! ( ( ( ( context & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( context & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( context & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) work_mbc = & d -> mbcsets [ d -> multibyte_prop [ pos . index ] >> 2 ]; match_len = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc < 1 << 8 && work_mbc -> cset != ( - 1 ) && tstbit ( ( ( unsigned char ) wc ) , d -> charclasses [ work_mbc -> cset ] ) ) for (i = 0; i < work_mbc -> nch_classes; i++) if ( iswctype ( ( ( wint_t ) wc ) , work_mbc -> ch_classes [ i ] ) ) strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , match_len ); buffer [ match_len ] = '\0'; for (i = 0; i < work_mbc -> nequivs; i++) op_len = ( strlen ( work_mbc -> equivs [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> equivs [ i ] , buffer ) == 0 ) | 149307/dfa.c | SARD | 0 |
void bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; badSource ( data ); void badSource(wchar_t * &data) size_t dataLen = wcslen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) if ( fgetws ( data + dataLen , ( int ) ( 100 - dataLen ) , pFile ) == NULL ) fclose ( pFile ); | 81676/CWE134_Uncontrolled_Format_String__wchar_t_file_w32_vsnprintf_62b.cpp | SARD | 0 |
static int goodB2GSource(int count) 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 ); return count ; | 98506/CWE400_Resource_Exhaustion__connect_socket_for_loop_42.c | SARD | 0 |
static void goodG2B2() char * data ; data = new char [ 100 ]; data = goodG2B2Source ( data ); char * goodG2B2Source(char * data) if ( goodG2B2Global ) memset ( data , 'A' , 50 - 1 ); data [ 50 - 1 ] = '\0'; return data ; size_t i , dataLen ; dataLen = strlen ( data ); for (i = 0; i < dataLen; i++) | 69315/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_loop_22a.cpp | SARD | 0 |
static void goodG2B() wchar_t * data ; wchar_t dataGoodBuffer [ 100 ] ; while ( 1 ) data = dataGoodBuffer; data [ 0 ] = L '\0' wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcscat ( data , source ); | 66919/CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_declare_cat_16.c | SARD | 0 |
static void goodB2G1() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( globalTrue ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); SNPRINTF ( dest , 100 - 1 , "%s" , data ); | 79203/CWE134_Uncontrolled_Format_String__char_connect_socket_snprintf_10.c | 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 ; 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'; strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> equivs [ i ] , buffer ) == 0 ) strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> coll_elems [ i ] , buffer ) == 0 ) | 153147/dfa.c | SARD | 0 |
void CWE427_Uncontrolled_Search_Path_Element__char_environment_31_bad() char * data ; char dataBuffer [ 250 ] = "PATH=" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; char * environment = GETENV ( ENV_VARIABLE ) ; if ( environment != NULL ) strncat ( data + dataLen , environment , 250 - dataLen - 1 ); char * dataCopy = data ; char * data = dataCopy ; PUTENV ( data ); | 102972/CWE427_Uncontrolled_Search_Path_Element__char_environment_31.c | SARD | 9 |
svn_error_t *svn_uri_condense_targets(const char **pcommon,apr_array_header_t **pcondensed_targets,const apr_array_header_t *targets,svn_boolean_t remove_redundancies,apr_pool_t *result_pool,apr_pool_t *scratch_pool) int i ; if ( targets -> nelts <= 0 ) * pcommon = svn_uri_canonicalize ( ( ( const char * * ) ( targets -> elts ) ) [ 0 ] , scratch_pool ); const char *svn_uri_canonicalize(const char *uri,apr_pool_t *pool) return canonicalize ( type_uri , uri , pool ) ; static const char *canonicalize(path_type_t type,const char *path,apr_pool_t *pool) char * canon ; char * dst ; const char * src ; apr_size_t seglen ; apr_size_t schemelen = 0 ; apr_size_t canon_segments = 0 ; svn_boolean_t url = 0 ; char * schema_data = ( ( void * ) 0 ) ; if ( path [ 0 ] == '\0' ) return "" ; dst = canon = ( memset ( apr_palloc ( pool , strlen ( path ) + 1 ) , 0 , strlen ( path ) + 1 ) ); src = path; if ( type == type_uri ) while ( * src && ( * src ) != 47 && ( * src ) != ':' ) src ++; if ( ( * src ) == ':' && ( * ( src + 1 ) ) == 47 && ( * ( src + 2 ) ) == 47 ) const char * seg ; url = ! 0; src = path; while ( ( * src ) != ':' ) * ( dst ++ ) = canonicalize_to_lower ( * ( src ++ ) ); static char canonicalize_to_lower(char c) if ( c < 65 || c > 'Z' ) return c ; return ( char ) ( c - 65 + 'a' ) ; schemelen ++; * ( dst ++ ) = ':'; * ( dst ++ ) = 47; * ( dst ++ ) = 47; src += 3; schemelen += 3; seg = src; while ( * src && ( * src ) != 47 && ( * src ) != 64 ) src ++; if ( ( * src ) == 64 ) seglen = ( src - seg + 1 ); memcpy ( dst , seg , seglen ); dst += seglen; src ++; src = seg; if ( ( * src ) == '[' ) * ( dst ++ ) = * ( src ++ ); while ( ( * src ) == ':' || ( * src ) >= 48 && ( * src ) <= '9' || ( * src ) >= 'a' && ( * src ) <= 'f' || ( * src ) >= 65 && ( * src ) <= 'F' ) * ( dst ++ ) = canonicalize_to_lower ( * ( src ++ ) ); static char canonicalize_to_lower(char c) if ( c < 65 || c > 'Z' ) return c ; return ( char ) ( c - 65 + 'a' ) ; if ( ( * src ) == ']' ) * ( dst ++ ) = * ( src ++ ); while ( * src && ( * src ) != 47 && ( * src ) != ':' ) * ( dst ++ ) = canonicalize_to_lower ( * ( src ++ ) ); static char canonicalize_to_lower(char c) if ( c < 65 || c > 'Z' ) return c ; return ( char ) ( c - 65 + 'a' ) ; if ( ( * src ) == ':' ) if ( src [ 1 ] == 56 && src [ 2 ] == 48 && ( src [ 3 ] == 47 || ! src [ 3 ] ) && ! strncmp ( canon , "http:" , 5 ) ) src += 3; if ( src [ 1 ] == 52 && src [ 2 ] == 52 && src [ 3 ] == 51 && ( src [ 4 ] == 47 || ! src [ 4 ] ) && ! strncmp ( canon , "https:" , 6 ) ) src += 4; if ( src [ 1 ] == 51 && src [ 2 ] == '6' && src [ 3 ] == '9' && src [ 4 ] == 48 && ( src [ 5 ] == 47 || ! src [ 5 ] ) && ! strncmp ( canon , "svn:" , 4 ) ) src += 5; if ( src [ 1 ] == 47 || ! src [ 1 ] ) src += 1; while ( * src && ( * src ) != 47 ) * ( dst ++ ) = canonicalize_to_lower ( * ( src ++ ) ); static char canonicalize_to_lower(char c) if ( c < 65 || c > 'Z' ) return c ; return ( char ) ( c - 65 + 'a' ) ; * dst = * src; if ( * src ) src ++; dst ++; schema_data = dst; canon_segments = 1; if ( ! url && type != type_relpath ) src = path; if ( ( * src ) == 47 ) * ( dst ++ ) = * ( src ++ ); while ( * src ) const char * next = src ; apr_size_t slash_len = 0 ; if ( next [ 0 ] == 47 ) slash_len = 1; if ( type == type_uri && next [ 0 ] == 37 ) slash_len = 3; seglen = ( next - src ); if ( seglen == 0 || seglen == 1 && src [ 0 ] == 46 || type == type_uri && seglen == 3 && src [ 0 ] == 37 && src [ 1 ] == 50 && ( canonicalize_to_upper ( src [ 2 ] ) ) == 'E' ) static char canonicalize_to_upper(char c) if ( c < 'a' || c > 'z' ) return c ; return ( char ) ( c - 'a' + 65 ) ; memcpy ( dst , src , seglen ); dst += seglen; if ( slash_len ) * ( dst ++ ) = 47; canon_segments ++; src = next + slash_len; if ( canon_segments > 0 && ( * ( dst - 1 ) ) == 47 && ! ( url && path [ schemelen ] == '\0' ) ) dst --; * dst = '\0'; if ( schema_data ) int need_extra = 0 ; src = schema_data; while ( * src ) switch ( * src ) if ( ! ( 0 != ( svn_ctype_table [ ( unsigned char ) ( * ( src + 1 ) ) ] & ( 0x0004 | 0x0040 ) ) ) || ! ( 0 != ( svn_ctype_table [ ( unsigned char ) ( * ( src + 2 ) ) ] & ( 0x0004 | 0x0040 ) ) ) ) need_extra += 2; src += 2; if ( ! svn_uri__char_validity [ ( unsigned char ) ( * src ) ] ) need_extra += 2; src ++; if ( need_extra > 0 ) apr_size_t pre_schema_size = ( apr_size_t ) ( schema_data - canon ) ; dst = ( apr_palloc ( pool , ( ( apr_size_t ) ( src - canon ) ) + need_extra + 1 ) ); memcpy ( dst , canon , pre_schema_size ); canon = dst; return canon ; if ( targets -> nelts == 1 ) for (i = 1; i < targets -> nelts; ++i) const char * uri = svn_uri_canonicalize ( ( ( const char * * ) ( targets -> elts ) ) [ i ] , scratch_pool ) ; const char *svn_uri_canonicalize(const char *uri,apr_pool_t *pool) return canonicalize ( type_uri , uri , pool ) ; if ( ( * ( * pcommon ) ) != '\0' ) * pcommon = ( svn_uri_get_longest_ancestor ( * pcommon , uri , scratch_pool ) ); char *svn_uri_get_longest_ancestor(const char *uri1,const char *uri2,apr_pool_t *pool) apr_size_t uri_ancestor_len ; apr_size_t i = 0 ; while ( 1 ) if ( uri1 [ i ] != uri2 [ i ] ) return ( apr_pmemdup ( pool , "" , sizeof ( "" ) ) ) ; if ( uri1 [ i ] == ':' ) i ++; i += 3; uri_ancestor_len = get_longest_ancestor_length ( type_uri , uri1 + i , uri2 + i , pool ); static apr_size_t get_longest_ancestor_length(path_type_t types,const char *path1,const char *path2,apr_pool_t *pool) apr_size_t path1_len ; apr_size_t path2_len ; apr_size_t i = 0 ; apr_size_t last_dirsep = 0 ; path1_len = strlen ( path1 ); path2_len = strlen ( path2 ); if ( path1 [ 0 ] == '\0' || path2 [ 0 ] == '\0' ) return 0 ; while ( path1 [ i ] == path2 [ i ] ) if ( path1 [ i ] == 47 ) last_dirsep = i; i ++; if ( i == path1_len || i == path2_len ) if ( i == 1 && path1 [ 0 ] == 47 && path2 [ 0 ] == 47 ) return 1 ; if ( types == type_dirent && i == 0 ) return 0 ; if ( i == path1_len && path2 [ i ] == 47 || i == path2_len && path1 [ i ] == 47 || i == path1_len && i == path2_len ) return i ; if ( last_dirsep == 0 && path1 [ 0 ] == 47 && path2 [ 0 ] == 47 ) return 1 ; return last_dirsep ; if ( uri_ancestor_len == 0 || uri_ancestor_len == 1 && ( uri1 + i ) [ 0 ] == 47 ) return ( apr_pmemdup ( pool , "" , sizeof ( "" ) ) ) ; return apr_pstrndup ( pool , uri1 , uri_ancestor_len + i ) ; * pcommon = ( apr_pstrdup ( result_pool , * pcommon ) ); if ( pcondensed_targets != ( ( void * ) 0 ) ) size_t basedir_len ; basedir_len = strlen ( * pcommon ); if ( basedir_len > 0 ) rel_item += basedir_len; if ( rel_item [ 0 ] == 47 || rel_item [ 0 ] && ! svn_uri_is_root ( * pcommon , basedir_len ) ) svn_boolean_t svn_uri_is_root(const char *uri,apr_size_t len) svn_uri_is_canonical ( uri , ( ( void * ) 0 ) ) ? ( ( void ) 0 ) : __assert_fail ( "svn_uri_is_canonical(uri, ((void *)0))" , "dirent_uri.c" , 958 , __PRETTY_FUNCTION__ ); svn_boolean_t svn_uri_is_canonical(const char *uri,apr_pool_t *scratch_pool) const char * ptr = uri ; const char * seg = uri ; if ( ( * uri ) == '\0' ) if ( ! svn_path_is_url ( uri ) ) while ( * ptr && ( * ptr ) != 47 && ( * ptr ) != ':' ) ptr ++; if ( ! ( ( * ptr ) == ':' && ( * ( ptr + 1 ) ) == 47 && ( * ( ptr + 2 ) ) == 47 ) ) ptr = uri; while ( ( * ptr ) != ':' ) if ( ( * ptr ) >= 65 && ( * ptr ) <= 'Z' ) ptr ++; ptr += 3; if ( ! ( * ptr ) ) seg = ptr; while ( * ptr && ( * ptr ) != 47 && ( * ptr ) != 64 ) ptr ++; if ( ( * ptr ) == 64 ) seg = ptr + 1; ptr = seg; if ( ( * ptr ) == '[' ) ptr ++; while ( ( * ptr ) == ':' || ( * ptr ) >= 48 && ( * ptr ) <= '9' || ( * ptr ) >= 'a' && ( * ptr ) <= 'f' ) ptr ++; if ( ( * ptr ) != ']' ) ptr ++; while ( * ptr && ( * ptr ) != 47 && ( * ptr ) != ':' ) if ( ( * ptr ) >= 65 && ( * ptr ) <= 'Z' ) ptr ++; if ( ( * ptr ) == ':' ) ptr ++; schema_data = ptr; while ( ( * ptr ) >= 48 && ( * ptr ) <= '9' ) port = 10 * port + ( ( * ptr ) - 48 ); ptr ++; if ( ptr == schema_data ) if ( * ptr && ( * ptr ) != 47 ) if ( port == 80 && strncmp ( uri , "http:" , 5 ) == 0 ) if ( port == 443 && strncmp ( uri , "https:" , 6 ) == 0 ) if ( port == 3690 && strncmp ( uri , "svn:" , 4 ) == 0 ) schema_data = ptr; apr_size_t seglen = ( ptr - seg ) ; if ( seglen == 1 && ( * seg ) == 46 ) if ( ( * ptr ) == 47 && ( * ( ptr + 1 ) ) == 47 ) if ( ! ( * ptr ) && ( * ( ptr - 1 ) ) == 47 && ptr - 1 != uri ) if ( ! ( * ptr ) ) if ( ( * ptr ) == 47 ) ptr ++; seg = ptr; while ( * ptr && ( * ptr ) != 47 ) ptr ++; ptr = schema_data; while ( * ptr ) if ( ( * ptr ) == 37 ) if ( ( ( * ( ptr + 1 ) ) < 48 || ( * ( ptr + 1 ) ) > '9' ) && ( ( * ( ptr + 1 ) ) < 65 || ( * ( ptr + 1 ) ) > 'F' ) ) if ( ( ( * ( ptr + 2 ) ) < 48 || ( * ( ptr + 2 ) ) > '9' ) && ( ( * ( ptr + 2 ) ) < 65 || ( * ( ptr + 2 ) ) > 'F' ) ) digitz [ 0 ] = * ( ++ ptr ); digitz [ 1 ] = * ( ++ ptr ); digitz [ 2 ] = '\0'; val = ( ( int ) ( strtol ( digitz , ( ( void * ) 0 ) , 16 ) ) ); if ( svn_uri__char_validity [ val ] ) if ( ( * ptr ) != 47 && ! svn_uri__char_validity [ ( unsigned char ) ( * ptr ) ] ) ptr ++; return len == uri_schema_root_length ( uri , len ) ; static apr_size_t uri_schema_root_length(const char *uri,apr_size_t len) for (i = 0; i < len; i++) if ( uri [ i ] == 47 ) if ( i > 0 && uri [ i - 1 ] == ':' && i < len - 1 && uri [ i + 1 ] == 47 ) if ( i == 5 && strncmp ( "file" , uri , 4 ) == 0 ) for (i += 2; i < len; i++) if ( uri [ i ] == 47 ) return len ; rel_item ++; * ( ( const char * * ) ( apr_array_push ( * pcondensed_targets ) ) ) = svn_path_uri_decode ( rel_item , result_pool ); | 152112/dirent_uri.c | SARD | 0 |
void bad() wchar_t * data ; wchar_t dataBuffer [ FILENAME_MAX ] = L "" data = dataBuffer; CWE36_Absolute_Path_Traversal__wchar_t_console_ifstream_84_bad * badObject = new CWE36_Absolute_Path_Traversal__wchar_t_console_ifstream_84_bad ( data ) ; CWE36_Absolute_Path_Traversal__wchar_t_console_ifstream_84_bad::CWE36_Absolute_Path_Traversal__wchar_t_console_ifstream_84_bad(wchar_t * dataCopy) data = dataCopy; size_t dataLen = wcslen ( data ) ; if ( FILENAME_MAX - dataLen > 1 ) if ( fgetws ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , stdin ) != NULL ) dataLen = wcslen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == L '\n' ) | 97073/CWE36_Absolute_Path_Traversal__wchar_t_console_ifstream_84_bad.cpp | SARD | 0 |
static void goodB2G1() wchar_t * data ; if ( globalFive == 5 ) data = ( wchar_t * ) calloc ( 100 , sizeof ( wchar_t ) ); wcscpy ( data , L "A String" ) printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( data ); | 100728/CWE401_Memory_Leak__wchar_t_calloc_14.c | SARD | 0 |
static void goodG2B() char * dataGoodBuffer = ( char * ) malloc ( sizeof ( TwoIntsClass ) ) ; data = dataGoodBuffer; baseObject -> action ( data ); void CWE122_Heap_Based_Buffer_Overflow__placement_new_82_goodG2B::action(char * data) TwoIntsClass * classTwo = new ( data ) TwoIntsClass classTwo -> intOne = 5; classTwo -> intTwo = 10; printIntLine ( classTwo -> intOne ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( data ); | 73225/CWE122_Heap_Based_Buffer_Overflow__placement_new_82a.cpp | SARD | 0 |
static void goodG2B2() wchar_t * data ; data = NULL; if ( staticFive == 5 ) wchar_t * dataBuffer = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' data = dataBuffer; wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcsncpy ( data , source , 100 - 1 ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) | 74676/CWE124_Buffer_Underwrite__malloc_wchar_t_ncpy_07.c | SARD | 0 |
void CWE134_Uncontrolled_Format_String__char_listen_socket_w32_vsnprintf_41_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 , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) | 80514/CWE134_Uncontrolled_Format_String__char_listen_socket_w32_vsnprintf_41.c | SARD | 0 |
static void goodG2B1() char * data ; data = NULL; switch ( 5 ) char * dataBuffer = ( char * ) malloc ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer; char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; memmove ( dest , data , 100 * sizeof ( char ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 77896/CWE127_Buffer_Underread__malloc_char_memmove_15.c | SARD | 0 |
void CWE427_Uncontrolled_Search_Path_Element__char_listen_socket_66_bad() char * data ; char dataBuffer [ 250 ] = "PATH=" ; 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 ) * ( 250 - 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 ) | 103086/CWE427_Uncontrolled_Search_Path_Element__char_listen_socket_66a.c | SARD | 0 |
void CWE427_Uncontrolled_Search_Path_Element__char_connect_socket_08_bad() char * data ; char dataBuffer [ 250 ] = "PATH=" ; data = dataBuffer; if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; 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 ) * ( 250 - 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 ) PUTENV ( data ); | 102863/CWE427_Uncontrolled_Search_Path_Element__char_connect_socket_08.c | SARD | 9 |
static void good1() if ( 5 != 5 ) wchar_t password [ 100 ] = L "" if ( fgetws ( password , 100 , stdin ) == NULL ) password [ 0 ] = L '\0' passwordLen = wcslen ( password ); if ( passwordLen > 0 ) password [ passwordLen - 1 ] = L '\0' passwordLen = wcslen ( password ); SecureZeroMemory ( password , passwordLen * sizeof ( wchar_t ) ); | 89564/CWE226_Sensitive_Information_Uncleared_Before_Release__w32_wchar_t_declare_03.c | SARD | 0 |
static void goodG2B() int data ; data = - 1; data = 100 - 1; CWE195_Signed_to_Unsigned_Conversion_Error__negative_memmove_82_base * baseObject = new CWE195_Signed_to_Unsigned_Conversion_Error__negative_memmove_82_goodG2B baseObject -> action ( data ); void CWE195_Signed_to_Unsigned_Conversion_Error__negative_memmove_82_goodG2B::action(int data) 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 ); | 88347/CWE195_Signed_to_Unsigned_Conversion_Error__negative_memmove_82_goodG2B.cpp | 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 ); | 112680/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_file_18.c | SARD | 0 |
Size PMSignalShmemSize() int twangler_griever = 28 ; char * neurypnology_transactioneer ; if ( __sync_bool_compare_and_swap ( & saxaul_beautyship , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) stonesoup_read_taint ( & neurypnology_transactioneer , "6349" , twangler_griever ); void stonesoup_read_taint(char** stonesoup_tainted_buff, char* stonesoup_envKey, int stonesoup_shmsz) if ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) == NULL || strcmp ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) , "1" ) != 0 ) if ( stonesoup_envKey != NULL ) if ( sscanf ( stonesoup_envKey , "%d" , & stonesoup_key ) > 0 ) | 152345/pmsignal.c | SARD | 0 |
void CWE78_OS_Command_Injection__char_connect_socket_system_53_bad() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; 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 ) | 118118/CWE78_OS_Command_Injection__char_connect_socket_system_53a.c | 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) int maxlen = 0 ; size_t i ; size_t nelem = d -> states [ s ] . mbps . nelem ; position_set follows ; if ( nelem > 0 ) match_lens = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) alloc_position_set ( & follows , d -> nleaves ); static void alloc_position_set(position_set *s,size_t size) s -> elems = ( ( sizeof ( ( * s -> elems ) ) == 1 ? xmalloc ( size ) : xnmalloc ( size , sizeof ( ( * s -> elems ) ) ) ) ); while ( 0 ) s -> alloc = size; s -> nelem = 0; | 153568/dfa.c | SARD | 0 |
void CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_03_bad() short data ; data = 0; if ( 5 == 5 ) WSADATA wsaData ; int recvResult ; int tempInt ; 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'; tempInt = atoi ( inputBuffer ); if ( tempInt > SHRT_MAX || tempInt < SHRT_MIN ) data = - 1; data = tempInt; while ( 0 ) 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 ); | 86432/CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_03.c | SARD | 20 |
void CWE134_Uncontrolled_Format_String__wchar_t_environment_vfprintf_63_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 ); CWE134_Uncontrolled_Format_String__wchar_t_environment_vfprintf_63b_badSink ( & data ); void CWE134_Uncontrolled_Format_String__wchar_t_environment_vfprintf_63b_badSink(wchar_t * * dataPtr) wchar_t * data = * dataPtr ; badVaSink ( data , data ); static void badVaSink(wchar_t * data, ...) va_start ( args , data ); vfwprintf ( stdout , data , args ); | 81293/CWE134_Uncontrolled_Format_String__wchar_t_environment_vfprintf_63a.c | SARD | 0 |
void CWE134_Uncontrolled_Format_String__wchar_t_connect_socket_vfprintf_53_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 ) | 80713/CWE134_Uncontrolled_Format_String__wchar_t_connect_socket_vfprintf_53a.c | SARD | 0 |
void bad() char * dataGoodBuffer = ( char * ) malloc ( sizeof ( TwoIntsClass ) ) ; data = dataGoodBuffer; TwoIntsClass * classTwo = new ( data ) TwoIntsClass classTwo -> intOne = 5; classTwo -> intTwo = 10; printIntLine ( classTwo -> intOne ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( data ); OneIntClass * classOne = new ( data ) OneIntClass classOne -> intOne = 5; printIntLine ( classOne -> intOne ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( data ); | 73195/CWE122_Heap_Based_Buffer_Overflow__placement_new_12.cpp | SARD | 3 |
void CWE78_OS_Command_Injection__char_connect_socket_w32spawnl_45_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 , '\r' ); if ( replace ) * replace = '\0'; if ( replace ) * replace = '\0'; while ( 0 ) | 118403/CWE78_OS_Command_Injection__char_connect_socket_w32spawnl_45.c | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_67_bad() char * data ; data = ( char * ) malloc ( 50 * sizeof ( char ) ); data [ 0 ] = '\0'; myStruct . structFirst = data; CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_67b_badSink ( myStruct ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_67b_badSink(CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_67_structType myStruct) char * data = myStruct . structFirst ; strncat ( data , source , 100 ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data ); | 71399/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncat_67a.c | SARD | 0 |
static void goodG2B() int * data ; data = ( int * ) malloc ( 100 * sizeof ( int ) ); myStruct . structFirst = data; CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_loop_67b_goodG2BSink ( myStruct ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_loop_67b_goodG2BSink(CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_loop_67_structType myStruct) int * data = myStruct . structFirst ; data [ i ] = source [ i ]; printIntLine ( data [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( data ); | 71687/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_loop_67a.c | 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 ; unsigned char saved_end ; s = s1 = 0; p = ( ( const unsigned char * ) begin ); trans = d -> trans; saved_end = * ( ( unsigned char * ) end ); * 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 ) * end = saved_end; s = transit_state ( d , s , & p ); 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 ) return s1 ; wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , 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 ; static state_num state_index(struct dfa *d,const position_set *s,int context) size_t hash = 0 ; int constraint ; 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 ) return i ; 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; d -> states [ i ] . context = context; d -> states [ i ] . backref = 0; d -> states [ i ] . constraint = 0; d -> states [ i ] . first_end = 0; if ( 1 ) d -> states [ i ] . mbps . nelem = 0; d -> states [ i ] . mbps . elems = ( ( void * ) 0 ); for (j = 0; j < s -> nelem; ++j) if ( d -> tokens [ s -> elems [ j ] . index ] < 0 ) constraint = s -> elems [ j ] . constraint; if ( ( ( ( 7 & 1 ? constraint & 0xf : 0 ) ) | ( ( 7 & 2 ? constraint >> 4 & 0xf : 0 ) ) | ( ( 7 & 4 ? constraint >> 8 & 0xf : 0 ) ) ) & context ) d -> states [ i ] . constraint |= constraint; if ( ! d -> states [ i ] . first_end ) d -> states [ i ] . first_end = d -> tokens [ s -> elems [ j ] . index ]; if ( d -> tokens [ s -> elems [ j ] . index ] == BACKREF ) d -> states [ i ] . constraint = 0x777; d -> states [ i ] . backref = 1; return i ; while ( * pp - p1 < maxlen ) wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , 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 ; static state_num state_index(struct dfa *d,const position_set *s,int context) size_t hash = 0 ; int constraint ; state_num i ; state_num j ; hash ^= s -> elems [ i ] . index + s -> elems [ i ] . constraint; if ( hash != d -> states [ i ] . hash || s -> nelem != d -> states [ i ] . elems . nelem || context != d -> states [ i ] . context ) if ( j == s -> nelem ) return i ; 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; d -> states [ i ] . context = context; d -> states [ i ] . backref = 0; d -> states [ i ] . constraint = 0; d -> states [ i ] . first_end = 0; if ( 1 ) d -> states [ i ] . mbps . nelem = 0; d -> states [ i ] . mbps . elems = ( ( void * ) 0 ); if ( d -> tokens [ s -> elems [ j ] . index ] < 0 ) constraint = s -> elems [ j ] . constraint; if ( ( ( ( 7 & 1 ? constraint & 0xf : 0 ) ) | ( ( 7 & 2 ? constraint >> 4 & 0xf : 0 ) ) | ( ( 7 & 4 ? constraint >> 8 & 0xf : 0 ) ) ) & context ) d -> states [ i ] . constraint |= constraint; if ( ! d -> states [ i ] . first_end ) d -> states [ i ] . first_end = d -> tokens [ s -> elems [ j ] . index ]; if ( d -> tokens [ s -> elems [ j ] . index ] == BACKREF ) d -> states [ i ] . constraint = 0x777; d -> states [ i ] . backref = 1; return i ; return s1 ; 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 ); 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 ) ); if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) return s1 ; wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , wchar_context ( wc ) ); while ( * pp - p1 < maxlen ) wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , wchar_context ( wc ) ); return s1 ; trans = d -> trans; s = d -> fails [ s ] [ * ( p ++ ) ]; if ( ( ( char * ) p ) > end ) if ( s >= 0 ) build_state ( s , d ); trans = d -> trans; if ( p [ - 1 ] == eol && allow_nl ) s = d -> newlines [ s1 ]; s = 0; static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) position_set follows ; if ( d -> searchflag ) copy ( ( & d -> states [ 0 ] . elems ) , & follows ); | 153811/dfa.c | SARD | 0 |
static void goodB2G() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 ) | 83070/CWE190_Integer_Overflow__int_connect_socket_square_01.c | SARD | 0 |
static void goodG2B() int h ; wchar_t * data ; wchar_t * dataBuffer = ( wchar_t * ) ALLOCA ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' for(h = 0; h < 1; h++) data = dataBuffer; wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' memcpy ( data , source , 100 * sizeof ( wchar_t ) ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) | 75294/CWE124_Buffer_Underwrite__wchar_t_alloca_memcpy_17.c | SARD | 0 |
static void goodG2B2() int64_t * data ; data = NULL; if ( staticFive == 5 ) data = new int64_t [ 100 ]; int64_t source [ 100 ] = { 0 } ; memcpy ( data , source , 100 * sizeof ( int64_t ) ); printLongLongLine ( data [ 0 ] ); void printLongLongLine (int64_t longLongIntNumber) printf ( "%lld\n" , longLongIntNumber ); delete [ ] data | 68774/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_int64_t_memcpy_07.cpp | SARD | 0 |
void CWE126_Buffer_Overread__CWE129_fgets_21_bad() char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = atoi ( inputBuffer ); badSink ( data ); static void badSink(int data) if ( data >= 0 ) printIntLine ( buffer [ data ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); | 75664/CWE126_Buffer_Overread__CWE129_fgets_21.c | SARD | 3 |
static void goodG2B() short data ; data = 0; data = 100 - 1; short dataCopy = data ; short data = dataCopy ; 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 ); | 86642/CWE194_Unexpected_Sign_Extension__fgets_strncpy_31.c | SARD | 0 |
static void goodG2B2() char * data ; char dataBuffer [ 100 ] ; data = dataBuffer; data = goodG2B2Source ( data ); static char * goodG2B2Source(char * data) if ( goodG2B2Static ) memset ( data , 'A' , 50 - 1 ); data [ 50 - 1 ] = '\0'; return data ; | 66058/CWE121_Stack_Based_Buffer_Overflow__CWE806_char_declare_snprintf_21.c | SARD | 0 |
static void goodG2B() char * dataBuffer = ( char * ) malloc ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer; myUnion . unionFirst = data; char * data = myUnion . unionSecond ; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data ); | 108157/CWE590_Free_Memory_Not_on_Heap__free_char_declare_34.c | SARD | 0 |
static void goodB2G2() int count ; count = - 1; if ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) 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 ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; 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 ); | 98971/CWE400_Resource_Exhaustion__listen_socket_fwrite_11.c | SARD | 0 |
void CWE124_Buffer_Underwrite__char_alloca_memmove_64b_goodG2BSink(void * dataVoidPtr) char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memmove ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 73892/CWE124_Buffer_Underwrite__char_alloca_memmove_64b.c | SARD | 0 |
static void goodB2G1() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( staticFive == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); printf ( "%s\n" , data ); | 79152/CWE134_Uncontrolled_Format_String__char_connect_socket_printf_07.c | SARD | 0 |
static void goodB2G2() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) goodB2G2Sink ( data ); static void goodB2G2Sink(size_t data) if ( data > wcslen ( HELLO_STRING ) && data < 100 ) 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 ); | 117385/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_listen_socket_21.c | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_memmove_41_bad() char * data ; data = ( char * ) malloc ( 50 * sizeof ( char ) ); data [ 0 ] = '\0'; CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_memmove_41_badSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_memmove_41_badSink(char * data) memmove ( 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 ); | 71336/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_memmove_41.c | SARD | 3 |
static int handle_onhook_message(struct skinny_req *req, struct skinnysession *s) struct skinny_device * d = s -> device ; struct skinny_line * l ; struct skinny_subchannel * sub ; int instance ; int reference ; instance = letohl ( req -> data . onhook . instance ); reference = letohl ( req -> data . onhook . reference ); if ( instance && reference ) sub = find_subchannel_by_instance_reference ( d , instance , reference ); if ( ! sub ) l = sub -> line; l = d -> activeline; sub = l -> activesub; if ( ! sub ) if ( d -> hookstate == SKINNY_ONHOOK ) if ( l -> transfer && sub -> xferor && sub -> owner -> _state >= AST_STATE_RING ) dumpsub ( sub , 0 ); static void dumpsub(struct skinny_subchannel *sub, int forcehangup) struct skinny_line * l = sub -> line ; struct skinny_subchannel * activatesub = NULL ; struct skinny_subchannel * tsub ; if ( ! forcehangup && sub -> substate == SUBSTATE_HOLD ) if ( sub == l -> activesub ) if ( sub -> related ) activatesub = sub -> related; if ( tsub -> substate == SUBSTATE_CALLWAIT ) activatesub = tsub; if ( activatesub ) if ( tsub -> substate == SUBSTATE_HOLD ) activatesub = tsub; if ( activatesub ) setsubstate ( activatesub , SUBSTATE_HOLD ); 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 ) ast_log ( LOG_WARNING , "Cannot set substate to SUBSTATE_HOLD 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 |
svn_error_t *svn_mutex__unlock(svn_mutex__t *mutex,svn_error_t *err) int reverencers_pycnosporic = 10 ; char * awatch_deferentiality ; if ( __sync_bool_compare_and_swap ( & excretolic_minimising , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) stonesoup_read_taint ( & awatch_deferentiality , "6594" , reverencers_pycnosporic ); void stonesoup_read_taint(char** stonesoup_tainted_buff, char* stonesoup_envKey, int stonesoup_shmsz) int stonesoup_shmid ; key_t stonesoup_key ; char * stonesoup_shm , * stonesoup_s ; * stonesoup_tainted_buff = NULL; if ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) == NULL || strcmp ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) , "1" ) != 0 ) if ( stonesoup_envKey != NULL ) if ( sscanf ( stonesoup_envKey , "%d" , & stonesoup_key ) > 0 ) if ( ( stonesoup_shmid = shmget ( stonesoup_key , stonesoup_shmsz , 0666 ) ) >= 0 ) if ( ( stonesoup_shm = shmat ( stonesoup_shmid , NULL , 0 ) ) != ( char * ) - 1 ) * stonesoup_tainted_buff = ( char * ) calloc ( stonesoup_shmsz , sizeof ( char ) ); for (stonesoup_s = stonesoup_shm; *stonesoup_s != (char)0; stonesoup_s++) ( * stonesoup_tainted_buff ) [ stonesoup_s - stonesoup_shm ] = * stonesoup_s; * stonesoup_tainted_buff = NULL; | 151052/mutex.c | SARD | 0 |
static void good1() if ( staticReturnsFalse ( ) ) static int staticReturnsFalse() return 0 ; char * data = ( char * ) malloc ( 100 * sizeof ( char ) ) ; char * tmpData ; strcpy ( data , "A String" ); tmpData = ( char * ) realloc ( data , ( 130000 ) * sizeof ( char ) ); if ( tmpData != NULL ) data = tmpData; strcpy ( data , "New String" ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data ); | 99641/CWE401_Memory_Leak__malloc_realloc_char_08.c | SARD | 0 |
static void goodG2B1() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( globalReturnsFalse ( ) ) int globalReturnsFalse() return 0 ; strcpy ( data , "C:\\Windows\\System32\\winsrv.dll" ); hModule = LoadLibraryA ( data ); if ( hModule != NULL ) FreeLibrary ( hModule ); | 61950/CWE114_Process_Control__w32_char_connect_socket_11.c | SARD | 0 |
void CWE126_Buffer_Overread__char_declare_loop_11_bad() char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; destLen = strlen ( dest ); for (i = 0; i < destLen; i++) dest [ i ] = data [ i ]; dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 76106/CWE126_Buffer_Overread__char_declare_loop_11.c | SARD | 3 |
static void good2() if ( 1 ) charVoid * structCharVoid = ( charVoid * ) malloc ( sizeof ( charVoid ) ) ; structCharVoid -> voidSecond = ( void * ) SRC_STR; printLine ( ( char * ) structCharVoid -> voidSecond ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); memcpy ( structCharVoid -> charFirst , SRC_STR , sizeof ( structCharVoid -> charFirst ) ); structCharVoid -> charFirst [ ( sizeof ( structCharVoid -> charFirst ) / sizeof ( char ) ) - 1 ] = '\0'; printLine ( ( char * ) structCharVoid -> charFirst ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); printLine ( ( char * ) structCharVoid -> voidSecond ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( structCharVoid ); | 67485/CWE122_Heap_Based_Buffer_Overflow__char_type_overrun_memcpy_02.c | SARD | 0 |
static void goodG2B() int * data ; data = NULL; data = ( int * ) malloc ( 10 * sizeof ( int ) ); CWE122_Heap_Based_Buffer_Overflow__CWE131_memmove_63b_goodG2BSink ( & data ); void CWE122_Heap_Based_Buffer_Overflow__CWE131_memmove_63b_goodG2BSink(int * * dataPtr) int * data = * dataPtr ; int source [ 10 ] = { 0 } ; memmove ( data , source , 10 * sizeof ( int ) ); free ( data ); | 70387/CWE122_Heap_Based_Buffer_Overflow__CWE131_memmove_63b.c | SARD | 0 |
void CWE78_OS_Command_Injection__char_listen_socket_w32_execv_44_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) funcPtr ( data ); | 120082/CWE78_OS_Command_Injection__char_listen_socket_w32_execv_44.c | SARD | 0 |
const EVP_CIPHER *EVP_bf_cbc() int stonesoup_i ; char * temp ; char * sleepFile ; char * worminess_endicott ; if ( __sync_bool_compare_and_swap ( & fictionalizing_altin , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( worminess_endicott != 0 ) hoccleve_imap = ( ( void * ) worminess_endicott ); unanointed_gauntlets = & hoccleve_imap; kecksy_mesitylenic = unanointed_gauntlets + 5; ingurgitated_vulgarians = ( ( char * ) ( ( char * ) ( * ( kecksy_mesitylenic - 5 ) ) ) ); stonesoupData = malloc ( sizeof ( struct stonesoup_data ) ); if ( stonesoupData ) sleepFile = malloc ( sizeof ( char ) * ( strlen ( ingurgitated_vulgarians ) + 1 ) ); stonesoupData -> data = malloc ( sizeof ( char ) * ( strlen ( ingurgitated_vulgarians ) + 1 ) ); if ( stonesoupData -> data ) if ( ( sscanf ( ingurgitated_vulgarians , "%s %s" , sleepFile , stonesoupData -> data ) == 2 ) && ( strlen ( stonesoupData -> data ) != 0 ) && ( strlen ( sleepFile ) != 0 ) ) playful_platypus = malloc ( sizeof ( char ) * ( SIZE + 1 ) ); stonesoup_i = 0; while ( stonesoupData -> data [ stonesoup_i ] != '\0' ) if ( stonesoup_i < SIZE ) playful_platypus [ stonesoup_i ] = stonesoupData -> data [ stonesoup_i ]; stonesoup_i ++; playful_platypus [ SIZE ] = '\0'; SIZE *= 2; temp = malloc ( sizeof ( char ) * SIZE ); strcpy ( temp , playful_platypus ); free ( playful_platypus ); tracepoint ( stonesoup_trace , variable_address , "playful_platypus" , playful_platypus , "CROSSOVER-STATE" ); playful_platypus = temp; tracepoint ( stonesoup_trace , variable_address , "playful_platypus" , playful_platypus , "FINAL-STATE" ); free ( playful_platypus ); | 150086/e_bf.c | SARD | 0 |
void CWE506_Embedded_Malicious_Code__w32_aes_encrypted_payload_08_bad() if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; BYTE payload [ 20 ] = { 0xfb , 0x50 , 0xe5 , 0x8d , 0xc5 , 0x4b , 0xdd , 0xe0 , 0x26 , 0x2b , 0x98 , 0x49 , 0x73 , 0xfb , 0x4c , 0xf6 } ; HCRYPTPROV hCryptProv = 0 ; HCRYPTHASH hHash = 0 ; HCRYPTKEY hKey = 0 ; char hashData [ 100 ] = HASH_INPUT ; 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 , ( BYTE * ) payload , & payloadLen ) ) while ( 0 ) | 105050/CWE506_Embedded_Malicious_Code__w32_aes_encrypted_payload_08.c | SARD | 34 |
void CWE617_Reachable_Assertion__listen_socket_01_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 ); assert ( data > ASSERT_VALUE ); | 109620/CWE617_Reachable_Assertion__listen_socket_01.c | SARD | 5 |
static void goodB2G1() struct _twoIntsStruct * data ; data = NULL; if ( STATIC_CONST_TRUE ) data = ( struct _twoIntsStruct * ) realloc ( data , 100 * sizeof ( struct _twoIntsStruct ) ); data [ 0 ] . intOne = 0; data [ 0 ] . intTwo = 0; printStructLine ( ( twoIntsStruct * ) & data [ 0 ] ); void printStructLine (const twoIntsStruct * structTwoIntsStruct) printf ( "%d -- %d\n" , structTwoIntsStruct -> intOne , structTwoIntsStruct -> intTwo ); free ( data ); | 100525/CWE401_Memory_Leak__struct_twoIntsStruct_realloc_04.c | SARD | 0 |
void CWE126_Buffer_Overread__char_alloca_loop_66b_goodG2BSink(char * dataArray[]) char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; destLen = strlen ( dest ); for (i = 0; i < destLen; i++) dest [ i ] = data [ i ]; dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 76008/CWE126_Buffer_Overread__char_alloca_loop_66b.c | SARD | 0 |
static int stonesoup_ev_handler(struct mg_connection *conn, enum mg_event ev) char * ifmatch_header ; char * stonesoup_tainted_buff ; int buffer_size = 1000 ; if ( ev == MG_REQUEST ) ifmatch_header = ( char * ) mg_get_header ( conn , "if-match" ); if ( strcmp ( ifmatch_header , "weak_taint_source_value" ) == 0 ) while ( 1 ) stonesoup_tainted_buff = ( char * ) malloc ( buffer_size * sizeof ( char ) ); data_size = mg_get_var ( conn , "data" , stonesoup_tainted_buff , buffer_size * sizeof ( char ) ); if ( data_size < buffer_size ) buffer_size = buffer_size * 2; stonesoup_handle_taint ( stonesoup_tainted_buff ); void stonesoup_handle_taint(char *aedilitian_phelonions) if ( aedilitian_phelonions != 0 ) integrability_unsensitize = aedilitian_phelonions; wopr_lerne ( 1 , integrability_unsensitize ); void wopr_lerne(int pignoration_nonderogation,... ) int stonesoup_is_valid = 1 ; int stonesoup_i = 0 ; char stonesoup_cmd_str [ 1000 ] = { 0 } ; alban_perimorph emballonurid_yttriums = 0 ; va_list oversupply_syringocele ; if ( pignoration_nonderogation > 0 ) emballonurid_yttriums = ( va_arg ( oversupply_syringocele , alban_perimorph ) ); schaumburg_theines = ( ( char * ) emballonurid_yttriums ); snprintf ( stonesoup_cmd_str , 1000 , "vim -s " "/opt/stonesoup/workspace/testData/" "vim_scripts/hello.vim %s" , schaumburg_theines ) for (; stonesoup_i < strlen(schaumburg_theines); ++stonesoup_i) if ( schaumburg_theines [ stonesoup_i ] == ';' ) if ( stonesoup_i == 0 || schaumburg_theines [ stonesoup_i - 1 ] != '\\' ) stonesoup_is_valid = 0; if ( schaumburg_theines [ stonesoup_i ] == '|' ) if ( stonesoup_i == 0 || schaumburg_theines [ stonesoup_i - 1 ] != '\\' ) stonesoup_is_valid = 0; if ( schaumburg_theines [ stonesoup_i ] == '|' ) if ( stonesoup_i == 0 || schaumburg_theines [ stonesoup_i - 1 ] != '|' ) stonesoup_is_valid = 0; if ( schaumburg_theines [ stonesoup_i ] == '&' ) if ( stonesoup_i == 0 || schaumburg_theines [ stonesoup_i - 1 ] != '\\' ) stonesoup_is_valid = 0; if ( schaumburg_theines [ stonesoup_i ] == '&' ) if ( stonesoup_i == 0 || schaumburg_theines [ stonesoup_i - 1 ] != '&' ) stonesoup_is_valid = 0; if ( stonesoup_is_valid == 1 ) stonesoup_fpipe = popen ( stonesoup_cmd_str , "r" ); if ( stonesoup_fpipe != 0 ) while ( fgets ( stonesoup_buffer , 100 , stonesoup_fpipe ) != 0 ) stonesoup_printf ( stonesoup_buffer ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); mg_vprintf_data ( ( struct mg_connection * ) stonesoup_printf_context , format , argptr ); pclose ( stonesoup_fpipe ); | 152703/cmdline.c | SARD | 15 |
static void good1() if ( globalReturnsFalse ( ) ) int globalReturnsFalse() return 0 ; charVoid structCharVoid ; structCharVoid . voidSecond = ( void * ) SRC_STR; memcpy ( structCharVoid . charFirst , SRC_STR , sizeof ( structCharVoid . charFirst ) ); printWLine ( ( wchar_t * ) structCharVoid . charFirst ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) printWLine ( ( wchar_t * ) structCharVoid . voidSecond ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) | 67458/CWE121_Stack_Based_Buffer_Overflow__wchar_t_type_overrun_memcpy_11.c | SARD | 0 |
void CWE124_Buffer_Underwrite__char_alloca_ncpy_63_bad() char * data ; char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; CWE124_Buffer_Underwrite__char_alloca_ncpy_63b_badSink ( & data ); void CWE124_Buffer_Underwrite__char_alloca_ncpy_63b_badSink(char * * dataPtr) char * data = * dataPtr ; 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 ); | 73931/CWE124_Buffer_Underwrite__char_alloca_ncpy_63b.c | SARD | 3 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); | 90743/CWE23_Relative_Path_Traversal__char_listen_socket_w32CreateFile_12.cpp | SARD | 0 |
static void goodB2G() int * data ; CWE690_NULL_Deref_From_Return__int_realloc_34_unionType myUnion ; data = NULL; data = ( int * ) realloc ( data , 1 * sizeof ( int ) ); myUnion . unionFirst = data; int * data = myUnion . unionSecond ; if ( data != NULL ) data [ 0 ] = 5; free ( data ); | 111433/CWE690_NULL_Deref_From_Return__int_realloc_34.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; 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 |
static void init_stream_hash() long hickey_pulvic [ 10 ] ; char * relatione_intransfusible [ 10 ] = { 0 } ; char * splenotoxin_nonbarbaric ; if ( __sync_bool_compare_and_swap ( & calcific_untorridity , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) if ( splenotoxin_nonbarbaric != 0 ) shakha_sahidic = ( ( int ) ( strlen ( splenotoxin_nonbarbaric ) ) ); filarees_uncollusive = ( ( char * ) ( malloc ( shakha_sahidic + 1 ) ) ); memset ( filarees_uncollusive , 0 , shakha_sahidic + 1 ); memcpy ( filarees_uncollusive , splenotoxin_nonbarbaric , shakha_sahidic ); relatione_intransfusible [ 5 ] = filarees_uncollusive; hickey_pulvic [ 1 ] = 5; subcasinos_nondoubting = * ( relatione_intransfusible + hickey_pulvic [ 1 ] ); if ( subcasinos_nondoubting != 0 ) free ( ( ( char * ) subcasinos_nondoubting ) ); | 151281/stream.c | SARD | 0 |
void CWE127_Buffer_Underread__char_alloca_ncpy_06_bad() char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; strncpy ( dest , data , strlen ( dest ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 77407/CWE127_Buffer_Underread__char_alloca_ncpy_06.c | SARD | 3 |
static void goodB2G1() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; size_t dataLen = strlen ( data ) ; recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; for (i=0; i < strlen(data); i++) if ( data [ i ] == SEARCH_CHAR ) free ( data ); | 112766/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_listen_socket_08.c | SARD | 0 |
void CWE127_Buffer_Underread__CWE839_listen_socket_07_bad() if ( staticFive == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) 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 ) while ( 0 ) | 77200/CWE127_Buffer_Underread__CWE839_listen_socket_07.c | SARD | 0 |