func
stringlengths 181
23.6k
| path
stringlengths 12
123
| source
stringclasses 2
values | label
int64 0
40
|
---|---|---|---|
static void goodG2B() char * data ; char * dataGoodBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; data = dataGoodBuffer; data [ 0 ] = '\0'; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; strncat ( data , source , 100 ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 63969/CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncat_18.c | SARD | 0 |
void parse_dir_colors() char * * arg ; char * * c ; char * colors ; char * s ; int i ; if ( Hflag ) if ( getenv ( "TERM" ) == ( ( void * ) 0 ) ) s = getenv ( "TREE_COLORS" ); if ( s == ( ( void * ) 0 ) ) s = getenv ( "LS_COLORS" ); if ( ( s == ( ( void * ) 0 ) || strlen ( s ) == 0 ) && force_color ) s = ":no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.bat=01;32:*.BAT=01;32:*.btm=01;32:*.BTM=01;32:*.cmd=01;32:*.CMD=01;32:*.com=01;32:*.COM=01;32:*.dll=01;32:*.DLL=01;32:*.exe=01;32:*.EXE=01;32:*.arj=01;31:*.bz2=01;31:*.deb=01;31:*.gz=01;31:*.lzh=01;31:*.rpm=01;31:*.tar=01;31:*.taz=01;31:*.tb2=01;31:*.tbz2=01;31:*.tbz=01;31:*.tgz=01;31:*.tz2=01;31:*.z=01;31:*.Z=01;31:*.zip=01;31:*.ZIP=01;31:*.zoo=01;31:*.asf=01;35:*.ASF=01;35:*.avi=01;35:*.AVI=01;35:*.bmp=01;35:*.BMP=01;35:*.flac=01;35:*.FLAC=01;35:*.gif=01;35:*.GIF=01;35:*.jpg=01;35:*.JPG=01;35:*.jpeg=01;35:*.JPEG=01;35:*.m2a=01;35:*.M2a=01;35:*.m2v=01;35:*.M2V=01;35:*.mov=01;35:*.MOV=01;35:*.mp3=01;35:*.MP3=01;35:*.mpeg=01;35:*.MPEG=01;35:*.mpg=01;35:*.MPG=01;35:*.ogg=01;35:*.OGG=01;35:*.ppm=01;35:*.rm=01;35:*.RM=01;35:*.tga=01;35:*.TGA=01;35:*.tif=01;35:*.TIF=01;35:*.wav=01;35:*.WAV=01;35:*.wmv=01;35:*.WMV=01;35:*.xbm=01;35:*.xpm=01;35:"; if ( s == ( ( void * ) 0 ) || ! force_color && ( nocolor || ! isatty ( 1 ) ) ) colors = strcpy ( ( xmalloc ( strlen ( s ) + 1 ) ) , s ); arg = split ( colors , ":" , & n ); char **split(char *str,char *delim,int *nwrds) int n = 128 ; char * * w = ( xmalloc ( sizeof ( char * ) * n ) ) ; w [ * nwrds = 0 ] = strtok ( str , delim ); while ( w [ * nwrds ] ) if ( * nwrds == n - 2 ) w = ( xrealloc ( w , sizeof ( char * ) * ( n += 256 ) ) ); w [ ++ * nwrds ] = strtok ( ( ( void * ) 0 ) , delim ); w [ * nwrds ] = ( ( void * ) 0 ); return w ; for (i = 0; arg[i]; i++) c = split ( arg [ i ] , "=" , & n ); char **split(char *str,char *delim,int *nwrds) int n = 128 ; char * * w = ( xmalloc ( sizeof ( char * ) * n ) ) ; w [ * nwrds = 0 ] = strtok ( str , delim ); while ( w [ * nwrds ] ) if ( * nwrds == n - 2 ) w = ( xrealloc ( w , sizeof ( char * ) * ( n += 256 ) ) ); w [ ++ * nwrds ] = strtok ( ( ( void * ) 0 ) , delim ); w [ * nwrds ] = ( ( void * ) 0 ); return w ; switch ( cmd ( c [ 0 ] ) ) int cmd(char *s) static struct { char * cmd ; char cmdnum ; } cmds [ ] = { { ( "no" ) , ( COL_NORMAL ) } , { ( "fi" ) , ( COL_FILE ) } , { ( "di" ) , ( COL_DIR ) } , { ( "ln" ) , ( COL_LINK ) } , { ( "pi" ) , ( COL_FIFO ) } , { ( "do" ) , ( COL_DOOR ) } , { ( "bd" ) , ( COL_BLK ) } , { ( "cd" ) , ( COL_CHR ) } , { ( "or" ) , ( COL_ORPHAN ) } , { ( "so" ) , ( COL_SOCK ) } , { ( "su" ) , ( COL_SETUID ) } , { ( "sg" ) , ( COL_SETGID ) } , { ( "tw" ) , ( COL_STICKY_OTHER_WRITABLE ) } , { ( "ow" ) , ( COL_OTHER_WRITABLE ) } , { ( "st" ) , ( COL_STICKY ) } , { ( "ex" ) , ( COL_EXEC ) } , { ( "mi" ) , ( COL_MISSING ) } , { ( "lc" ) , ( COL_LEFTCODE ) } , { ( "rc" ) , ( COL_RIGHTCODE ) } , { ( "ec" ) , ( COL_ENDCODE ) } , { ( ( ( void * ) 0 ) ) , ( 0 ) } } ; int i ; for (i = 0; cmds[i] . cmdnum; i++) if ( ! strcmp ( cmds [ i ] . cmd , s ) ) return cmds [ i ] . cmdnum ; if ( s [ 0 ] == '*' ) return DOT_EXTENSION ; return ERROR ; if ( c [ 1 ] ) orphan_flgs = strcpy ( ( xmalloc ( strlen ( c [ 1 ] ) + 1 ) ) , c [ 1 ] ); | 150436/color.c | SARD | 0 |
static void goodG2B1() wchar_t * data ; data = NULL; if ( globalFive != 5 ) data = ( wchar_t * ) malloc ( ( 10 + 1 ) * sizeof ( wchar_t ) ); wchar_t source [ 10 + 1 ] = SRC_STRING ; size_t i , sourceLen ; sourceLen = wcslen ( source ); for (i = 0; i < sourceLen + 1; i++) data [ i ] = source [ i ]; free ( data ); | 71037/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_loop_14.c | SARD | 0 |
static void goodG2B() char * data ; map < int , char * > dataMap ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; strcpy ( data , "fixedstringtest" ); dataMap [ 0 ] = data; dataMap [ 1 ] = data; dataMap [ 2 ] = data; goodG2BSink ( dataMap ); void goodG2BSink(map<int, char *> dataMap) char * data = dataMap [ 2 ] ; goodG2BVaSink ( data , data ); static void goodG2BVaSink(char * data, ...) char dest [ 100 ] = "" ; va_list args ; vsnprintf ( dest , 100 - 1 , data , args ); printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 79381/CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_74b.cpp | 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 ) if ( sscanf ( data , "%d" , & n ) == 1 ) | 109128/CWE606_Unchecked_Loop_Condition__char_listen_socket_07.c | SARD | 0 |
static void goodG2B() char * data ; char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; data = dataBuffer; data = dataBuffer; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memcpy ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 74033/CWE124_Buffer_Underwrite__char_declare_memcpy_12.c | SARD | 0 |
static void goodG2B() wchar_t * data ; wchar_t * * dataPtr2 = & data ; data = NULL; data = new wchar_t [ 100 ]; data [ 0 ] = L '\0' wchar_t * data = * dataPtr2 ; wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcsncat ( data , source , 100 ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) delete [ ] data | 69173/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_wchar_t_ncat_32.cpp | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_cpy_03_bad() wchar_t * data ; if ( 5 == 5 ) data = ( wchar_t * ) malloc ( 10 * sizeof ( wchar_t ) ); wcscpy ( data , source ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( data ); | 70978/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_cpy_03.c | SARD | 3 |
void CWE127_Buffer_Underread__wchar_t_declare_memmove_04_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' if ( STATIC_CONST_TRUE ) data = dataBuffer - 8; wchar_t dest [ 100 ] ; wmemset ( dest , L 'C' , 100 - 1 dest [ 100 - 1 ] = L '\0' memmove ( dest , data , 100 * sizeof ( wchar_t ) ); printWLine ( dest ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) | 79021/CWE127_Buffer_Underread__wchar_t_declare_memmove_04.c | SARD | 3 |
static void goodB2G1() if ( staticFive == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; count = atoi ( inputBuffer ); while ( 0 ) if ( count > 0 && count <= 20 ) for (i = 0; i < (size_t)count; i++) | 98487/CWE400_Resource_Exhaustion__connect_socket_for_loop_07.c | SARD | 0 |
cgiEnvironmentResultType cgiWriteEnvironment(char *filename) FILE * out ; out = fopen ( filename , "wb" ); if ( ! out ) if ( ! cgiWriteString ( out , "CGIC2.0" ) ) if ( ! cgiWriteString ( out , cgiServerSoftware ) ) if ( ! cgiWriteString ( out , cgiServerName ) ) if ( ! cgiWriteString ( out , cgiGatewayInterface ) ) if ( ! cgiWriteString ( out , cgiServerProtocol ) ) if ( ! cgiWriteString ( out , cgiServerPort ) ) if ( ! cgiWriteString ( out , cgiRequestMethod ) ) if ( ! cgiWriteString ( out , cgiPathInfo ) ) if ( ! cgiWriteString ( out , cgiPathTranslated ) ) if ( ! cgiWriteString ( out , cgiScriptName ) ) if ( ! cgiWriteString ( out , cgiQueryString ) ) if ( ! cgiWriteString ( out , cgiRemoteHost ) ) if ( ! cgiWriteString ( out , cgiRemoteAddr ) ) if ( ! cgiWriteString ( out , cgiAuthType ) ) if ( ! cgiWriteString ( out , cgiRemoteUser ) ) if ( ! cgiWriteString ( out , cgiRemoteIdent ) ) if ( ! cgiWriteString ( out , cgiContentType ) ) if ( ! cgiWriteString ( out , cgiAccept ) ) if ( ! cgiWriteString ( out , cgiUserAgent ) ) if ( ! cgiWriteString ( out , cgiReferrer ) ) static int cgiWriteString(FILE *out, char *s) int len = ( int ) strlen ( s ) ; cgiWriteInt ( out , len ); if ( ( ( int ) fwrite ( s , 1 , len , out ) ) != len ) | 149093/cgic.c | SARD | 0 |
void CWE126_Buffer_Overread__CWE129_connect_socket_11_bad() if ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( data >= 0 ) printIntLine ( buffer [ data ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); | 75608/CWE126_Buffer_Overread__CWE129_connect_socket_11.c | SARD | 3 |
void CWE78_OS_Command_Injection__char_listen_socket_execlp_02_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( 1 ) 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 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); | 119912/CWE78_OS_Command_Injection__char_listen_socket_execlp_02.c | SARD | 0 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; if ( globalTrue ) 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'; hFile = CreateFileA ( data , ( GENERIC_WRITE | GENERIC_READ ) , 0 , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL ); if ( hFile != INVALID_HANDLE_VALUE ) CloseHandle ( hFile ); | 90021/CWE23_Relative_Path_Traversal__char_console_w32CreateFile_10.cpp | SARD | 4 |
int av_copy_packet(AVPacket *dst,AVPacket *src) * dst = * src; return copy_packet_data ( dst , src ) ; static int copy_packet_data(AVPacket *dst,AVPacket *src) dst -> data = ( ( void * ) 0 ); dst -> side_data = ( ( void * ) 0 ); void * data ; if ( 1 ) if ( ( ( unsigned int ) ( dst -> size ) ) > ( ( unsigned int ) ( dst -> size ) ) + 16 ) data = av_malloc ( ( dst -> size + 16 ) ); data = av_malloc ( ( dst -> size ) ); if ( ! data ) memcpy ( data , ( src -> data ) , ( dst -> size ) ); dst -> data = data; while ( 0 ) dst -> destruct = av_destruct_packet; if ( dst -> side_data_elems ) void * data ; if ( 0 ) if ( ( ( unsigned int ) ( ( dst -> side_data_elems ) * sizeof ( ( * dst -> side_data ) ) ) ) > ( ( unsigned int ) ( ( dst -> side_data_elems ) * sizeof ( ( * dst -> side_data ) ) ) ) + 16 ) data = av_malloc ( ( dst -> side_data_elems ) * sizeof ( ( * dst -> side_data ) ) + 16 ); data = av_malloc ( ( dst -> side_data_elems ) * sizeof ( ( * dst -> side_data ) ) ); if ( ! data ) memcpy ( data , ( src -> side_data ) , ( dst -> side_data_elems ) * sizeof ( ( * dst -> side_data ) ) ); if ( 0 ) memset ( ( ( ( uint8_t * ) data ) + ( dst -> side_data_elems ) * sizeof ( ( * dst -> side_data ) ) ) , 0 , 16 ); dst -> side_data = data; while ( 0 ) memset ( ( ( ( uint8_t * ) data ) + src -> side_data [ i ] . size ) , 0 , 16 ); | 152363/avpacket.c | SARD | 0 |
void CWE134_Uncontrolled_Format_String__char_console_vfprintf_03_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( 5 == 5 ) size_t dataLen = strlen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) dataLen = strlen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == '\n' ) data [ dataLen - 1 ] = '\0'; | 79532/CWE134_Uncontrolled_Format_String__char_console_vfprintf_03.c | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_CWE129_connect_socket_16_bad() while ( 1 ) int * buffer = ( int * ) malloc ( 10 * sizeof ( int ) ) ; buffer [ i ] = 0; buffer [ data ] = 1; for(i = 0; i < 10; i++) printIntLine ( buffer [ i ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); free ( buffer ); | 70463/CWE122_Heap_Based_Buffer_Overflow__c_CWE129_connect_socket_16.c | SARD | 3 |
RestyleManager::ReparentStyleContext(nsIFrame* aFrame) nsStyleContext * oldContext = aFrame -> StyleContext ( ) ; nsRefPtr < nsStyleContext > newContext ; nsIFrame * providerFrame = aFrame -> GetParentStyleContextFrame ( ) ; bool isChild = providerFrame && providerFrame -> GetParent ( ) == aFrame ; nsStyleContext * newParentContext = nullptr ; if ( isChild ) newParentContext = providerFrame -> StyleContext ( ); if ( providerFrame ) newParentContext = providerFrame -> StyleContext ( ); nsIFrame * prevContinuation = GetPrevContinuationWithPossiblySameStyle ( aFrame ) ; nsStyleContext * prevContinuationContext ; bool copyFromContinuation = prevContinuation && ( prevContinuationContext = prevContinuation -> StyleContext ( ) ) -> GetPseudo ( ) == oldContext -> GetPseudo ( ) && prevContinuationContext -> GetParent ( ) == newParentContext ; if ( copyFromContinuation ) newContext = prevContinuationContext; nsIFrame * parentFrame = aFrame -> GetParent ( ) ; Element * element = ElementForStyleContext ( parentFrame ? parentFrame -> GetContent ( ) : nullptr , aFrame , oldContext -> GetPseudoType ( ) ) ; nsIContent * pseudoElementContent = aFrame -> GetContent ( ) ; Element * pseudoElement = ( pseudoElementContent && pseudoElementContent -> IsElement ( ) ) ? pseudoElementContent -> AsElement ( ) : nullptr ; newContext = mPresContext -> StyleSet ( ) -> ReparentStyleContext ( oldContext , newParentContext , element , pseudoElement ); if ( newContext ) if ( newContext != oldContext ) VerifyStyleTree ( mPresContext , aFrame , newParentContext ); static VerifyStyleTree(nsPresContext* aPresContext, nsIFrame* nsStyleContext* aParentContext) nsStyleContext * context = aFrame -> StyleContext ( ) ; int32_t contextIndex = 0 ; for (nsStyleContext* (extraContext = ++contextIndex) VerifyContextParent ( aPresContext , aFrame , extraContext , context ); static VerifyContextParent(nsPresContext* aPresContext, nsIFrame* nsStyleContext* aContext, nsStyleContext* aParentContext) if ( ! aContext ) aContext = aFrame -> StyleContext ( ); if ( ! aParentContext ) nsIFrame * providerFrame = aFrame -> GetParentStyleContextFrame ( ) ; if ( providerFrame ) aParentContext = providerFrame -> StyleContext ( ); nsStyleContext * actualParentContext = aContext -> GetParent ( ) ; if ( aParentContext ) if ( actualParentContext ) DumpContext ( nullptr , actualParentContext ); static DumpContext(nsIFrame* aFrame, nsStyleContext* aContext) if ( aFrame ) fputs ( "frame: " , stdout ); | CVE-2015-0826/Firefox_35.0b8_CVE_2015_0826_layout_base_RestyleManager.cpp | NVD | 0 |
void CWE789_Uncontrolled_Mem_Alloc__malloc_char_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 ) while ( 0 ) | 117127/CWE789_Uncontrolled_Mem_Alloc__malloc_char_listen_socket_01.c | SARD | 0 |
void CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_environment_51_bad() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; size_t dataLen = strlen ( data ) ; strncat ( data + dataLen , environment , 100 - dataLen - 1 ); CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_environment_51b_badSink ( data ); void CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_environment_51b_badSink(char * data) for (; *data != '\0'; data++) if ( * data == SEARCH_CHAR ) free ( data ); | 112644/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_environment_51a.c | SARD | 0 |
static void goodG2B() void * data ; data = NULL; char * dataGoodBuffer = ( char * ) malloc ( 50 * sizeof ( char ) ) ; memset ( dataGoodBuffer , 'A' , 50 - 1 ); dataGoodBuffer [ 50 - 1 ] = '\0'; data = ( void * ) dataGoodBuffer; CWE122_Heap_Based_Buffer_Overflow__CWE135_63b_goodG2BSink ( & data ); void CWE122_Heap_Based_Buffer_Overflow__CWE135_63b_goodG2BSink(void * * dataPtr) void * data = * dataPtr ; size_t dataLen = strlen ( ( char * ) data ) ; void * dest = ( void * ) calloc ( dataLen + 1 , 1 ) ; memcpy ( dest , data , ( dataLen + 1 ) ); printLine ( ( char * ) dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( dest ); | 70435/CWE122_Heap_Based_Buffer_Overflow__CWE135_63b.c | SARD | 0 |
static void goodG2B() wchar_t * data ; CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_ncat_34_unionType myUnion ; wchar_t * dataGoodBuffer = ( wchar_t * ) ALLOCA ( 100 * sizeof ( wchar_t ) ) ; data = dataGoodBuffer; data [ 0 ] = L '\0' myUnion . unionFirst = data; wchar_t * data = myUnion . unionSecond ; wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcsncat ( data , source , 100 ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) | 65173/CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_ncat_34.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 ; 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 ) strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> coll_elems [ i ] , buffer ) == 0 ) | 150556/dfa.c | SARD | 0 |
static void goodG2B1() 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 dest [ 100 ] ; wmemset ( dest , L 'C' , 100 - 1 dest [ 100 - 1 ] = L '\0' memmove ( dest , data , 100 * sizeof ( wchar_t ) ); printWLine ( dest ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) | 78128/CWE127_Buffer_Underread__malloc_wchar_t_memmove_07.c | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_ncpy_04_bad() wchar_t * data ; data = NULL; if ( STATIC_CONST_TRUE ) data = ( wchar_t * ) malloc ( 50 * sizeof ( wchar_t ) ); data [ 0 ] = L '\0' wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcsncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = L '\0' free ( data ); | 72131/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_ncpy_04.c | SARD | 3 |
void CWE222_Truncation_of_Security_Relevant_Information__w32_13_bad() if ( GLOBAL_CONST_FIVE == 5 ) WSADATA wsaData ; struct sockaddr_in service ; char username [ USERNAME_SIZE + 1 ] ; char truncatedUsername [ TRUNCATED_USERNAME_SIZE + 1 ] ; if ( 0 != WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) ) listenSocket = socket ( PF_INET , SOCK_STREAM , 0 ); 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 ( LISTEN_PORT ); if ( SOCKET_ERROR == bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) ) if ( SOCKET_ERROR == listen ( listenSocket , LISTEN_BACKLOG ) ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == INVALID_SOCKET ) if ( sizeof ( username ) - sizeof ( char ) != recv ( acceptSocket , username , sizeof ( username ) - sizeof ( char ) , 0 ) ) username [ USERNAME_SIZE ] = '\0'; memcpy ( truncatedUsername , username , sizeof ( truncatedUsername ) ); truncatedUsername [ TRUNCATED_USERNAME_SIZE ] = '\0'; if ( LogonUserA ( truncatedUsername , DOMAIN , PASSWORD , LOGON32_LOGON_NETWORK , LOGON32_PROVIDER_DEFAULT , & pHandle ) != 0 ) while ( 0 ) | 89484/CWE222_Truncation_of_Security_Relevant_Information__w32_13.c | SARD | 30 |
cgiEnvironmentResultType cgiWriteEnvironment(char *filename) FILE * out ; out = fopen ( filename , "wb" ); if ( ! out ) if ( ! cgiWriteString ( out , "CGIC2.0" ) ) if ( ! cgiWriteString ( out , cgiServerSoftware ) ) if ( ! cgiWriteString ( out , cgiServerName ) ) if ( ! cgiWriteString ( out , cgiGatewayInterface ) ) if ( ! cgiWriteString ( out , cgiServerProtocol ) ) static int cgiWriteString(FILE *out, char *s) int len = ( int ) strlen ( s ) ; if ( ( ( int ) fwrite ( s , 1 , len , out ) ) != len ) | 149093/cgic.c | SARD | 0 |
void CWE194_Unexpected_Sign_Extension__fgets_malloc_31_bad() short data ; data = 0; char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = ( short ) atoi ( inputBuffer ); short dataCopy = data ; short data = dataCopy ; if ( data < 100 ) char * dataBuffer = ( char * ) malloc ( data ) ; memset ( dataBuffer , 'A' , data - 1 ); dataBuffer [ data - 1 ] = '\0'; free ( dataBuffer ); | 86498/CWE194_Unexpected_Sign_Extension__fgets_malloc_31.c | SARD | 20 |
char *svn_dirent_join_many(apr_pool_t *pool,const char *base,... ) apr_size_t saved_lengths [ 10 ] ; apr_size_t total_len ; int nargs ; const char * s ; apr_size_t len ; int add_separator ; int base_arg = 0 ; total_len = strlen ( base ); add_separator = 1; if ( total_len == 0 || base [ total_len - 1 ] == 47 ) add_separator = 0; saved_lengths [ 0 ] = total_len; nargs = 0; while ( ( s = ( va_arg ( va , const char * ) ) ) != ( ( void * ) 0 ) ) len = strlen ( s ); if ( nargs ++ < 10 ) saved_lengths [ nargs ] = len; if ( dirent_is_rooted ( s ) ) static svn_boolean_t dirent_is_rooted(const char *dirent) if ( ! dirent ) return 0 ; if ( dirent [ 0 ] == 47 ) return ! 0 ; return 0 ; total_len = len; add_separator = 1; if ( s [ len - 1 ] == 47 ) add_separator = 0; if ( nargs <= base_arg + 1 ) total_len += add_separator + len; total_len += 1 + len; if ( add_separator == 0 && total_len == 1 ) nargs = 0; while ( ( s = ( va_arg ( va , const char * ) ) ) != ( ( void * ) 0 ) ) if ( nargs < 10 ) len = strlen ( s ); memcpy ( p , s , len ); p += len; * p = '\0'; ( ( apr_size_t ) ( p - dirent ) ) == total_len ? ( ( void ) 0 ) : __assert_fail ( "(apr_size_t)(p - dirent) == total_len" , "dirent_uri.c" , 1164 , __PRETTY_FUNCTION__ ); | 149429/dirent_uri.c | SARD | 0 |
static void goodG2B() char * data ; char * * dataPtr1 = & data ; data = new char [ 100 ]; char * data = * dataPtr1 ; memset ( data , 'A' , 50 - 1 ); data [ 50 - 1 ] = '\0'; * dataPtr1 = data; strncpy ( dest , data , strlen ( data ) ); dest [ 50 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); delete [ ] data | 69509/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncpy_32.cpp | SARD | 0 |
void CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_memmove_08_bad() char source [ 100 ] ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memmove ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 88117/CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_memmove_08.c | SARD | 20 |
static void goodG2B() int h ; char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; for(h = 0; h < 1; h++) strcpy ( data , "C:\\Windows\\System32\\winsrv.dll" ); hModule = LoadLibraryA ( data ); if ( hModule != NULL ) FreeLibrary ( hModule ); | 62004/CWE114_Process_Control__w32_char_console_17.c | SARD | 0 |
static CVE_2015_1159_PATCHED_cgi_puts(const char *s, /* I - String to output FILE *out) /* I - Output file */ while ( * s ) if ( * s == '<' ) if ( * s == '>' ) if ( * s == '\"' ) if ( * s == '\'' ) fputs ( "'" , out ); s ++; | CVE-2015-1159/CVE_2015_1159_PATCHED_cgi_puts.c | NVD | 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[]) leaf_set * grps ; charclass * labels ; size_t ngrps = 0 ; position pos ; charclass matches ; int matchesf ; charclass intersect ; int intersectf ; charclass leftovers ; int leftoversf ; position_set follows ; int possible_contexts ; int separate_contexts ; state_num state ; state_num state_letter ; size_t i ; size_t j ; size_t k ; grps = ( ( sizeof ( ( * grps ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * grps ) ) ) ) ); while ( 0 ) labels = ( ( sizeof ( ( * labels ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * labels ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> states[s] . elems . nelem; ++i) pos = d -> states [ s ] . elems . elems [ i ]; if ( d -> tokens [ pos . index ] >= 0 && d -> tokens [ pos . index ] < ( 1 << 8 ) ) if ( d -> tokens [ pos . index ] >= CSET ) if ( pos . constraint != 0x777 ) if ( ! ( ( ( ( 4 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= ~newline [ j ]; if ( ! ( ( ( ( 2 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= ~letters [ j ]; if ( ! ( ( ( ( 1 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= letters [ j ] | newline [ j ]; if ( j == ( ( 1 << 8 ) + 8 * sizeof ( int ) - 1 ) / ( 8 * sizeof ( int ) ) ) for (j = 0; j < ngrps; ++j) if ( d -> tokens [ pos . index ] >= 0 && d -> tokens [ pos . index ] < ( 1 << 8 ) && ! tstbit ( d -> tokens [ pos . index ] , labels [ j ] ) ) intersectf = 0; for (k = 0; k < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++k) ( intersect [ k ] = matches [ k ] & labels [ j ] [ k ] ) ? ( intersectf = 1 ) : 0; if ( ! intersectf ) leftoversf = matchesf = 0; for (k = 0; k < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++k) int match = matches [ k ] ; int label = labels [ j ] [ k ] ; ( leftovers [ k ] = ~match & label ) ? ( leftoversf = 1 ) : 0; ( matches [ k ] = match & ~label ) ? ( matchesf = 1 ) : 0; if ( leftoversf ) grps [ ngrps ] . elems = ( ( sizeof ( ( * grps [ ngrps ] . elems ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * grps [ ngrps ] . elems ) ) ) ) ); while ( 0 ) grps [ ngrps ] . nelem = grps [ j ] . nelem; grps [ j ] . elems [ grps [ j ] . nelem ++ ] = pos . index; if ( ! matchesf ) if ( j == ngrps ) grps [ ngrps ] . elems = ( ( sizeof ( ( * grps [ ngrps ] . elems ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * grps [ ngrps ] . elems ) ) ) ) ); while ( 0 ) grps [ ngrps ] . nelem = 1; grps [ ngrps ] . elems [ 0 ] = pos . index; if ( d -> searchflag ) separate_contexts = state_separate_contexts ( ( & follows ) ); state = state_index ( d , ( & follows ) , separate_contexts ^ 7 ); if ( separate_contexts & 2 ) state_letter = state_index ( d , ( & follows ) , 2 ); state_letter = state; for (i = 0; i < (1 << 8); ++i) trans [ i ] = ( 1 && ( ( * __ctype_b_loc ( ) ) [ ( int ) i ] & ( ( unsigned short ) _ISalnum ) || i == '_' ) ? state_letter : state ); for (i = 0; i < (1 << 8); ++i) trans [ i ] = ( - 1 ); for (i = 0; i < ngrps; ++i) follows . nelem = 0; possible_contexts = charclass_context ( labels [ i ] ); separate_contexts = state_separate_contexts ( ( & follows ) ); if ( ( separate_contexts & possible_contexts ) != possible_contexts ) state = state_index ( d , ( & follows ) , separate_contexts ^ 7 ); 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 ); | 153514/dfa.c | SARD | 0 |
int /* O - 1 on success, 0 on failure cupsd_client_t *con) /* I - Client connection */ ipp_tag_t group ; ipp_attribute_t * attr ; con -> response = ippNew ( ); con -> response -> request . status . version [ 0 ] = con -> request -> request . op . version [ 0 ]; con -> response -> request . status . version [ 1 ] = con -> request -> request . op . version [ 1 ]; con -> response -> request . status . request_id = con -> request -> request . op . request_id; if ( con -> request -> request . any . version [ 0 ] != 1 && con -> request -> request . any . version [ 0 ] != 2 ) if ( con -> request -> request . any . request_id < 1 ) if ( ! con -> request -> attrs ) for (attr = con->request->attrs, group = attr = attr->next) if ( attr -> group_tag < group && attr -> group_tag != IPP_TAG_ZERO ) group = attr -> group_tag; if ( ! attr ) attr = con -> request -> attrs; if ( attr ) attr = attr -> next; if ( attr && attr -> name && ! strcmp ( attr -> name , "attributes-natural-language" ) && ( attr -> value_tag & IPP_TAG_MASK ) == IPP_TAG_LANGUAGE ) if ( ! con -> language || strcmp ( attr -> values [ 0 ] . string . text , con -> language -> language ) ) | CVE-2015-1158/CVE_2015_1158_PATCHED_cupsdProcessIPPRequest.c | NVD | 0 |
static void goodG2B() twoIntsStruct * data ; data = NULL; twoIntsStruct * dataBuffer = ( twoIntsStruct * ) malloc ( 100 * sizeof ( twoIntsStruct ) ) ; size_t i ; for (i = 0; i < 100; i++) dataBuffer [ i ] . intOne = 1; dataBuffer [ i ] . intTwo = 1; data = dataBuffer; CWE590_Free_Memory_Not_on_Heap__free_struct_alloca_63b_goodG2BSink ( & data ); void CWE590_Free_Memory_Not_on_Heap__free_struct_alloca_63b_goodG2BSink(twoIntsStruct * * dataPtr) twoIntsStruct * data = * dataPtr ; free ( data ); | 108605/CWE590_Free_Memory_Not_on_Heap__free_struct_alloca_63b.c | SARD | 0 |
static void goodB2G() char * password ; char * & passwordRef = password ; char passwordBuffer [ 100 ] = "" ; password = passwordBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t passwordLen = strlen ( password ) ; 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 * ) ( password + passwordLen ) , ( 100 - passwordLen - 1 ) * sizeof ( char ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) password [ passwordLen + recvResult / sizeof ( char ) ] = '\0'; while ( 0 ) char * password = passwordRef ; HCRYPTPROV hCryptProv = 0 ; HCRYPTHASH hHash = 0 ; HCRYPTKEY hKey = 0 ; char hashData [ 100 ] = HASH_INPUT ; BYTE payload [ ( 100 - 1 ) * sizeof ( char ) ] ; DWORD payloadBytes ; payloadBytes = decodeHexChars ( payload , sizeof ( payload ) , password ); size_t decodeHexChars(unsigned char * bytes, size_t numBytes, const char * hex) size_t numWritten = 0 ; while ( numWritten < numBytes && isxdigit ( hex [ 2 * numWritten ] ) && isxdigit ( hex [ 2 * numWritten + 1 ] ) ) int byte ; bytes [ numWritten ] = ( unsigned char ) byte; return numWritten ; if ( ! CryptAcquireContext ( & hCryptProv , NULL , MS_ENH_RSA_AES_PROV , PROV_RSA_AES , 0 ) ) if ( ! CryptCreateHash ( hCryptProv , CALG_SHA_256 , 0 , 0 , & hHash ) ) if ( ! CryptHashData ( hHash , ( BYTE * ) hashData , strlen ( hashData ) , 0 ) ) if ( ! CryptDeriveKey ( hCryptProv , CALG_AES_256 , hHash , 0 , & hKey ) ) if ( ! CryptDecrypt ( hKey , 0 , 1 , 0 , payload , & payloadBytes ) ) memcpy ( password , payload , payloadBytes ); password [ payloadBytes / sizeof ( char ) ] = '\0'; while ( 0 ) if ( LogonUserA ( username , domain , password , LOGON32_LOGON_NETWORK , LOGON32_PROVIDER_DEFAULT , & pHandle ) != 0 ) | 94168/CWE319_Cleartext_Tx_Sensitive_Info__w32_char_listen_socket_33.cpp | SARD | 0 |
void CWE789_Uncontrolled_Mem_Alloc__malloc_char_fscanf_01_bad() size_t data ; data = 0; char * myString ; if ( data > strlen ( HELLO_STRING ) ) myString = ( char * ) malloc ( data * sizeof ( char ) ); strcpy ( myString , HELLO_STRING ); printLine ( myString ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( myString ); | 117079/CWE789_Uncontrolled_Mem_Alloc__malloc_char_fscanf_01.c | SARD | 10 |
void CWE78_OS_Command_Injection__char_file_popen_22_bad() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; data = CWE78_OS_Command_Injection__char_file_popen_22_badSource ( data ); char * CWE78_OS_Command_Injection__char_file_popen_22_badSource(char * data) if ( CWE78_OS_Command_Injection__char_file_popen_22_badGlobal ) size_t dataLen = strlen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0'; return data ; | 119498/CWE78_OS_Command_Injection__char_file_popen_22b.c | SARD | 0 |
StructType::ConstructData(JSContext* HandleObject const CallArgs& args) if ( ! CType :: IsCType ( obj ) || CType :: GetTypeCode ( obj ) != TYPE_struct ) if ( ! CType :: IsSizeDefined ( obj ) ) JSObject * result = CData :: Create ( cx , obj , NullPtr ( ) , nullptr , true ) ; if ( ! result ) if ( args . length ( ) == 0 ) char * buffer = static_cast < char * > CData :: GetData ( result ) if ( args . length ( ) == 1 ) if ( ExplicitConvert ( cx , args [ 0 ] , obj , buffer ) ) static ExplicitConvert(JSContext* cx, HandleValue val, HandleObject targetType, void* buffer) if ( ImplicitConvert ( cx , val , targetType , buffer , false , nullptr ) ) static ImplicitConvert(JSContext* HandleValue JSObject* void* bool bool* freePointer) RootedObject targetType ( cx , targetType_ ) ; JSObject * sourceData = nullptr ; JSObject * sourceType = nullptr ; RootedObject valObj ( cx , nullptr ) ; if ( val . isObject ( ) ) valObj = & val . toObject ( ); if ( CData :: IsCData ( valObj ) ) sourceData = valObj; sourceType = CData :: GetCType ( sourceData ); if ( CType :: TypesEqual ( sourceType , targetType ) ) if ( CDataFinalizer :: IsCDataFinalizer ( valObj ) ) sourceData = valObj; sourceType = CDataFinalizer :: GetCType ( cx , sourceData ); CDataFinalizer :: Private * p = ( CDataFinalizer :: Private * ) JS_GetPrivate ( sourceData ) ; if ( ! p ) if ( CType :: TypesEqual ( sourceType , targetType ) ) TypeCode targetCode = CType :: GetTypeCode ( targetType ) ; switch ( targetCode ) if ( val . isNull ( ) ) JS :: Rooted < JSObject * > baseType ( cx , PointerType :: GetBaseType ( targetType ) ) ; if ( sourceData ) TypeCode sourceCode = CType :: GetTypeCode ( sourceType ) ; bool voidptrTarget = CType :: GetTypeCode ( baseType ) == TYPE_void_t ; if ( sourceCode == TYPE_pointer && voidptrTarget ) if ( sourceCode == TYPE_array ) JSObject * elementType = ArrayType :: GetBaseType ( sourceType ) ; if ( voidptrTarget || CType :: TypesEqual ( baseType , elementType ) ) * static_cast < void * * > ( buffer ) = sourceBuffer if ( isArgument && val . isString ( ) ) if ( val . isObject ( ) && JS_IsArrayBufferObject ( valObj ) ) if ( val . isObject ( ) && JS_IsArrayBufferViewObject ( valObj ) ) if ( ! CanConvertTypedArrayItemTo ( baseType , valObj , cx ) ) if ( ! isArgument ) void * ptr ; JS :: AutoCheckCannotGC nogc ; ptr = JS_GetArrayBufferViewData ( valObj , nogc ); if ( ! ptr ) * static_cast < void * * > ( buffer ) = ptr RootedObject baseType ( cx , ArrayType :: GetBaseType ( targetType ) ) ; size_t targetLength = ArrayType :: GetLength ( targetType ) ; if ( val . isString ( ) ) if ( val . isObject ( ) && JS_IsArrayObject ( cx , valObj ) ) uint32_t sourceLength ; if ( ! JS_GetArrayLength ( cx , valObj , & sourceLength ) || targetLength != size_t ( sourceLength ) ) size_t elementSize = CType :: GetSize ( baseType ) ; auto intermediate = cx -> make_pod_array < char > ( arraySize ) if ( ! intermediate ) for (uint32_t i = 0; i < sourceLength; ++i) RootedValue item ( cx ) ; if ( ! JS_GetElement ( cx , valObj , i , & item ) ) char * data = intermediate . get ( ) + elementSize * i ; if ( ! ImplicitConvert ( cx , item , baseType , data , false , nullptr ) ) static ImplicitConvert(JSContext* HandleValue JSObject* void* bool bool* freePointer) RootedObject targetType ( cx , targetType_ ) ; RootedObject valObj ( cx , nullptr ) ; if ( val . isObject ( ) ) valObj = & val . toObject ( ); if ( CData :: IsCData ( valObj ) ) sourceData = valObj; sourceType = CData :: GetCType ( sourceData ); if ( CType :: TypesEqual ( sourceType , targetType ) ) size_t size = CType :: GetSize ( sourceType ) ; memmove ( buffer , CData :: GetData ( sourceData ) , size ); | CVE-2015-2726/Firefox_38.8.0esr_CVE_2015_2726_js_src_ctypes_CTypes.cpp | NVD | 0 |
static void goodG2B1() wchar_t * data ; wchar_t dataGoodBuffer [ 100 ] ; if ( globalFalse ) data = dataGoodBuffer; data [ 0 ] = L '\0' wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' memmove ( data , source , 100 * sizeof ( wchar_t ) ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) | 65361/CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_declare_memmove_10.c | SARD | 0 |
static void goodG2B() int data ; int * dataPtr2 = & data ; data = - 1; data = 100 - 1; int data = * dataPtr2 ; char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) memmove ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 87939/CWE195_Signed_to_Unsigned_Conversion_Error__fscanf_memmove_32.c | SARD | 0 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; size_t dataLen = strlen ( data ) ; char * environment = GETENV ( ENV_VARIABLE ) ; if ( environment != NULL ) strncat ( data + dataLen , environment , FILENAME_MAX - dataLen - 1 ); pFile = FOPEN ( data , "wb+" ); if ( pFile != NULL ) fclose ( pFile ); | 90077/CWE23_Relative_Path_Traversal__char_environment_fopen_18.cpp | SARD | 4 |
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 mbclen ; int maxlen = 0 ; size_t i ; int * match_lens = ( ( void * ) 0 ) ; size_t nelem = d -> states [ s ] . mbps . nelem ; position_set follows ; if ( nelem > 0 ) match_lens = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) transit_state_consume_1char ( d , s , pp , match_lens , & mbclen , & follows ); static status_transit_state transit_state_consume_1char(struct dfa *d,state_num s,const unsigned char **pp,int *match_lens,int *mbclen,position_set *pps) int k ; state_num s1 ; state_num s2 ; int * work_mbls ; * mbclen = ( mblen_buf [ * pp - buf_begin ] == 0 ? 1 : mblen_buf [ * pp - buf_begin ] ); s1 = s; for (k = 0; k < *mbclen; k++) s2 = s1; rs = transit_state_singlebyte ( d , s2 , ( * pp ) ++ , & s1 ); 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) int * rarray ; rarray = ( ( sizeof ( ( * rarray ) ) == 1 ? xmalloc ( d -> states [ s ] . mbps . nelem ) : xnmalloc ( d -> states [ s ] . mbps . nelem , sizeof ( ( * rarray ) ) ) ) ); while ( 0 ) 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 ); return rarray ; | 153172/dfa.c | SARD | 0 |
void CWE78_OS_Command_Injection__char_environment_w32_spawnlp_63_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 ); CWE78_OS_Command_Injection__char_environment_w32_spawnlp_63b_badSink ( & data ); void CWE78_OS_Command_Injection__char_environment_w32_spawnlp_63b_badSink(char * * dataPtr) char * data = * dataPtr ; | 119226/CWE78_OS_Command_Injection__char_environment_w32_spawnlp_63a.c | SARD | 0 |
static void goodG2B() size_t data ; size_t * dataPtr2 = & data ; data = 0; data = 20; size_t data = * dataPtr2 ; wchar_t * myString ; if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); free ( myString ); | 117340/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fscanf_32.c | SARD | 0 |
static void goodB2G1() size_t data ; data = 0; if ( STATIC_CONST_FIVE == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) if ( STATIC_CONST_FIVE != 5 ) char * myString ; if ( data > strlen ( HELLO_STRING ) && data < 100 ) myString = ( char * ) malloc ( data * sizeof ( char ) ); strcpy ( myString , HELLO_STRING ); free ( myString ); | 117132/CWE789_Uncontrolled_Mem_Alloc__malloc_char_listen_socket_06.c | SARD | 0 |
static void goodB2G1() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); | 109381/CWE606_Unchecked_Loop_Condition__wchar_t_listen_socket_22a.c | SARD | 0 |
void CWE78_OS_Command_Injection__char_console_popen_11_bad() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; if ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; size_t dataLen = strlen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) dataLen = strlen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == '\n' ) data [ dataLen - 1 ] = '\0'; data [ dataLen ] = '\0'; pipe = POPEN ( data , "wb" ); if ( pipe != NULL ) PCLOSE ( pipe ); | 118529/CWE78_OS_Command_Injection__char_console_popen_11.c | SARD | 15 |
static void badSink() int data = CWE195_Signed_to_Unsigned_Conversion_Error__negative_malloc_45_badData ; 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 ); | 88234/CWE195_Signed_to_Unsigned_Conversion_Error__negative_malloc_45.c | SARD | 20 |
static void goodG2B() wchar_t * data ; data = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ); wmemset ( data , L 'A' , 50 - 1 data [ 50 - 1 ] = L '\0' CWE122_Heap_Based_Buffer_Overflow__c_CWE806_wchar_t_ncpy_53b_goodG2BSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE806_wchar_t_ncpy_53b_goodG2BSink(wchar_t * data) CWE122_Heap_Based_Buffer_Overflow__c_CWE806_wchar_t_ncpy_53c_goodG2BSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE806_wchar_t_ncpy_53c_goodG2BSink(wchar_t * data) CWE122_Heap_Based_Buffer_Overflow__c_CWE806_wchar_t_ncpy_53d_goodG2BSink ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE806_wchar_t_ncpy_53d_goodG2BSink(wchar_t * data) wchar_t dest [ 50 ] = L "" wcsncpy ( dest , data , wcslen ( data ) ); | 72735/CWE122_Heap_Based_Buffer_Overflow__c_CWE806_wchar_t_ncpy_53d.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 ); 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 ); | 152026/dfa.c | SARD | 0 |
static int sctp_getsockopt(struct sock *sk, int level, int char __user *optval, int __user *optlen) int len ; if ( level != SOL_SCTP ) if ( get_user ( len , optlen ) ) if ( len < 0 ) switch ( optname ) retval = sctp_getsockopt_primary_addr ( sk , len , optval , optlen ); static int sctp_getsockopt_primary_addr(struct sock *sk, int char __user *optval, int __user *optlen) struct sctp_prim prim ; struct sctp_association * asoc ; if ( len < sizeof ( struct sctp_prim ) ) len = sizeof ( struct sctp_prim ); if ( copy_from_user ( & prim , optval , len ) ) asoc = sctp_id2assoc ( sk , prim . ssp_assoc_id ); struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id) struct sctp_association * asoc = NULL ; if ( ! sctp_style ( sk , UDP ) ) if ( ! sctp_sstate ( sk , ESTABLISHED ) && ! sctp_sstate ( sk , CLOSING ) ) return NULL ; return asoc ; if ( ! id || ( id == ( sctp_assoc_t ) - 1 ) ) return NULL ; asoc = ( struct sctp_association * ) idr_find ( & sctp_assocs_id , ( int ) id ); if ( ! asoc || ( asoc -> base . sk != sk ) || asoc -> base . dead ) return NULL ; return asoc ; if ( ! asoc ) if ( ! asoc -> peer . primary_path ) memcpy ( & prim . ssp_addr , & asoc -> peer . primary_path -> ipaddr , asoc -> peer . primary_path -> af_specific -> sockaddr_len ); sctp_get_pf_specific ( sk -> sk_family ) -> addr_to_user ( sp , ( union sctp_addr * ) & prim . ssp_addr ); if ( copy_to_user ( optval , & prim , len ) ) | CVE-2017-6353/linux_kernel_4.10.1_CVE_2017_6353_net_sctp_socket.c | NVD | 0 |
qcms_profile* qcms_profile_sRGB(void) qcms_profile * profile ; uint16_t * table ; qcms_CIE_xyYTRIPLE Rec709Primaries = { { 0.6400 , 0.3300 , 1.0 } , { 0.3000 , 0.6000 , 1.0 } , { 0.1500 , 0.0600 , 1.0 } } ; qcms_CIE_xyY D65 ; D65 = white_point_from_temp ( 6504 ); table = build_sRGB_gamma_table ( 1024 ); if ( ! table ) profile = qcms_profile_create_rgb_with_table ( D65 , Rec709Primaries , table , 1024 ); qcms_profile* qcms_CIE_xyY qcms_CIE_xyYTRIPLE uint16_t *table, int num_entries) qcms_profile * profile = qcms_profile_create ( ) ; if ( ! profile ) if ( ! set_rgb_colorants ( profile , white_point , primaries ) ) profile -> redTRC = curve_from_table ( table , num_entries ); profile -> blueTRC = curve_from_table ( table , num_entries ); profile -> greenTRC = curve_from_table ( table , num_entries ); if ( ! profile -> redTRC || ! profile -> blueTRC || ! profile -> greenTRC ) qcms_profile_release ( profile ); void qcms_profile_release(qcms_profile *profile) if ( profile -> mBA ) mAB_release ( profile -> mBA ); static void mAB_release(struct lutmABType *lut) uint8_t i ; for (i = 0; i < lut->num_in_channels; i++) for (i = 0; i < lut->num_out_channels; i++) free ( lut -> b_curves [ i ] ); | CVE-2015-0811/Firefox_36.0b9_CVE_2015_0811_gfx_qcms_iccread.c | NVD | 0 |
static void goodG2B() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; strcpy ( data , "C:\\Windows\\System32\\winsrv.dll" ); CWE114_Process_Control__w32_char_relativePath_41_goodG2BSink ( data ); void CWE114_Process_Control__w32_char_relativePath_41_goodG2BSink(char * data) HMODULE hModule ; hModule = LoadLibraryA ( data ); if ( hModule != NULL ) FreeLibrary ( hModule ); | 62204/CWE114_Process_Control__w32_char_relativePath_41.c | SARD | 0 |
static void goodG2B1() char * data ; if ( staticReturnsFalse ( ) ) static int staticReturnsFalse() return 0 ; data = ( char * ) malloc ( ( 10 + 1 ) * sizeof ( char ) ); memcpy ( data , source , ( strlen ( source ) + 1 ) * sizeof ( char ) ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data ); | 70839/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_char_memcpy_08.c | SARD | 0 |
static void goodG2B1() size_t data ; data = 0; if ( staticFalse ) data = 20; if ( staticTrue ) wchar_t * myString ; if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); printWLine ( myString ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( myString ); | 117227/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_connect_socket_05.c | SARD | 0 |
static void goodG2B1() int64_t * data ; data = NULL; if ( GLOBAL_CONST_FIVE != 5 ) data = new int64_t [ 100 ]; int64_t source [ 100 ] = { 0 } ; memmove ( data , source , 100 * sizeof ( int64_t ) ); printLongLongLine ( data [ 0 ] ); void printLongLongLine (int64_t longLongIntNumber) printf ( "%lld\n" , longLongIntNumber ); delete [ ] data | 68828/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_int64_t_memmove_13.cpp | SARD | 0 |
CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval* vp) CallArgs args = CallArgsFromVp ( argc , vp ) ; RootedObject objSelf ( cx , & args . callee ( ) ) ; RootedObject objProto ( cx ) ; if ( ! GetObjectProperty ( cx , objSelf , "prototype" , & objProto ) ) if ( args . length ( ) == 0 ) if ( args . length ( ) != 2 ) JS :: HandleValue valCodePtr = args [ 1 ] ; if ( ! valCodePtr . isObject ( ) ) JSObject * objCodePtr = & valCodePtr . toObject ( ) ; if ( ! CData :: IsCData ( objCodePtr ) ) RootedObject objCodePtrType ( cx , CData :: GetCType ( objCodePtr ) ) ; TypeCode typCodePtr = CType :: GetTypeCode ( objCodePtrType ) ; if ( typCodePtr != TYPE_pointer ) JSObject * objCodeType = PointerType :: GetBaseType ( objCodePtrType ) ; TypeCode typCode = CType :: GetTypeCode ( objCodeType ) ; if ( typCode != TYPE_function ) uintptr_t code = * reinterpret_cast < uintptr_t * > CData :: GetData ( objCodePtr ) if ( ! code ) FunctionInfo * funInfoFinalizer = FunctionType :: GetFunctionInfo ( objCodeType ) ; if ( ( funInfoFinalizer -> mArgTypes . length ( ) != 1 ) || ( funInfoFinalizer -> mIsVariadic ) ) RootedObject objArgType ( cx , funInfoFinalizer -> mArgTypes [ 0 ] ) ; size_t sizeArg ; RootedValue valData ( cx , args [ 0 ] ) ; if ( ! CType :: GetSafeSize ( objArgType , & sizeArg ) ) ScopedJSFreePtr < void > cargs ( malloc ( sizeArg ) ) ; if ( ! ImplicitConvert ( cx , valData , objArgType , cargs . get ( ) , false , & freePointer ) ) static ImplicitConvert(JSContext* HandleValue JSObject* void* bool bool* freePointer) RootedObject targetType ( cx , targetType_ ) ; JSObject * sourceData = nullptr ; JSObject * sourceType = nullptr ; RootedObject valObj ( cx , nullptr ) ; if ( val . isObject ( ) ) valObj = & val . toObject ( ); if ( CData :: IsCData ( valObj ) ) sourceData = valObj; sourceType = CData :: GetCType ( sourceData ); if ( CType :: TypesEqual ( sourceType , targetType ) ) if ( CDataFinalizer :: IsCDataFinalizer ( valObj ) ) sourceData = valObj; sourceType = CDataFinalizer :: GetCType ( cx , sourceData ); CDataFinalizer :: Private * p = ( CDataFinalizer :: Private * ) JS_GetPrivate ( sourceData ) ; if ( ! p ) if ( CType :: TypesEqual ( sourceType , targetType ) ) TypeCode targetCode = CType :: GetTypeCode ( targetType ) ; switch ( targetCode ) bool result ; if ( ! jsvalToBool ( cx , val , & result ) ) * static_cast < bool * > ( buffer ) = result type result ; type result ; type result ; if ( ! jsvalToFloat ( cx , val , & result ) ) * static_cast < type * > ( buffer ) = result if ( val . isNull ( ) ) * static_cast < void * * > ( buffer ) = nullptr JS :: Rooted < JSObject * > baseType ( cx , PointerType :: GetBaseType ( targetType ) ) ; if ( sourceData ) TypeCode sourceCode = CType :: GetTypeCode ( sourceType ) ; bool voidptrTarget = CType :: GetTypeCode ( baseType ) == TYPE_void_t ; if ( sourceCode == TYPE_pointer && voidptrTarget ) if ( sourceCode == TYPE_array ) JSObject * elementType = ArrayType :: GetBaseType ( sourceType ) ; if ( voidptrTarget || CType :: TypesEqual ( baseType , elementType ) ) * static_cast < void * * > ( buffer ) = sourceBuffer if ( isArgument && val . isString ( ) ) if ( val . isObject ( ) && JS_IsArrayBufferObject ( valObj ) ) if ( val . isObject ( ) && JS_IsArrayBufferViewObject ( valObj ) ) if ( ! CanConvertTypedArrayItemTo ( baseType , valObj , cx ) ) if ( ! isArgument ) void * ptr ; JS :: AutoCheckCannotGC nogc ; ptr = JS_GetArrayBufferViewData ( valObj , nogc ); if ( ! ptr ) * static_cast < void * * > ( buffer ) = ptr RootedObject baseType ( cx , ArrayType :: GetBaseType ( targetType ) ) ; size_t targetLength = ArrayType :: GetLength ( targetType ) ; if ( val . isString ( ) ) JSString * sourceString = val . toString ( ) ; JSLinearString * sourceLinear = sourceString -> ensureLinear ( cx ) ; if ( ! sourceLinear ) switch ( CType :: GetTypeCode ( baseType ) ) size_t nbytes = GetDeflatedUTF8StringLength ( cx , sourceLinear ) ; if ( nbytes == ( size_t ) - 1 ) if ( targetLength < nbytes ) char * charBuffer = static_cast < char * > buffer if ( val . isObject ( ) && ! sourceData ) AutoIdArray props ( cx , JS_Enumerate ( cx , valObj ) ) ; if ( ! props ) auto intermediate = cx -> make_pod_array < char > ( structSize ) if ( ! intermediate ) const FieldInfoHash * fields = StructType :: GetFieldInfo ( targetType ) ; if ( props . length ( ) != fields -> count ( ) ) RootedId id ( cx ) ; for (size_t i = 0; i < props.length(); ++i) id = props [ i ]; if ( ! JSID_IS_STRING ( id ) ) JSFlatString * name = JSID_TO_FLAT_STRING ( id ) ; const FieldInfo * field = StructType :: LookupField ( cx , targetType , name ) ; if ( ! field ) RootedValue prop ( cx ) ; if ( ! JS_GetPropertyById ( cx , valObj , id , & prop ) ) char * fieldData = intermediate . get ( ) + field -> mOffset ; if ( ! ImplicitConvert ( cx , prop , field -> mType , fieldData , false , nullptr ) ) static ImplicitConvert(JSContext* HandleValue JSObject* void* bool bool* freePointer) RootedObject targetType ( cx , targetType_ ) ; JSObject * sourceData = nullptr ; JSObject * sourceType = nullptr ; RootedObject valObj ( cx , nullptr ) ; if ( val . isObject ( ) ) valObj = & val . toObject ( ); if ( CData :: IsCData ( valObj ) ) sourceData = valObj; sourceType = CData :: GetCType ( sourceData ); if ( CType :: TypesEqual ( sourceType , targetType ) ) if ( CDataFinalizer :: IsCDataFinalizer ( valObj ) ) sourceData = valObj; sourceType = CDataFinalizer :: GetCType ( cx , sourceData ); CDataFinalizer :: Private * p = ( CDataFinalizer :: Private * ) JS_GetPrivate ( sourceData ) ; if ( ! p ) if ( CType :: TypesEqual ( sourceType , targetType ) ) TypeCode targetCode = CType :: GetTypeCode ( targetType ) ; switch ( targetCode ) if ( val . isNull ( ) ) JS :: Rooted < JSObject * > baseType ( cx , PointerType :: GetBaseType ( targetType ) ) ; if ( sourceData ) TypeCode sourceCode = CType :: GetTypeCode ( sourceType ) ; bool voidptrTarget = CType :: GetTypeCode ( baseType ) == TYPE_void_t ; if ( sourceCode == TYPE_pointer && voidptrTarget ) if ( sourceCode == TYPE_array ) JSObject * elementType = ArrayType :: GetBaseType ( sourceType ) ; if ( voidptrTarget || CType :: TypesEqual ( baseType , elementType ) ) * static_cast < void * * > ( buffer ) = sourceBuffer if ( isArgument && val . isString ( ) ) if ( val . isObject ( ) && JS_IsArrayBufferObject ( valObj ) ) if ( val . isObject ( ) && JS_IsArrayBufferViewObject ( valObj ) ) if ( ! CanConvertTypedArrayItemTo ( baseType , valObj , cx ) ) if ( ! isArgument ) void * ptr ; JS :: AutoCheckCannotGC nogc ; ptr = JS_GetArrayBufferViewData ( valObj , nogc ); if ( ! ptr ) * static_cast < void * * > ( buffer ) = ptr RootedObject baseType ( cx , ArrayType :: GetBaseType ( targetType ) ) ; size_t targetLength = ArrayType :: GetLength ( targetType ) ; if ( val . isString ( ) ) if ( val . isObject ( ) && JS_IsArrayObject ( cx , valObj ) ) uint32_t sourceLength ; if ( ! JS_GetArrayLength ( cx , valObj , & sourceLength ) || targetLength != size_t ( sourceLength ) ) size_t elementSize = CType :: GetSize ( baseType ) ; auto intermediate = cx -> make_pod_array < char > ( arraySize ) if ( ! intermediate ) for (uint32_t i = 0; i < sourceLength; ++i) RootedValue item ( cx ) ; if ( ! JS_GetElement ( cx , valObj , i , & item ) ) char * data = intermediate . get ( ) + elementSize * i ; if ( ! ImplicitConvert ( cx , item , baseType , data , false , nullptr ) ) static ImplicitConvert(JSContext* HandleValue JSObject* void* bool bool* freePointer) RootedObject targetType ( cx , targetType_ ) ; RootedObject valObj ( cx , nullptr ) ; if ( val . isObject ( ) ) valObj = & val . toObject ( ); if ( CData :: IsCData ( valObj ) ) sourceData = valObj; sourceType = CData :: GetCType ( sourceData ); if ( CType :: TypesEqual ( sourceType , targetType ) ) size_t size = CType :: GetSize ( sourceType ) ; memmove ( buffer , CData :: GetData ( sourceData ) , size ); | CVE-2015-2726/Firefox_38.8.0esr_CVE_2015_2726_js_src_ctypes_CTypes.cpp | NVD | 0 |
AVInputFormat *av_probe_input_format(AVProbeData *pd,int is_opened) return av_probe_input_format2 ( pd , is_opened , & score ) ; AVInputFormat *av_probe_input_format2(AVProbeData *pd,int is_opened,int *score_max) AVInputFormat * fmt = av_probe_input_format3 ( pd , is_opened , & score_ret ) ; AVInputFormat *av_probe_input_format3(AVProbeData *pd,int is_opened,int *score_ret) AVProbeData lpd = * pd ; AVInputFormat * fmt1 = ( ( void * ) 0 ) ; static const uint8_t zerobuffer [ 32 ] ; if ( ! lpd . buf ) lpd . buf = zerobuffer; if ( lpd . buf_size > '\n' && ff_id3v2_match ( lpd . buf , "ID3" ) ) int id3len = ff_id3v2_tag_len ( lpd . buf ) ; if ( lpd . buf_size > id3len + 16 ) lpd . buf += id3len; lpd . buf_size -= id3len; while ( fmt1 = av_iformat_next ( fmt1 ) ) if ( ! is_opened == ! ( fmt1 -> flags & 0x1 ) ) if ( fmt1 -> read_probe ) if ( fmt1 -> extensions && av_match_ext ( lpd . filename , fmt1 -> extensions ) ) int av_match_ext(const char *filename,const char *extensions) const char * ext ; if ( ! filename ) ext = ( strrchr ( filename , '.' ) ); if ( ext ) ext ++; if ( ! av_strcasecmp ( ext1 , ext ) ) | 153814/utils.c | SARD | 0 |
gboolean try_conversation_dissector(const address *addr_a,const address *addr_b,const port_type ptype,const guint32 port_a,const guint32 port_b,tvbuff_t *tvb,packet_info *pinfo,proto_tree *tree) conversation_t * conversation ; conversation = find_conversation ( pinfo -> fd -> num , addr_a , addr_b , ptype , port_a , port_b , 0 ); conversation_t *find_conversation(const guint32 frame_num,const address *addr_a,const address *addr_b,const port_type ptype,const guint32 port_a,const guint32 port_b,const guint options) conversation_t * conversation ; if ( ! ( options & ( 0x01 | 0x02 ) ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_exact , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_exact , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x02 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x01 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2 , frame_num , addr_b , addr_a , ptype , port_b , port_a ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x01 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_port2 , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation == ( ( void * ) 0 ) && ( addr_a -> type ) == AT_FC ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_port2 , frame_num , addr_b , addr_a , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ! ( options & 0x02 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_port2 , frame_num , addr_b , addr_a , ptype , port_b , port_a ); if ( conversation != ( ( void * ) 0 ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_no_addr2_or_port2 , frame_num , addr_a , addr_b , ptype , port_a , port_b ); if ( conversation != ( ( void * ) 0 ) ) if ( ptype != PT_UDP ) if ( ! ( conversation -> options & 0x08 ) ) conversation = conversation_create_from_template ( conversation , addr_b , port_b ); static conversation_t *conversation_create_from_template(conversation_t *conversation,const address *addr2,const guint32 port2) if ( conversation -> options & 0x08 && ( conversation -> key_ptr -> ptype ) != PT_UDP ) conversation_t * new_conversation_from_template ; guint options = conversation -> options & ( ~ ( 0x08 | 0x01 | 0x02 ) ) ; if ( conversation -> options & 0x01 && conversation -> options & 0x02 ) if ( conversation -> options & 0x02 ) new_conversation_from_template = conversation_new ( conversation -> setup_frame , ( & conversation -> key_ptr -> addr1 ) , ( & conversation -> key_ptr -> addr2 ) , conversation -> key_ptr -> ptype , conversation -> key_ptr -> port1 , port2 , options ); conversation_t *conversation_new(const guint32 setup_frame,const address *addr1,const address *addr2,const port_type ptype,const guint32 port1,const guint32 port2,const guint options) guint8 * SE_COPY_ADDRESS_data ; SE_COPY_ADDRESS_data = ( se_alloc ( ( addr1 -> len ) ) ); memcpy ( SE_COPY_ADDRESS_data , addr1 -> data , ( addr1 -> len ) ); guint8 * SE_COPY_ADDRESS_data ; SE_COPY_ADDRESS_data = ( se_alloc ( ( addr2 -> len ) ) ); memcpy ( SE_COPY_ADDRESS_data , addr2 -> data , ( addr2 -> len ) ); ( & new_key -> addr2 ) -> data = SE_COPY_ADDRESS_data; new_key -> ptype = ptype; new_key -> port1 = port1; new_key -> port2 = port2; conversation -> key_ptr = new_key; conversation_insert_into_hashtable ( hashtable , conversation ); return conversation ; | 149895/conversation.c | SARD | 0 |
static void goodG2B2() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); if ( globalTrue ) memset ( data , 'A' , 50 - 1 ); data [ 50 - 1 ] = '\0'; memmove ( dest , data , strlen ( data ) * sizeof ( char ) ); dest [ 50 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data ); | 72329/CWE122_Heap_Based_Buffer_Overflow__c_CWE806_char_memmove_10.c | SARD | 0 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; 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'; badSink ( data ); void badSink(char * data) hFile = CreateFileA ( data , ( GENERIC_WRITE | GENERIC_READ ) , 0 , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL ); if ( hFile != INVALID_HANDLE_VALUE ) CloseHandle ( hFile ); | 96479/CWE36_Absolute_Path_Traversal__char_file_w32CreateFile_51a.cpp | SARD | 0 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; size_t dataLen = strlen ( data ) ; if ( FILENAME_MAX - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( FILENAME_MAX - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0'; badSink ( & data ); void badSink(void * dataVoidPtr) char * * dataPtr = ( char * * ) dataVoidPtr ; char * data = ( * dataPtr ) ; pFile = FOPEN ( data , "wb+" ); if ( pFile != NULL ) fclose ( pFile ); | 90336/CWE23_Relative_Path_Traversal__char_file_fopen_64a.cpp | SARD | 0 |
void CWE124_Buffer_Underwrite__char_alloca_ncpy_18_bad() char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; strncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 73919/CWE124_Buffer_Underwrite__char_alloca_ncpy_18.c | SARD | 3 |
void CWE78_OS_Command_Injection__char_connect_socket_system_21_bad() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; data = badSource ( data ); static char * badSource(char * data) if ( badStatic ) 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 ) | 118105/CWE78_OS_Command_Injection__char_connect_socket_system_21.c | SARD | 0 |
void CWE680_Integer_Overflow_to_Buffer_Overflow__malloc_fgets_11_bad() int data ; data = - 1; if ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = atoi ( inputBuffer ); size_t i ; int * intPointer ; intPointer = ( int * ) malloc ( data * sizeof ( int ) ); for (i = 0; i < (size_t)data; i++) intPointer [ i ] = 0; free ( intPointer ); | 110370/CWE680_Integer_Overflow_to_Buffer_Overflow__malloc_fgets_11.c | SARD | 3 |
void CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_strncpy_12_bad() if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( data < 100 ) strncpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 88169/CWE195_Signed_to_Unsigned_Conversion_Error__listen_socket_strncpy_12.c | SARD | 20 |
void CWE605_Multiple_Binds_Same_Port__basic_15_bad() switch ( 6 ) char data [ 100 ] = "" ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; size_t dataLen = strlen ( data ) ; int bOptLen = sizeof ( BOOL ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) if ( setsockopt ( listenSocket , SOL_SOCKET , SO_REUSEADDR , ( char * ) & bOptVal , bOptLen ) != 0 ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , data + dataLen , ( int ) ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ recvResult ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; if ( replace ) * replace = '\0'; while ( 0 ) | 108926/CWE605_Multiple_Binds_Same_Port__basic_15.c | SARD | 39 |
void CWE127_Buffer_Underread__char_alloca_ncpy_05_bad() char * data ; char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; if ( staticTrue ) data = dataBuffer - 8; char dest [ 100 ] ; memset ( dest , 'C' , 100 - 1 ); dest [ 100 - 1 ] = '\0'; strncpy ( dest , data , strlen ( dest ) ); dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 77406/CWE127_Buffer_Underread__char_alloca_ncpy_05.c | SARD | 3 |
void CWE197_Numeric_Truncation_Error__int_connect_socket_to_short_44_bad() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); funcPtr ( data ); | 88683/CWE197_Numeric_Truncation_Error__int_connect_socket_to_short_44.c | 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[]) leaf_set * grps ; charclass * labels ; size_t ngrps = 0 ; position pos ; charclass matches ; int matchesf ; charclass intersect ; int intersectf ; charclass leftovers ; int leftoversf ; size_t i ; size_t j ; size_t k ; grps = ( ( sizeof ( ( * grps ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * grps ) ) ) ) ); while ( 0 ) labels = ( ( sizeof ( ( * labels ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * labels ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> states[s] . elems . nelem; ++i) pos = d -> states [ s ] . elems . elems [ i ]; if ( d -> tokens [ pos . index ] >= 0 && d -> tokens [ pos . index ] < ( 1 << 8 ) ) if ( d -> tokens [ pos . index ] >= CSET ) if ( pos . constraint != 0x777 ) if ( ! ( ( ( ( 4 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= ~newline [ j ]; if ( ! ( ( ( ( 2 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= ~letters [ j ]; if ( ! ( ( ( ( 1 & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) for (j = 0; j < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++j) matches [ j ] &= letters [ j ] | newline [ j ]; if ( j == ( ( 1 << 8 ) + 8 * sizeof ( int ) - 1 ) / ( 8 * sizeof ( int ) ) ) for (j = 0; j < ngrps; ++j) if ( d -> tokens [ pos . index ] >= 0 && d -> tokens [ pos . index ] < ( 1 << 8 ) && ! tstbit ( d -> tokens [ pos . index ] , labels [ j ] ) ) intersectf = 0; for (k = 0; k < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++k) ( intersect [ k ] = matches [ k ] & labels [ j ] [ k ] ) ? ( intersectf = 1 ) : 0; if ( ! intersectf ) leftoversf = matchesf = 0; for (k = 0; k < ((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int )); ++k) int match = matches [ k ] ; int label = labels [ j ] [ k ] ; ( leftovers [ k ] = ~match & label ) ? ( leftoversf = 1 ) : 0; ( matches [ k ] = match & ~label ) ? ( matchesf = 1 ) : 0; if ( leftoversf ) copyset ( leftovers , labels [ ngrps ] ); grps [ ngrps ] . elems = ( ( sizeof ( ( * grps [ ngrps ] . elems ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * grps [ ngrps ] . elems ) ) ) ) ); while ( 0 ) memcpy ( grps [ ngrps ] . elems , grps [ j ] . elems , sizeof ( grps [ j ] . elems [ 0 ] ) * grps [ j ] . nelem ); grps [ ngrps ] . nelem = grps [ j ] . nelem; grps [ j ] . elems [ grps [ j ] . nelem ++ ] = pos . index; if ( ! matchesf ) if ( j == ngrps ) grps [ ngrps ] . elems = ( ( sizeof ( ( * grps [ ngrps ] . elems ) ) == 1 ? xmalloc ( d -> nleaves ) : xnmalloc ( d -> nleaves , sizeof ( ( * grps [ ngrps ] . elems ) ) ) ) ); while ( 0 ) grps [ ngrps ] . nelem = 1; grps [ ngrps ] . elems [ 0 ] = pos . index; static void copyset(const int src[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))],charclass dst) memcpy ( dst , src , sizeof ( charclass ) ); | 153811/dfa.c | SARD | 0 |
void CWE197_Numeric_Truncation_Error__int_listen_socket_to_char_63_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 ); CWE197_Numeric_Truncation_Error__int_listen_socket_to_char_63b_badSink ( & data ); void CWE197_Numeric_Truncation_Error__int_listen_socket_to_char_63b_badSink(int * dataPtr) int data = * dataPtr ; char charData = ( char ) data ; printHexCharLine ( charData ); void printHexCharLine (char charHex) printf ( "%02x\n" , charHex ); | 89027/CWE197_Numeric_Truncation_Error__int_listen_socket_to_char_63a.c | SARD | 0 |
void CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_loop_06_bad() wchar_t * data ; data = NULL; if ( STATIC_CONST_FIVE == 5 ) data = ( wchar_t * ) malloc ( 10 * sizeof ( wchar_t ) ); wchar_t source [ 10 + 1 ] = SRC_STRING ; size_t i , sourceLen ; sourceLen = wcslen ( source ); for (i = 0; i < sourceLen + 1; i++) data [ i ] = source [ i ]; free ( data ); | 71029/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_loop_06.c | SARD | 3 |
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; size_t dataLen = strlen ( data ) ; recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; badSink_b ( data ); void badSink_b(char * data) badSink_c ( data ); void badSink_c(char * data) hFile = CreateFileA ( data , ( GENERIC_WRITE | GENERIC_READ ) , 0 , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL ); if ( hFile != INVALID_HANDLE_VALUE ) CloseHandle ( hFile ); | 96720/CWE36_Absolute_Path_Traversal__char_listen_socket_w32CreateFile_52a.cpp | SARD | 0 |
void bad() char * dataBuffer = new char [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; dataMap [ 0 ] = data; dataMap [ 1 ] = data; dataMap [ 2 ] = data; badSink ( dataMap ); void badSink(map<int, char *> dataMap) char * data = dataMap [ 2 ] ; strncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); | 74953/CWE124_Buffer_Underwrite__new_char_ncpy_74a.cpp | SARD | 0 |
void CWE369_Divide_by_Zero__float_listenSocket_05_bad() if ( staticTrue ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = ( float ) atof ( inputBuffer ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); int result = ( int ) ( 100.0 / data ) ; printIntLine ( result ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); | 94822/CWE369_Divide_by_Zero__float_listenSocket_05.c | SARD | 25 |
void *stonesoup_print_data (void *data) struct stonesoup_data * ssD = ( struct stonesoup_data * ) data ; struct stonesoup_queue * ssQ = get_instance ( ssD -> file2 ) ; struct stonesoup_queue *get_instance (char* file2) static struct stonesoup_queue * ssQ = NULL ; if ( ssQ == NULL ) if ( file2 != NULL ) stonesoup_readFile ( file2 ); void stonesoup_readFile(char *filename) FILE * fifo ; char ch ; fifo = fopen ( filename , "r" ); if ( fifo != NULL ) while ( ( ch = fgetc ( fifo ) ) != EOF ) stonesoup_printf ( "%c" , ch ); | 149955/eng_lib.c | SARD | 0 |
static state_num transit_state(struct dfa *d,state_num s,const unsigned char **pp) int mbclen ; int maxlen = 0 ; size_t i ; int * match_lens = ( ( void * ) 0 ) ; size_t nelem = d -> states [ s ] . mbps . nelem ; position_set follows ; if ( nelem > 0 ) match_lens = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) transit_state_consume_1char ( d , s , pp , match_lens , & mbclen , & follows ); static status_transit_state transit_state_consume_1char(struct dfa *d,state_num s,const unsigned char **pp,int *match_lens,int *mbclen,position_set *pps) int k ; state_num s1 ; state_num s2 ; int * work_mbls ; * mbclen = ( mblen_buf [ * pp - buf_begin ] == 0 ? 1 : mblen_buf [ * pp - buf_begin ] ); s1 = s; for (k = 0; k < *mbclen; k++) s2 = s1; rs = transit_state_singlebyte ( d , s2 , ( * pp ) ++ , & s1 ); static status_transit_state transit_state_singlebyte(struct dfa *d,state_num s,const unsigned char *p,state_num *next_state) state_num * t ; state_num works = s ; status_transit_state rval = TRANSIT_STATE_IN_PROGRESS ; while ( rval == TRANSIT_STATE_IN_PROGRESS ) if ( ( t = d -> trans [ works ] ) != ( ( void * ) 0 ) ) works = t [ * p ]; rval = TRANSIT_STATE_DONE; if ( works < 0 ) works = 0; if ( works < 0 ) works = 0; if ( d -> fails [ works ] ) works = d -> fails [ works ] [ * p ]; rval = TRANSIT_STATE_DONE; return rval ; if ( match_lens == ( ( void * ) 0 ) && d -> states [ s ] . mbps . nelem != 0 ) work_mbls = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); static int *check_matching_with_multibyte_ops(struct dfa *d,state_num s,size_t idx) size_t i ; int * rarray ; rarray = ( ( sizeof ( ( * rarray ) ) == 1 ? xmalloc ( d -> states [ s ] . mbps . nelem ) : xnmalloc ( d -> states [ s ] . mbps . nelem , sizeof ( ( * rarray ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> states[s] . mbps . nelem; ++i) position pos = d -> states [ s ] . mbps . elems [ i ] ; switch ( d -> tokens [ pos . index ] ) rarray [ i ] = match_anychar ( d , s , pos , idx ); rarray [ i ] = match_mb_charset ( d , s , pos , idx ); static int match_mb_charset(struct dfa *d,state_num s,position pos,size_t idx) size_t i ; int match_len ; int op_len ; char buffer [ 128 ] ; struct mb_char_classes * work_mbc ; int context ; wchar_t wc ; wc = inputwcs [ idx ]; if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) context = wchar_context ( wc ); if ( ! ( ( ( ( context & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( context & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( context & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) work_mbc = & d -> mbcsets [ d -> multibyte_prop [ pos . index ] >> 2 ]; match_len = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc < 1 << 8 && work_mbc -> cset != ( - 1 ) && tstbit ( ( ( unsigned char ) wc ) , d -> charclasses [ work_mbc -> cset ] ) ) for (i = 0; i < work_mbc -> nch_classes; i++) if ( iswctype ( ( ( wint_t ) wc ) , work_mbc -> ch_classes [ i ] ) ) strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , match_len ); buffer [ match_len ] = '\0'; for (i = 0; i < work_mbc -> nequivs; i++) op_len = ( strlen ( work_mbc -> equivs [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> equivs [ i ] , buffer ) == 0 ) match_len = op_len; strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> coll_elems [ i ] , buffer ) == 0 ) return match ? match_len : 0 ; | 152959/dfa.c | SARD | 0 |
static void goodG2B() wchar_t * data ; data = NULL; data = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ); data [ 0 ] = L CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cpy_82_base * baseObject = new CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cpy_82_goodG2B baseObject -> action ( data ); void CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cpy_82_goodG2B::action(wchar_t * data) wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcscpy ( data , source ); free ( data ); | 72989/CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cpy_82_goodG2B.cpp | SARD | 0 |
static void goodB2G() size_t data ; data = 0; data = rand ( ); CWE789_Uncontrolled_Mem_Alloc__malloc_char_rand_52b_goodB2GSink ( data ); void CWE789_Uncontrolled_Mem_Alloc__malloc_char_rand_52b_goodB2GSink(size_t data) CWE789_Uncontrolled_Mem_Alloc__malloc_char_rand_52c_goodB2GSink ( data ); void CWE789_Uncontrolled_Mem_Alloc__malloc_char_rand_52c_goodB2GSink(size_t data) char * myString ; if ( data > strlen ( HELLO_STRING ) && data < 100 ) myString = ( char * ) malloc ( data * sizeof ( char ) ); strcpy ( myString , HELLO_STRING ); printLine ( myString ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( myString ); | 117205/CWE789_Uncontrolled_Mem_Alloc__malloc_char_rand_52c.c | SARD | 0 |
static void goodG2B() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; strcat ( data , "file.txt" ); hFile = CreateFileA ( data , ( GENERIC_WRITE | GENERIC_READ ) , 0 , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL ); if ( hFile != INVALID_HANDLE_VALUE ) CloseHandle ( hFile ); | 90503/CWE23_Relative_Path_Traversal__char_file_w32CreateFile_12.cpp | SARD | 0 |
size_t CWE789_Uncontrolled_Mem_Alloc__malloc_char_listen_socket_61b_badSource(size_t data) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); return data ; | 117160/CWE789_Uncontrolled_Mem_Alloc__malloc_char_listen_socket_61b.c | SARD | 0 |
void bad() wchar_t * data ; data = NULL; while ( 1 ) data = new wchar_t [ 10 ]; wchar_t source [ 10 + 1 ] = SRC_STRING ; memmove ( 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 | 68207/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_wchar_t_memmove_16.cpp | SARD | 3 |
void CWE134_Uncontrolled_Format_String__char_file_vfprintf_42_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; data = badSource ( data ); static char * badSource(char * data) size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0'; fclose ( pFile ); return data ; | 80131/CWE134_Uncontrolled_Format_String__char_file_vfprintf_42.c | SARD | 0 |
svn_error_t *svn_dirent_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 ) svn_error_t * svn_err__temp = svn_dirent_get_absolute ( pcommon , ( ( const char * * ) ( targets -> elts ) ) [ 0 ] , scratch_pool ) ; if ( svn_err__temp ) while ( 0 ) if ( targets -> nelts == 1 ) for (i = 1; i < targets -> nelts; ++i) const char * rel = ( ( const char * * ) ( targets -> elts ) ) [ i ] ; svn_error_t * svn_err__temp = svn_dirent_get_absolute ( & absolute , rel , scratch_pool ) ; if ( svn_err__temp ) while ( 0 ) svn_error_t *svn_dirent_get_absolute(const char **pabsolute,const char *relative,apr_pool_t *pool) char * buffer ; apr_status_t apr_err ; const char * path_apr ; if ( ! ( ! svn_path_is_url ( relative ) ) ) svn_error_t * svn_err__temp = svn_error__malfunction ( ! 0 , "dirent_uri.c" , 1571 , "! svn_path_is_url(relative)" ) ; if ( svn_err__temp ) while ( 0 ) while ( 0 ) svn_error_t * svn_err__temp = svn_path_cstring_from_utf8 ( & path_apr , relative , pool ) ; if ( svn_err__temp ) while ( 0 ) apr_err = apr_filepath_merge ( & buffer , ( ( void * ) 0 ) , path_apr , 0x04 , pool ); if ( apr_err ) svn_error_t * svn_err__temp = svn_path_cstring_to_utf8 ( pabsolute , buffer , pool ) ; if ( svn_err__temp ) while ( 0 ) * pabsolute = svn_dirent_canonicalize ( * pabsolute , pool ); const char *svn_dirent_canonicalize(const char *dirent,apr_pool_t *pool) const char * dst = canonicalize ( type_dirent , dirent , 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 ; svn_boolean_t url = 0 ; if ( path [ 0 ] == '\0' ) 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 ++ ) ); * ( dst ++ ) = ':'; * ( dst ++ ) = 47; * ( dst ++ ) = 47; src += 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 ++ ) ); if ( ( * src ) == ']' ) * ( dst ++ ) = * ( src ++ ); while ( * src && ( * src ) != 47 && ( * src ) != ':' ) * ( dst ++ ) = canonicalize_to_lower ( * ( src ++ ) ); 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 ++ ) ); * dst = * src; if ( * src ) src ++; dst ++; 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' ) memcpy ( dst , src , seglen ); dst += seglen; if ( slash_len ) * ( dst ++ ) = 47; src = next + slash_len; if ( canon_segments > 0 && ( * ( dst - 1 ) ) == 47 && ! ( url && path [ schemelen ] == '\0' ) ) dst --; * dst = '\0'; memcpy ( dst , canon , pre_schema_size ); canon = dst; dst += pre_schema_size; * ( dst ++ ) = 47; * ( dst ++ ) = 37; * ( dst ++ ) = 50; * ( dst ++ ) = '5'; * ( dst ++ ) = ( ( char ) val ); * ( dst ++ ) = 37; * ( dst ++ ) = canonicalize_to_upper ( digitz [ 0 ] ); * ( dst ++ ) = canonicalize_to_upper ( digitz [ 1 ] ); apr_snprintf ( dst , 4 , "%%%02X" , ( ( unsigned char ) ( * src ) ) ); dst += 3; * ( dst ++ ) = * src; * dst = '\0'; return canon ; | 150882/dirent_uri.c | SARD | 0 |
static void good1() if ( 0 ) twoIntsStruct * data ; data = ( twoIntsStruct * ) malloc ( sizeof ( twoIntsStruct ) ); data -> intOne = 5; data -> intTwo = 6; * pointer = data; twoIntsStruct * data = * pointer ; printIntLine ( data -> intOne ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); printIntLine ( data -> intTwo ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); | 112408/CWE758_Undefined_Behavior__struct_pointer_alloca_use_02.c | SARD | 35 |
void bad() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); badSink ( & data ); void badSink(void * dataVoidPtr) int * dataPtr = ( int * ) dataVoidPtr ; int data = ( * dataPtr ) ; dataBytes = data * sizeof ( int ); intPointer = ( int * ) new char [ dataBytes ]; for (i = 0; i < (size_t)data; i++) intPointer [ i ] = 0; printIntLine ( intPointer [ 0 ] ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); delete [ ] intPointer | 110828/CWE680_Integer_Overflow_to_Buffer_Overflow__new_listen_socket_64a.cpp | SARD | 0 |
static void goodG2B() twoIntsStruct * data ; twoIntsStruct dataGoodBuffer [ 100 ] ; data = dataGoodBuffer; twoIntsStruct * dataCopy = data ; twoIntsStruct * data = dataCopy ; twoIntsStruct source [ 100 ] ; size_t i ; for (i = 0; i < 100; i++) source [ i ] . intOne = 0; source [ i ] . intOne = 0; memmove ( data , source , 100 * sizeof ( twoIntsStruct ) ); printStructLine ( & data [ 0 ] ); void printStructLine (const twoIntsStruct * structTwoIntsStruct) printf ( "%d -- %d\n" , structTwoIntsStruct -> intOne , structTwoIntsStruct -> intTwo ); | 65010/CWE121_Stack_Based_Buffer_Overflow__CWE805_struct_declare_memmove_31.c | SARD | 0 |
static void goodB2G2() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; size_t dataLen = strlen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) dataLen = strlen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == '\n' ) data [ dataLen - 1 ] = '\0'; if ( data [ i ] == SEARCH_CHAR ) | 112581/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_console_15.c | SARD | 0 |
void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_connect_socket_15_bad() size_t data ; data = 0; switch ( 6 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) switch ( 7 ) wchar_t * myString ; if ( data > wcslen ( HELLO_STRING ) ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); printWLine ( myString ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( myString ); | 117237/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_connect_socket_15.c | SARD | 10 |
void bad() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = strtoul ( inputBuffer , NULL , 0 ); while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); badSink ( & data ); void badSink(void * dataVoidPtr) size_t * dataPtr = ( size_t * ) dataVoidPtr ; size_t data = ( * dataPtr ) ; if ( data > strlen ( HELLO_STRING ) ) myString = new char [ data ]; strcpy ( myString , HELLO_STRING ); printLine ( myString ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); delete [ ] myString | 117643/CWE789_Uncontrolled_Mem_Alloc__new_char_listen_socket_64a.cpp | SARD | 0 |
static void goodB2G1() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; strcpy ( data , BAD_SOURCE_FIXED_STRING ); if ( globalReturnsFalse ( ) ) int globalReturnsFalse() return 0 ; size_t i ; for (i=0; i < strlen(data); i++) if ( data [ i ] == SEARCH_CHAR ) | 112721/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_fixed_string_11.c | SARD | 0 |
static void goodG2B1() 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 ( staticReturnsFalse ( ) ) static int staticReturnsFalse() return 0 ; 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 ) | 75285/CWE124_Buffer_Underwrite__wchar_t_alloca_memcpy_08.c | SARD | 0 |
static void goodG2B2() wchar_t * data ; data = new wchar_t [ 100 ]; data = goodG2B2Source ( data ); wchar_t * goodG2B2Source(wchar_t * data) if ( goodG2B2Global ) wmemset ( data , L 'A' , 50 - 1 data [ 50 - 1 ] = L '\0' return data ; size_t i , dataLen ; dataLen = wcslen ( data ); for (i = 0; i < dataLen; i++) | 69603/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_loop_22a.cpp | SARD | 0 |
static void goodG2B() char * data ; map < int , char * > dataMap ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; strcpy ( data , "C:\\Windows\\System32\\winsrv.dll" ); dataMap [ 0 ] = data; dataMap [ 1 ] = data; dataMap [ 2 ] = data; goodG2BSink ( dataMap ); void goodG2BSink(map<int, char *> dataMap) char * data = dataMap [ 2 ] ; HMODULE hModule ; hModule = LoadLibraryA ( data ); if ( hModule != NULL ) FreeLibrary ( hModule ); | 61983/CWE114_Process_Control__w32_char_connect_socket_74b.cpp | SARD | 0 |
void CWE194_Unexpected_Sign_Extension__connect_socket_memmove_64b_badSink(void * dataVoidPtr) 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 ); | 86418/CWE194_Unexpected_Sign_Extension__connect_socket_memmove_64b.c | SARD | 20 |
static void goodB2G1() int data ; data = - 1; if ( globalTrue ) 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 ( globalFalse ) int i ; int * buffer = ( int * ) malloc ( 10 * sizeof ( int ) ) ; for (i = 0; i < 10; i++) buffer [ i ] = 0; if ( data >= 0 && data < ( 10 ) ) buffer [ data ] = 1; free ( buffer ); | 70649/CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_10.c | SARD | 0 |
void dfacomp(const char *s,size_t len,struct dfa *d,int searchflag) dfamust ( d ); static void dfamust(struct dfa *d) must * musts ; must * mp ; size_t ri ; size_t i ; token t ; static must must0 ; musts = ( ( sizeof ( ( * musts ) ) == 1 ? xmalloc ( d -> tindex + 1 ) : xnmalloc ( d -> tindex + 1 , sizeof ( ( * musts ) ) ) ) ); while ( 0 ) mp = musts; for (i = 0; i <= d -> tindex; ++i) mp [ i ] = must0; for (i = 0; i <= d -> tindex; ++i) mp [ i ] . in = ( xmalloc ( sizeof ( ( * mp [ i ] . in ) ) ) ); mp [ i ] . left = ( xmalloc ( 2 ) ); mp [ i ] . right = ( xmalloc ( 2 ) ); mp [ i ] . is = ( xmalloc ( 2 ) ); mp [ i ] . left [ 0 ] = mp [ i ] . right [ 0 ] = mp [ i ] . is [ 0 ] = '\0'; mp [ i ] . in [ 0 ] = ( ( void * ) 0 ); for (ri = 0; ri < d -> tindex; ++ri) switch ( t = d -> tokens [ ri ] ) resetmust ( mp ); must * lmp ; must * rmp ; mp -> is [ 0 ] = '\0'; must * lmp ; must * rmp ; rmp = -- mp; lmp = -- mp; lmp -> in = addlists ( lmp -> in , rmp -> in ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> right [ 0 ] != '\0' && rmp -> left [ 0 ] != '\0' ) char * tp ; tp = icpyalloc ( ( lmp -> right ) ); tp = icatalloc ( tp , ( rmp -> left ) ); lmp -> in = enlist ( lmp -> in , tp , strlen ( tp ) ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' ) lmp -> left = icatalloc ( lmp -> left , ( rmp -> left ) ); if ( lmp -> left == ( ( void * ) 0 ) ) if ( rmp -> is [ 0 ] == '\0' ) lmp -> right [ 0 ] = '\0'; lmp -> right = icatalloc ( lmp -> right , ( rmp -> right ) ); if ( lmp -> right == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' && rmp -> is [ 0 ] != '\0' ) lmp -> is = icatalloc ( lmp -> is , ( rmp -> is ) ); if ( lmp -> is == ( ( void * ) 0 ) ) lmp -> is [ 0 ] = '\0'; if ( t < END ) if ( t == '\0' ) if ( t >= CSET || ! 1 || t == ANYCHAR || t == MBCSET ) mp -> is [ 0 ] = mp -> left [ 0 ] = mp -> right [ 0 ] = t; mp -> is [ 1 ] = mp -> left [ 1 ] = mp -> right [ 1 ] = '\0'; mp -> in = enlist ( mp -> in , mp -> is , ( ( size_t ) 1 ) ); if ( mp -> in == ( ( void * ) 0 ) ) static void resetmust(must *mp) mp -> left [ 0 ] = mp -> right [ 0 ] = mp -> is [ 0 ] = '\0'; freelist ( mp -> in ); static void freelist(char **cpp) size_t i ; if ( cpp == ( ( void * ) 0 ) ) for (i = 0; cpp[i] != ((void *)0); ++i) free ( cpp [ i ] ); cpp [ i ] = ( ( void * ) 0 ); | 153577/dfa.c | SARD | 0 |
static void good1() if ( globalFalse ) WSADATA wsaData ; struct sockaddr_in service ; char username [ USERNAME_SZ + 1 ] ; if ( 0 != WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) ) listenSocket = socket ( PF_INET , SOCK_STREAM , 0 ); 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 ( LISTEN_PORT ); if ( SOCKET_ERROR == bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) ) if ( SOCKET_ERROR == listen ( listenSocket , LISTEN_BACKLOG ) ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == INVALID_SOCKET ) if ( sizeof ( username ) - sizeof ( char ) != recv ( acceptSocket , username , sizeof ( username ) - sizeof ( char ) , 0 ) ) while ( 0 ) if ( acceptSocket != INVALID_SOCKET ) closesocket ( acceptSocket ); if ( listenSocket != INVALID_SOCKET ) closesocket ( listenSocket ); | 89499/CWE223_Omission_of_Security_Relevant_Information__w32_10.c | SARD | 0 |