func
stringlengths
181
23.6k
path
stringlengths
12
123
source
stringclasses
2 values
label
int64
0
40
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_ ) ; 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 ) 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_ ) ; 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 ) 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 ) size_t structSize = CType :: GetSize ( targetType ) ; auto intermediate = cx -> make_pod_array < char > ( structSize ) if ( ! intermediate ) const FieldInfoHash * fields = StructType :: GetFieldInfo ( targetType ) ; if ( props . length ( ) != fields -> count ( ) ) RootedId id ( cx ) ; 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 ) ) memcpy ( buffer , intermediate . get ( ) , structSize );
CVE-2015-2726/Firefox_38.8.0esr_CVE_2015_2726_js_src_ctypes_CTypes.cpp
NVD
0
void CWE325_Missing_Required_Cryptographic_Step__w32_CryptEncrypt_02_bad() if ( 1 ) BYTE payload [ 100 ] ; DWORD payloadLen = strlen ( PAYLOAD ) ; HCRYPTPROV hCryptProv = ( HCRYPTPROV ) NULL ; HCRYPTHASH hHash = ( HCRYPTHASH ) NULL ; char hashData [ 100 ] = HASH_INPUT ; memcpy ( payload , PAYLOAD , payloadLen ); 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 ) ) while ( 0 )
94423/CWE325_Missing_Required_Cryptographic_Step__w32_CryptEncrypt_02.c
SARD
0
static void goodB2G1() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; if ( GLOBAL_CONST_TRUE ) size_t dataLen = wcslen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgetws ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) dataLen = wcslen ( data ); if ( dataLen > 0 && data [ dataLen - 1 ] == L '\n' )
109226/CWE606_Unchecked_Loop_Condition__wchar_t_console_09.c
SARD
0
static void goodG2B() TwoIntsClass * data ; data = NULL; data = new TwoIntsClass [ 100 ]; CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_class_memcpy_82_base * baseObject = new CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_class_memcpy_82_goodG2B baseObject -> action ( data ); void CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_class_memcpy_82_goodG2B::action(TwoIntsClass * data) TwoIntsClass source [ 100 ] ; size_t i ; for (i = 0; i < 100; i++) source [ i ] . intOne = 0; source [ i ] . intTwo = 0; memcpy ( data , source , 100 * sizeof ( TwoIntsClass ) ); printIntLine ( data [ 0 ] . intOne ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber ); delete [ ] data
68669/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_class_memcpy_82_goodG2B.cpp
SARD
0
static void goodG2B2() wchar_t * data ; data = NULL; data = CWE124_Buffer_Underwrite__malloc_wchar_t_memmove_22_goodG2B2Source ( data ); wchar_t * CWE124_Buffer_Underwrite__malloc_wchar_t_memmove_22_goodG2B2Source(wchar_t * data) if ( CWE124_Buffer_Underwrite__malloc_wchar_t_memmove_22_goodG2B2Global ) wchar_t * dataBuffer = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' data = dataBuffer; return data ; 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 )
74641/CWE124_Buffer_Underwrite__malloc_wchar_t_memmove_22a.c
SARD
0
static void goodB2G2() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; switch ( 6 ) size_t dataLen = strlen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgets ( data + dataLen , ( int ) ( 100 - dataLen ) , pFile ) == NULL ) data [ dataLen ] = '\0'; goodB2G2VaSinkG ( data , data ); static void goodB2G2VaSinkG(char * data, ...) va_start ( args , data );
80168/CWE134_Uncontrolled_Format_String__char_file_vprintf_15.c
SARD
0
void CWE123_Write_What_Where_Condition__connect_socket_12_bad() badStruct data ; linkedList head = { & head , & head } ; data . list . next = head . next; data . list . prev = head . prev; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; 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 , sizeof ( data ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket );
73417/CWE123_Write_What_Where_Condition__connect_socket_12.c
SARD
0
static void goodG2B() wchar_t * data ; data = new wchar_t [ 100 ]; wmemset ( data , L 'A' , 50 - 1 data [ 50 - 1 ] = L CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_82_base * baseObject = new CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_82_goodG2B baseObject -> action ( data ); void CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_82_goodG2B::action(wchar_t * data) wchar_t dest [ 50 ] = L "" memcpy ( dest , data , wcslen ( data ) * sizeof ( wchar_t ) );
69677/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_82_goodG2B.cpp
SARD
0
void CWE590_Free_Memory_Not_on_Heap__free_struct_static_16_bad() twoIntsStruct * data ; data = NULL; while ( 1 ) static twoIntsStruct dataBuffer [ 100 ] ; size_t i ; for (i = 0; i < 100; i++) dataBuffer [ i ] . intOne = 1; dataBuffer [ i ] . intTwo = 1; data = dataBuffer; free ( data );
108671/CWE590_Free_Memory_Not_on_Heap__free_struct_static_16.c
SARD
1
void wrong_arguments_func_pointer_015 () int i ; wrong_arguments_func_pointer_015_dst1_gbl = ( char * * ) malloc ( 5 * sizeof ( char * ) ); for(i=0;i<5;i++) wrong_arguments_func_pointer_015_dst1_gbl [ i ] = ( char * ) malloc ( 15 * sizeof ( char ) ); fptr ( wrong_arguments_func_pointer_015_dst1_gbl , str2 ); for(i=0;i<5;i++) free ( wrong_arguments_func_pointer_015_dst1_gbl [ i ] ); wrong_arguments_func_pointer_015_dst1_gbl [ i ] = NULL; free ( wrong_arguments_func_pointer_015_dst1_gbl );
199328/wrong_arguments_func_pointer.c
SARD
2
void CWE369_Divide_by_Zero__int_connect_socket_modulo_06_bad() if ( STATIC_CONST_FIVE == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) printIntLine ( 100 % data ); void printIntLine (int intNumber) printf ( "%d\n" , intNumber );
95015/CWE369_Divide_by_Zero__int_connect_socket_modulo_06.c
SARD
25
void bad() twoIntsStruct * data ; data = NULL; data = ( twoIntsStruct * ) realloc ( data , 100 * sizeof ( twoIntsStruct ) ); data [ 0 ] . intOne = 0; data [ 0 ] . intTwo = 0; printStructLine ( & data [ 0 ] ); void printStructLine (const twoIntsStruct * structTwoIntsStruct) printf ( "%d -- %d\n" , structTwoIntsStruct -> intOne , structTwoIntsStruct -> intTwo ); dataMap [ 0 ] = data; dataMap [ 1 ] = data; dataMap [ 2 ] = data; badSink ( dataMap ); void badSink(map<int, twoIntsStruct *> dataMap) twoIntsStruct * data = dataMap [ 2 ] ;
100709/CWE401_Memory_Leak__twoIntsStruct_realloc_74a.cpp
SARD
0
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; if ( globalTrue ) 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 ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 )
95739/CWE36_Absolute_Path_Traversal__char_connect_socket_w32CreateFile_10.cpp
SARD
0
static void good1() if ( staticFalse ) 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 );
89494/CWE223_Omission_of_Security_Relevant_Information__w32_05.c
SARD
0
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 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'; if ( replace ) * replace = '\0'; while ( 0 )
96712/CWE36_Absolute_Path_Traversal__char_listen_socket_w32CreateFile_33.cpp
SARD
0
static void goodG2B() wchar_t * data ; wchar_t * & dataRef = data ; wchar_t dataBuffer [ 100 ] ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' data = dataBuffer; wchar_t * data = dataRef ; 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 )
75538/CWE124_Buffer_Underwrite__wchar_t_declare_memmove_33.cpp
SARD
0
void CWE78_OS_Command_Injection__wchar_t_connect_socket_w32_spawnv_03_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; if ( 5 == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
120681/CWE78_OS_Command_Injection__wchar_t_connect_socket_w32_spawnv_03.c
SARD
0
void CWE114_Process_Control__w32_char_file_15_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; switch ( 6 ) 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'; HMODULE hModule ; hModule = LoadLibraryA ( data ); if ( hModule != NULL ) FreeLibrary ( hModule );
62098/CWE114_Process_Control__w32_char_file_15.c
SARD
14
static int transcode() int ret ; ret = transcode_init ( ); static int transcode_init() int ret = 0 ; int i ; int j ; AVFormatContext * oc ; AVCodecContext * codec ; OutputStream * ost ; InputStream * ist ; char error [ 1024 ] ; for (i = 0; i < nb_input_files; i++) InputFile * ifile = input_files [ i ] ; if ( ifile -> rate_emu ) for (j = 0; j < ifile -> nb_streams; j++) input_streams [ j + ifile -> ist_index ] -> start = av_gettime ( ); for (i = 0; i < nb_output_files; i++) oc = output_files [ i ] -> ctx; if ( ! oc -> nb_streams && ! ( oc -> oformat -> flags & 0x1000 ) ) return - 22 ; for (i = 0; i < nb_filtergraphs; i++) if ( ( ret = avfilter_graph_config ( filtergraphs [ i ] -> graph , ( ( void * ) 0 ) ) ) < 0 ) return ret ; for (i = 0; i < nb_output_streams; i++) AVCodecContext * icodec = ( ( void * ) 0 ) ; ost = output_streams [ i ]; oc = output_files [ ost -> file_index ] -> ctx; ist = get_input_stream ( ost ); static InputStream *get_input_stream(OutputStream *ost) if ( ost -> source_index >= 0 ) return input_streams [ ost -> source_index ] ; return ( ( void * ) 0 ) ; if ( ost -> attachment_filename ) codec = ost -> st -> codec; if ( ist ) icodec = ist -> st -> codec; ost -> st -> disposition = ist -> st -> disposition; codec -> bits_per_raw_sample = icodec -> bits_per_raw_sample; codec -> chroma_sample_location = icodec -> chroma_sample_location; if ( ost -> stream_copy ) uint64_t extra_size ; extra_size = ( ( uint64_t ) ( icodec -> extradata_size ) ) + 16; if ( extra_size > 2147483647 ) return - 22 ; codec -> codec_id = icodec -> codec_id; codec -> codec_type = icodec -> codec_type; if ( ! codec -> codec_tag ) unsigned int codec_tag ; if ( ! oc -> oformat -> codec_tag || ( av_codec_get_id ( oc -> oformat -> codec_tag , icodec -> codec_tag ) ) == ( codec -> codec_id ) || ! av_codec_get_tag2 ( oc -> oformat -> codec_tag , icodec -> codec_id , & codec_tag ) ) codec -> codec_tag = icodec -> codec_tag; codec -> bit_rate = icodec -> bit_rate; codec -> rc_max_rate = icodec -> rc_max_rate; codec -> rc_buffer_size = icodec -> rc_buffer_size; codec -> field_order = icodec -> field_order; codec -> extradata = ( av_mallocz ( extra_size ) ); if ( ! codec -> extradata ) return - 12 ; memcpy ( ( codec -> extradata ) , ( icodec -> extradata ) , ( icodec -> extradata_size ) ); codec -> extradata_size = icodec -> extradata_size; codec -> bits_per_coded_sample = icodec -> bits_per_coded_sample; codec -> time_base = ist -> st -> time_base; if ( ! strcmp ( oc -> oformat -> name , "avi" ) ) if ( copy_tb < 0 && av_q2d ( ist -> st -> r_frame_rate ) >= av_q2d ( ist -> st -> avg_frame_rate ) && 0.5 / av_q2d ( ist -> st -> r_frame_rate ) > av_q2d ( ist -> st -> time_base ) && 0.5 / av_q2d ( ist -> st -> r_frame_rate ) > av_q2d ( icodec -> time_base ) && av_q2d ( ist -> st -> time_base ) < 1.0 / 500 && av_q2d ( icodec -> time_base ) < 1.0 / 500 || copy_tb == 2 ) codec -> time_base . num = ist -> st -> r_frame_rate . den; codec -> time_base . den = 2 * ist -> st -> r_frame_rate . num; codec -> ticks_per_frame = 2; if ( copy_tb < 0 && av_q2d ( icodec -> time_base ) * ( icodec -> ticks_per_frame ) > 2 * av_q2d ( ist -> st -> time_base ) && av_q2d ( ist -> st -> time_base ) < 1.0 / 500 || copy_tb == 0 ) codec -> time_base = icodec -> time_base; codec -> time_base . num *= icodec -> ticks_per_frame; codec -> time_base . den *= 2; codec -> ticks_per_frame = 2; if ( ! ( oc -> oformat -> flags & 0002000 ) && strcmp ( oc -> oformat -> name , "mov" ) && strcmp ( oc -> oformat -> name , "mp4" ) && strcmp ( oc -> oformat -> name , "3gp" ) && strcmp ( oc -> oformat -> name , "3g2" ) && strcmp ( oc -> oformat -> name , "psp" ) && strcmp ( oc -> oformat -> name , "ipod" ) && strcmp ( oc -> oformat -> name , "f4v" ) ) if ( copy_tb < 0 && icodec -> time_base . den && av_q2d ( icodec -> time_base ) * ( icodec -> ticks_per_frame ) > av_q2d ( ist -> st -> time_base ) && av_q2d ( ist -> st -> time_base ) < 1.0 / 500 || copy_tb == 0 ) codec -> time_base = icodec -> time_base; codec -> time_base . num *= icodec -> ticks_per_frame; codec -> time_base = icodec -> time_base; if ( ost -> frame_rate . num ) codec -> time_base = av_inv_q ( ost -> frame_rate ); switch ( codec -> codec_type ) codec -> channel_layout = icodec -> channel_layout; codec -> sample_rate = icodec -> sample_rate; codec -> channels = icodec -> channels; codec -> frame_size = icodec -> frame_size; codec -> audio_service_type = icodec -> audio_service_type; codec -> block_align = icodec -> block_align; if ( ( codec -> block_align == 1 || codec -> block_align == 1152 || codec -> block_align == 576 ) && ( codec -> codec_id ) == AV_CODEC_ID_MP3 ) codec -> block_align = 0; if ( ( codec -> codec_id ) == AV_CODEC_ID_AC3 ) codec -> block_align = 0; codec -> pix_fmt = icodec -> pix_fmt; codec -> width = icodec -> width; codec -> height = icodec -> height; codec -> has_b_frames = icodec -> has_b_frames; if ( ! codec -> sample_aspect_ratio . num ) codec -> sample_aspect_ratio = ost -> st -> sample_aspect_ratio = ( ist -> st -> sample_aspect_ratio . num ? ist -> st -> sample_aspect_ratio : ( ( ist -> st -> codec -> sample_aspect_ratio . num ? ist -> st -> codec -> sample_aspect_ratio : ( ( AVRational ) ( 0 ) , ( 1 ) ) ) ) ) ost -> st -> avg_frame_rate = ist -> st -> avg_frame_rate; codec -> width = icodec -> width; codec -> height = icodec -> height; if ( ! ost -> enc ) ost -> enc = avcodec_find_encoder ( codec -> codec_id ); if ( ! ost -> enc ) ret = - 22; if ( ist ) ist -> decoding_needed ++; ost -> encoding_needed = 1; if ( ( codec -> codec_type ) == AVMEDIA_TYPE_VIDEO ) if ( ost -> filter && ! ost -> frame_rate . num ) ost -> frame_rate = av_buffersink_get_frame_rate ( ost -> filter -> filter ); if ( ist && ! ost -> frame_rate . num ) ost -> frame_rate = ist -> framerate; if ( ist && ! ost -> frame_rate . num ) ost -> frame_rate = ( ist -> st -> r_frame_rate . num ? ist -> st -> r_frame_rate : ( ( AVRational ) ( 25 ) , ( 1 ) ) ) if ( ost -> enc && ost -> enc -> supported_framerates && ! ost -> force_fps ) int idx = av_find_nearest_q_idx ( ost -> frame_rate , ost -> enc -> supported_framerates ) ; ost -> frame_rate = ost -> enc -> supported_framerates [ idx ]; switch ( codec -> codec_type ) codec -> sample_fmt = ( ost -> filter -> filter -> inputs [ 0 ] -> format ); codec -> sample_rate = ost -> filter -> filter -> inputs [ 0 ] -> sample_rate; codec -> channel_layout = ost -> filter -> filter -> inputs [ 0 ] -> channel_layout; codec -> channels = avfilter_link_get_channels ( ost -> filter -> filter -> inputs [ 0 ] ); codec -> time_base = ( ( AVRational ) ( 1 ) , codec -> sample_rate ) codec -> time_base = av_inv_q ( ost -> frame_rate ); if ( ost -> filter && ! ( codec -> time_base . num && codec -> time_base . den ) ) codec -> time_base = ost -> filter -> filter -> inputs [ 0 ] -> time_base; codec -> width = ost -> filter -> filter -> inputs [ 0 ] -> w; codec -> height = ost -> filter -> filter -> inputs [ 0 ] -> h; codec -> sample_aspect_ratio = ost -> st -> sample_aspect_ratio = ( ost -> frame_aspect_ratio ? av_d2q ( ( ost -> frame_aspect_ratio * ( codec -> height ) / ( codec -> width ) ) , 255 ) : ost -> filter -> filter -> inputs [ 0 ] -> sample_aspect_ratio ); codec -> pix_fmt = ( ost -> filter -> filter -> inputs [ 0 ] -> format ); if ( ! icodec || codec -> width != icodec -> width || codec -> height != icodec -> height || ( codec -> pix_fmt ) != ( icodec -> pix_fmt ) ) codec -> bits_per_raw_sample = frame_bits_per_raw_sample; if ( ost -> forced_keyframes ) if ( ! strncmp ( ( ost -> forced_keyframes ) , "expr:" , 5 ) ) ret = av_expr_parse ( & ost -> forced_keyframes_pexpr , ( ost -> forced_keyframes + 5 ) , forced_keyframes_const_names , ( ( void * ) 0 ) , ( ( void * ) 0 ) , ( ( void * ) 0 ) , ( ( void * ) 0 ) , 0 , ( ( void * ) 0 ) ); if ( ret < 0 ) return ret ; ost -> forced_keyframes_expr_const_values [ FKF_N ] = 0; ost -> forced_keyframes_expr_const_values [ FKF_N_FORCED ] = 0; ost -> forced_keyframes_expr_const_values [ FKF_PREV_FORCED_N ] = ( __builtin_nanf ( "" ) ); ost -> forced_keyframes_expr_const_values [ FKF_PREV_FORCED_T ] = ( __builtin_nanf ( "" ) ); codec -> time_base = ( ( AVRational ) ( 1 ) , ( 1000 ) ) if ( ! codec -> width ) codec -> width = input_streams [ ost -> source_index ] -> st -> codec -> width; codec -> height = input_streams [ ost -> source_index ] -> st -> codec -> height; if ( codec -> flags & ( 0x0200 | 0002000 ) ) char logfilename [ 1024 ] ; FILE * f ; snprintf ( logfilename , sizeof ( logfilename ) , "%s-%d.log" , ( ost -> logfile_prefix ? ost -> logfile_prefix : "ffmpeg2pass" ) , i ); if ( ! strcmp ( ost -> enc -> name , "libx264" ) ) if ( codec -> flags & 0002000 ) char * logbuffer ; codec -> stats_in = logbuffer; if ( codec -> flags & 0x0200 ) f = fopen ( logfilename , "wb" ); ost -> logfile = f; for (i = 0; i < nb_output_streams; i++) ost = output_streams [ i ]; if ( ost -> encoding_needed ) AVCodec * codec = ost -> enc ; AVCodecContext * dec = ( ( void * ) 0 ) ; if ( ist = get_input_stream ( ost ) ) static InputStream *get_input_stream(OutputStream *ost) if ( ost -> source_index >= 0 ) return input_streams [ ost -> source_index ] ; return ( ( void * ) 0 ) ; dec = ist -> st -> codec; if ( dec && dec -> subtitle_header ) ost -> st -> codec -> subtitle_header = ( av_mallocz ( ( dec -> subtitle_header_size + 1 ) ) ); if ( ! ost -> st -> codec -> subtitle_header ) ret = - 12; memcpy ( ( ost -> st -> codec -> subtitle_header ) , ( dec -> subtitle_header ) , ( dec -> subtitle_header_size ) ); ost -> st -> codec -> subtitle_header_size = dec -> subtitle_header_size; if ( ( ret = avcodec_open2 ( ost -> st -> codec , codec , & ost -> opts ) ) < 0 ) for (i = 0; i < nb_input_streams; i++) if ( ( ret = init_input_stream ( i , error , ( sizeof ( error ) ) ) ) < 0 ) static int init_input_stream(int ist_index,char *error,int error_len) int ret ; InputStream * ist = input_streams [ ist_index ] ; if ( ist -> decoding_needed ) AVCodec * codec = ist -> dec ; if ( ! codec ) return - 22 ; ist -> dr1 = codec -> capabilities & 0000002 && ! ( '6' < 56 && do_deinterlace ); if ( ( codec -> type ) == AVMEDIA_TYPE_VIDEO && ist -> dr1 ) ist -> st -> codec -> get_buffer = codec_get_buffer; ist -> st -> codec -> release_buffer = codec_release_buffer; ist -> st -> codec -> opaque = ( & ist -> buffer_pool ); if ( ( ret = avcodec_open2 ( ist -> st -> codec , codec , & ist -> opts ) ) < 0 ) return ret ; return 0 ; for (i = 0; i < nb_input_files; i++) for (i = 0; i < nb_output_files; i++) oc = output_files [ i ] -> ctx; oc -> interrupt_callback = int_cb; if ( ( ret = avformat_write_header ( oc , & output_files [ i ] -> opts ) ) < 0 ) ret = - 22; if ( ret ) return ret ; return 0 ; if ( ret < 0 ) if ( ( ret = init_input_threads ( ) ) < 0 ) static int init_input_threads() int i ; int ret ; if ( nb_input_files == 1 ) return 0 ; for (i = 0; i < nb_input_files; i++) InputFile * f = input_files [ i ] ; if ( ! ( f -> fifo = av_fifo_alloc ( ( 8 * sizeof ( AVPacket ) ) ) ) ) return - 12 ; if ( ret = pthread_create ( & f -> thread , ( ( void * ) 0 ) , input_thread , f ) ) return - ret ; return 0 ; while ( ! received_sigterm ) int64_t cur_time = av_gettime ( ) ; if ( stdin_interaction ) if ( check_keyboard_interaction ( cur_time ) < 0 ) if ( ! need_output ( ) ) static int need_output() int i ; for (i = 0; i < nb_output_streams; i++) OutputStream * ost = output_streams [ i ] ; OutputFile * of = output_files [ ost -> file_index ] ; AVFormatContext * os = output_files [ ost -> file_index ] -> ctx ; if ( ost -> finished || os -> pb && ( avio_tell ( os -> pb ) ) >= of -> limit_filesize ) if ( ( ost -> frame_number ) >= ost -> max_frames ) return 1 ; return 0 ; ret = transcode_step ( ); static int transcode_step() OutputStream * ost ; InputStream * ist ; int ret ; ost = choose_output ( ); static OutputStream *choose_output() int i ; int64_t opts_min = 9223372036854775807L ; OutputStream * ost_min = ( ( void * ) 0 ) ; for (i = 0; i < nb_output_streams; i++) OutputStream * ost = output_streams [ i ] ; int64_t opts = av_rescale_q ( ost -> st -> cur_dts , ost -> st -> time_base , ( ( AVRational ) ( 1 ) , ( 1000000 ) ) ) if ( ! ost -> unavailable && ! ost -> finished && opts < opts_min ) opts_min = opts; ost_min = ost; return ost_min ; if ( ! ost ) if ( got_eagain ( ) ) static int got_eagain() int i ; for (i = 0; i < nb_output_streams; i++) if ( output_streams [ i ] -> unavailable ) return 1 ; return 0 ; return 0 ; return - ( ( int ) ( ( 'E' | 'O' << 8 | 'F' << 16 ) | ( ( unsigned int ) 32 ) << 24 ) ) ; if ( ost -> filter ) if ( ( ret = transcode_from_filter ( ost -> filter -> graph , & ist ) ) < 0 ) static int transcode_from_filter(FilterGraph *graph,InputStream **best_ist) int ret ; ret = avfilter_graph_request_oldest ( graph -> graph ); if ( ret >= 0 ) return reap_filters ( ) ; static int reap_filters() int i ; for (i = 0; i < nb_output_streams; i++) OutputStream * ost = output_streams [ i ] ; if ( ! ost -> filter ) if ( ! ost -> filtered_frame && ! ( ost -> filtered_frame = avcodec_alloc_frame ( ) ) ) return - 12 ; return 0 ; if ( ret == - ( ( int ) ( ( 'E' | 'O' << 8 | 'F' << 16 ) | ( ( unsigned int ) 32 ) << 24 ) ) ) ret = reap_filters ( ); static int reap_filters() int i ; OutputStream * ost = output_streams [ i ] ; if ( ! ost -> filter ) if ( ! ost -> filtered_frame && ! ( ost -> filtered_frame = avcodec_alloc_frame ( ) ) ) return - 12 ; return 0 ; return ret ; if ( ret != - 11 ) return ret ; return 0 ; return ret ; if ( ! ist ) return 0 ; ist = input_streams [ ost -> source_index ]; ret = process_input ( ist -> file_index ); static int process_input(int file_index) InputFile * ifile = input_files [ file_index ] ; int ret ; ret = get_input_packet ( ifile , & pkt ); static int get_input_packet(InputFile *f,AVPacket *pkt) if ( nb_input_files > 1 ) return get_input_packet_mt ( f , pkt ) ; static int get_input_packet_mt(InputFile *f,AVPacket *pkt) int ret = 0 ; if ( av_fifo_size ( f -> fifo ) ) if ( f -> finished ) ret = - ( ( int ) ( ( 'E' | 'O' << 8 | 'F' << 16 ) | ( ( unsigned int ) 32 ) << 24 ) ); ret = - 11; return ret ; return av_read_frame ( f -> ctx , pkt ) ; if ( ret == - 11 ) return ret ; if ( ret < 0 ) return - 11 ; return 0 ; if ( ret == - 11 ) return 0 ; if ( ret < 0 ) return ret == - ( ( int ) ( ( 'E' | 'O' << 8 | 'F' << 16 ) | ( ( unsigned int ) 32 ) << 24 ) ) ? 0 : ret ; return reap_filters ( ) ; static int reap_filters() int i ; OutputStream * ost = output_streams [ i ] ; if ( ! ost -> filter ) if ( ! ost -> filtered_frame && ! ( ost -> filtered_frame = avcodec_alloc_frame ( ) ) ) return - 12 ; return 0 ; if ( ret < 0 ) if ( ret == - ( ( int ) ( ( 'E' | 'O' << 8 | 'F' << 16 ) | ( ( unsigned int ) 32 ) << 24 ) ) || ret == - 11 ) static int check_keyboard_interaction(int64_t cur_time) int i ; int ret ; int key ; static int64_t last_time ; if ( received_nb_signals ) if ( cur_time - last_time >= 100000 && ! run_as_daemon ) key = read_key ( ); static int read_key() unsigned char ch ; struct timeval tv ; fd_set rfds ; ( & rfds ) -> fds_bits [ 0 / ( 8 * ( ( int ) ( sizeof ( __fd_mask ) ) ) ) ] |= ( ( __fd_mask ) 1 ) << 0 % ( 8 * ( ( int ) ( sizeof ( __fd_mask ) ) ) ); tv . tv_sec = 0; tv . tv_usec = 0; n = select ( 1 , & rfds , ( ( void * ) 0 ) , ( ( void * ) 0 ) , & tv ); if ( n > 0 ) n = ( read ( 0 , ( & ch ) , 1 ) ); if ( n == 1 ) return ch ; return n ; return - 1 ; key = - 1; if ( key == 'q' ) if ( key == 'c' || key == 'C' ) char buf [ 4096 ] ; char target [ 64 ] ; char command [ 256 ] ; char arg [ 256 ] = { ( 0 ) } ; double time ; int k ; fprintf ( stderr , "\nEnter command: <target> <time> <command>[ <argument>]\n" ); i = 0; while ( ( k = read_key ( ) ) != 10 && k != '\r' && i < sizeof ( buf ) - 1 ) static int read_key() unsigned char ch ; struct timeval tv ; fd_set rfds ; ( & rfds ) -> fds_bits [ 0 / ( 8 * ( ( int ) ( sizeof ( __fd_mask ) ) ) ) ] |= ( ( __fd_mask ) 1 ) << 0 % ( 8 * ( ( int ) ( sizeof ( __fd_mask ) ) ) ); tv . tv_sec = 0; tv . tv_usec = 0; n = select ( 1 , & rfds , ( ( void * ) 0 ) , ( ( void * ) 0 ) , & tv ); if ( n > 0 ) n = ( read ( 0 , ( & ch ) , 1 ) ); if ( n == 1 ) return ch ; return n ; return - 1 ; if ( k > 0 ) buf [ i ++ ] = k; buf [ i ] = 0; if ( k > 0 && ( n = sscanf ( buf , "%63[^ ] %lf %255[^ ] %255[^\n]" , target , & time , command , arg ) ) >= 3 ) for (i = 0; i < nb_filtergraphs; i++) FilterGraph * fg = filtergraphs [ i ] ; if ( fg -> graph ) if ( time < 0 ) ret = avfilter_graph_send_command ( fg -> graph , target , command , arg , buf , ( sizeof ( buf ) ) , ( key == 'c' ? 1 : 0 ) ); fprintf ( stderr , "Command reply for stream %d: ret:%d res:%s\n" , i , ret , buf ); if ( key == 100 || key == 'D' ) if ( key == 'D' ) if ( scanf ( "%d" , & debug ) != 1 ) fprintf ( stderr , "error parsing debug value\n" ); fprintf ( stderr , "debug=%d\n" , debug ); fprintf ( stderr , "key function\n? show this help\n+ increase verbosity\n- decrease verbosity\nc Send command to filtergraph\nD cycle through available debug modes\nh dump packets/hex press to cycle through the 3 states\nq quit\ns Show QP histogram\n" );
152660/ffmpeg.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 ] ) fifo_flgs = strcpy ( ( xmalloc ( strlen ( c [ 1 ] ) + 1 ) ) , c [ 1 ] );
153763/color.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 ( ! ( conversation -> options & 0x01 ) && ptype != PT_UDP ) if ( ! ( conversation -> options & 0x08 ) ) conversation = conversation_create_from_template ( conversation , addr_b , 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 ) ) if ( ptype != PT_UDP ) if ( ! ( conversation -> options & 0x08 ) ) conversation = conversation_create_from_template ( conversation , 0 , port_a ); 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 ) ) if ( ! ( conversation -> options & 0x01 ) ) conversation_set_addr2 ( conversation , addr_b ); void conversation_set_addr2(conversation_t *conv,const address *addr) ( void ) ( ! ( conv -> options & 0x08 ) ? ( ( void ) 0 ) : ( ( getenv ( "WIRESHARK_ABORT_ON_DISSECTOR_BUG" ) != ( ( void * ) 0 ) ? abort ( ) : except_throw ( 1 , 4 , ( ep_strdup_printf ( "%s:%u: failed assertion \"%s\" (%s)" , "conversation.c" , 710 , "!(conv->options & 0x08)" , "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask" ) ) ) ) ) );
149441/conversation.c
SARD
0
void CWE197_Numeric_Truncation_Error__int_connect_socket_to_short_07_bad() if ( staticFive == 5 ) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
88662/CWE197_Numeric_Truncation_Error__int_connect_socket_to_short_07.c
SARD
0
void CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_06_bad() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( STATIC_CONST_FIVE == 5 ) size_t dataLen = strlen ( data ) ; recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; badVaSinkB ( data , data ); static void badVaSinkB(char * data, ...) va_start ( args , data ); vsnprintf ( dest , 100 - 1 , data , args ); printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
79343/CWE134_Uncontrolled_Format_String__char_connect_socket_w32_vsnprintf_06.c
SARD
15
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 ); static void copy(const position_set *src,position_set *dst) if ( dst -> alloc <= src -> nelem ) size_t new_n_alloc = src -> nelem + ( ! dst -> elems ) ; dst -> elems = ( x2nrealloc ( ( dst -> elems ) , & new_n_alloc , sizeof ( ( * dst -> elems ) ) ) ); dst -> alloc = new_n_alloc; while ( 0 ) memcpy ( ( dst -> elems ) , ( src -> elems ) , sizeof ( dst -> elems [ 0 ] ) * src -> nelem ); dst -> nelem = src -> nelem;
151732/dfa.c
SARD
0
static void goodB2G1() int count ; count = - 1; 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'; count = atoi ( inputBuffer ); while ( 0 ) switch ( 8 ) const char * filename = "output_good.txt" ; if ( count > 0 && count <= 20 ) pFile = fopen ( filename , "w+" ); if ( pFile == NULL ) if ( strlen ( SENTENCE ) != fwrite ( SENTENCE , sizeof ( char ) , strlen ( SENTENCE ) , pFile ) ) if ( pFile ) fclose ( pFile );
98543/CWE400_Resource_Exhaustion__connect_socket_fwrite_15.c
SARD
0
static void good2() switch ( 6 ) BYTE payload [ 100 ] ; HCRYPTPROV hCryptProv = ( HCRYPTPROV ) NULL ; HCRYPTHASH hHash = ( HCRYPTHASH ) NULL ; HCRYPTKEY hKey = ( HCRYPTKEY ) NULL ; char hashData [ 100 ] = HASH_INPUT ; if ( ! CryptAcquireContext ( & hCryptProv , NULL , MS_ENH_RSA_AES_PROV , PROV_RSA_AES , 0 ) ) if ( ! CryptCreateHash ( hCryptProv , CALG_SHA_256 , 0 , 0 , & hHash ) ) if ( ! CryptHashData ( hHash , ( BYTE * ) hashData , strlen ( hashData ) , 0 ) ) if ( ! CryptDeriveKey ( hCryptProv , CALG_AES_256 , hHash , 0 , & hKey ) ) if ( ! CryptEncrypt ( hKey , 0 , 1 , 0 , payload , & payloadLen , sizeof ( payload ) ) ) while ( 0 )
94400/CWE325_Missing_Required_Cryptographic_Step__w32_CryptCreateHash_15.c
SARD
0
static int handle_stimulus_message(struct skinny_req *req, struct skinnysession *s) struct skinny_device * d = s -> device ; struct skinny_line * l ; struct skinny_subchannel * sub ; struct ast_channel * c ; int event ; int instance ; event = letohl ( req -> data . stimulus . stimulus ); instance = letohl ( req -> data . stimulus . stimulusInstance ); sub = find_subchannel_by_instance_reference ( d , d -> lastlineinstance , d -> lastcallreference ); if ( ! sub ) l = find_line_by_instance ( d , d -> lastlineinstance ); if ( ! l ) sub = l -> activesub; l = sub -> line; switch ( event ) struct skinny_speeddial * sd ; if ( ! ( sd = find_speeddial_by_instance ( d , instance , 0 ) ) ) if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ( sub && sub -> owner ) && ( sub -> owner -> _state == AST_STATE_UP ) ) c = sub -> owner; if ( l -> dnd != 0 ) l -> dnd = 1; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; if ( ! sub || ! sub -> owner ) c = skinny_new ( l , NULL , AST_STATE_DOWN , NULL , SKINNY_OUTGOING ); c = sub -> owner; if ( ! c ) sub = c -> tech_pvt; handle_callforward_button ( sub , SKINNY_CFWD_NOANSWER ); static int handle_callforward_button(struct skinny_subchannel *sub, int cfwdtype) struct skinny_line * l = sub -> line ; if ( l -> cfwdtype & cfwdtype ) setsubstate ( sub , SUBSTATE_OFFHOOK ); static void setsubstate(struct skinny_subchannel *sub, int state) struct skinny_line * l = sub -> line ; struct skinny_subline * subline = sub -> subline ; struct skinny_device * d = l -> device ; struct ast_channel * c = sub -> owner ; int actualstate = state ; if ( sub -> substate == SUBSTATE_ONHOOK ) if ( state != SUBSTATE_RINGIN && sub -> aa_sched ) sub -> aa_sched = 0; sub -> aa_beep = 0; sub -> aa_mute = 0; if ( ( state == SUBSTATE_RINGIN ) && ( ( d -> hookstate == SKINNY_OFFHOOK ) || ( AST_LIST_NEXT ( AST_LIST_FIRST ( & l -> sub ) , list ) ) ) ) actualstate = SUBSTATE_CALLWAIT; if ( ( state == SUBSTATE_CONNECTED ) && ( ! subline ) && ( AST_LIST_FIRST ( & l -> sublines ) ) ) const char * slastation ; struct skinny_subline * tmpsubline ; slastation = pbx_builtin_getvar_helper ( c , "SLASTATION" ); if ( slastation ) subline = tmpsubline; if ( subline ) subline -> sub = sub; sub -> subline = subline; subline -> callid = sub -> callid; if ( subline ) switch ( actualstate ) if ( sub -> substate != SUBSTATE_CONNECTED ) sub -> substate = SUBSTATE_HOLD; if ( skinnydebug ) ast_verb ( 3 , "Sub %d - change state from %s to %s\n" , sub -> callid , substate2str ( sub -> substate ) , substate2str ( actualstate ) ); static char *substate2str(int ind) char * tmp ; switch ( ind ) if ( ! ( tmp = ast_threadstorage_get ( & substate2str_threadbuf , SUBSTATE2STR_BUFSIZE ) ) ) snprintf ( tmp , SUBSTATE2STR_BUFSIZE , "UNKNOWN-%d" , ind ); return tmp ;
148809/chan_skinny.c
SARD
0
void dfacomp(const char *s,size_t len,struct dfa *d,int searchflag) dfaanalyze ( d , searchflag ); void dfaanalyze(struct dfa *d,int searchflag) d -> searchflag = searchflag; d -> follows = ( ( sizeof ( ( * d -> follows ) ) == 1 ? xzalloc ( d -> tindex ) : xcalloc ( d -> tindex , sizeof ( ( * d -> follows ) ) ) ) ); while ( 0 ) d -> salloc = 1; d -> sindex = 0; d -> states = ( ( sizeof ( ( * d -> states ) ) == 1 ? xmalloc ( ( d -> salloc ) ) : xnmalloc ( ( d -> salloc ) , sizeof ( ( * d -> states ) ) ) ) ); while ( 0 ) state_index ( d , ( & merged ) , ( separate_contexts & 4 ? 4 : separate_contexts ^ 7 ) ); static state_num state_index(struct dfa *d,const position_set *s,int context) 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 ) for (j = 0; j < s -> nelem; ++j) if ( s -> elems [ j ] . constraint != d -> states [ i ] . elems . elems [ j ] . constraint || s -> elems [ j ] . index != d -> states [ i ] . elems . elems [ j ] . index ) 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; d -> states [ i ] . hash = hash; alloc_position_set ( & d -> states [ i ] . elems , s -> nelem ); static void alloc_position_set(position_set *s,size_t size) s -> elems = ( ( sizeof ( ( * s -> elems ) ) == 1 ? xmalloc ( size ) : xnmalloc ( size , sizeof ( ( * s -> elems ) ) ) ) ); s -> alloc = size; s -> nelem = 0; copy ( s , & d -> states [ i ] . elems ); static void copy(const position_set *src,position_set *dst) if ( dst -> alloc <= src -> nelem ) size_t new_n_alloc = src -> nelem + ( ! dst -> elems ) ; dst -> elems = ( x2nrealloc ( ( dst -> elems ) , & new_n_alloc , sizeof ( ( * dst -> elems ) ) ) ); dst -> alloc = new_n_alloc; memcpy ( ( dst -> elems ) , ( src -> elems ) , sizeof ( dst -> elems [ 0 ] ) * src -> nelem ); dst -> nelem = src -> nelem; d -> states [ i ] . context = context; d -> states [ i ] . backref = 0; d -> states [ i ] . constraint = 0; d -> states [ i ] . first_end = 0; d -> states [ i ] . mbps . nelem = 0; d -> states [ i ] . mbps . elems = ( ( void * ) 0 ); for (j = 0; j < s -> nelem; ++j) if ( d -> tokens [ s -> elems [ j ] . index ] < 0 ) constraint = s -> elems [ j ] . constraint; if ( ( ( ( 7 & 1 ? constraint & 0xf : 0 ) ) | ( ( 7 & 2 ? constraint >> 4 & 0xf : 0 ) ) | ( ( 7 & 4 ? constraint >> 8 & 0xf : 0 ) ) ) & context ) d -> states [ i ] . constraint |= constraint; if ( ! d -> states [ i ] . first_end ) d -> states [ i ] . first_end = d -> tokens [ s -> elems [ j ] . index ]; if ( d -> tokens [ s -> elems [ j ] . index ] == BACKREF ) d -> states [ i ] . constraint = 0x777; d -> states [ i ] . backref = 1; ++ d -> sindex; return i ;
153287/dfa.c
SARD
0
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_loop_67_bad() wchar_t * data ; CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_loop_67_structType myStruct ; data = NULL; data = ( wchar_t * ) malloc ( 50 * sizeof ( wchar_t ) ); data [ 0 ] = L '\0' myStruct . structFirst = data; CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_loop_67b_badSink ( myStruct ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_loop_67b_badSink(CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_loop_67_structType myStruct) wchar_t * data = myStruct . structFirst ; size_t i ; wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' for (i = 0; i < 100; i++) data [ i ] = source [ i ]; data [ 100 - 1 ] = L '\0' free ( data );
71975/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_wchar_t_loop_67b.c
SARD
3
static status_transit_state transit_state_singlebyte(struct dfa *d,state_num s,const unsigned char *p,state_num *next_state) state_num * t ; state_num works = s ; status_transit_state rval = TRANSIT_STATE_IN_PROGRESS ; while ( rval == TRANSIT_STATE_IN_PROGRESS ) if ( ( t = d -> trans [ works ] ) != ( ( void * ) 0 ) ) works = t [ * p ]; rval = TRANSIT_STATE_DONE; if ( works < 0 ) works = 0; if ( works < 0 ) works = 0; if ( d -> fails [ works ] ) works = d -> fails [ works ] [ * p ]; rval = TRANSIT_STATE_DONE; build_state ( works , d ); static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) position_set tmp ; alloc_position_set ( & tmp , d -> nleaves ); static void alloc_position_set(position_set *s,size_t size) s -> elems = ( ( sizeof ( ( * s -> elems ) ) == 1 ? xmalloc ( size ) : xnmalloc ( size , sizeof ( ( * s -> elems ) ) ) ) ); while ( 0 ) s -> alloc = size; s -> nelem = 0;
151282/dfa.c
SARD
0
static void goodB2G() char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = strtoul ( inputBuffer , NULL , 0 ); CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_53b_goodB2GSink ( data ); void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_53b_goodB2GSink(size_t data) CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_53c_goodB2GSink ( data ); void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_53c_goodB2GSink(size_t data) CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_53d_goodB2GSink ( data ); void CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_53d_goodB2GSink(size_t data) if ( data > wcslen ( HELLO_STRING ) && data < 100 ) myString = ( wchar_t * ) malloc ( data * sizeof ( wchar_t ) ); wcscpy ( myString , HELLO_STRING ); printWLine ( myString ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( myString );
117302/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_53a.c
SARD
0
void CWE369_Divide_by_Zero__int_listen_socket_modulo_22_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 )
95317/CWE369_Divide_by_Zero__int_listen_socket_modulo_22a.c
SARD
0
static void goodB2G1() wchar_t * data ; wchar_t dataBuffer [ 100 ] = L "" data = dataBuffer; if ( 1 ) size_t dataLen = wcslen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) fclose ( pFile );
81643/CWE134_Uncontrolled_Format_String__wchar_t_file_w32_vsnprintf_02.c
SARD
0
static void goodG2B1() char * data ; data = NULL; switch ( 5 ) data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memcpy ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; free ( data );
71278/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_memcpy_15.c
SARD
0
void avcodec_string(char *buf,int buf_size,AVCodecContext *enc,int encode) const char * codec_type ; const char * codec_name ; const char * profile = ( ( void * ) 0 ) ; const AVCodec * p ; AVRational display_aspect_ratio ; if ( ! buf || buf_size <= 0 ) codec_type = av_get_media_type_string ( enc -> codec_type ); codec_name = avcodec_get_name ( enc -> codec_id ); const char *avcodec_get_name(enum AVCodecID id) const AVCodecDescriptor * cd ; AVCodec * codec ; if ( id == AV_CODEC_ID_NONE ) return "none" ; cd = avcodec_descriptor_get ( id ); if ( cd ) return cd -> name ; codec = avcodec_find_decoder ( id ); AVCodec *avcodec_find_decoder(enum AVCodecID id) return find_encdec ( id , 0 ) ; static AVCodec *find_encdec(enum AVCodecID id,int encoder) AVCodec * p ; AVCodec * experimental = ( ( void * ) 0 ) ; p = first_avcodec; id = remap_deprecated_codec_id ( id ); static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id) switch ( id ) return AV_CODEC_ID_OPUS ; return AV_CODEC_ID_TAK ; return id ; while ( p ) if ( ( ( encoder ? av_codec_is_encoder ( p ) : av_codec_is_decoder ( p ) ) ) && ( p -> id ) == id ) int av_codec_is_decoder(const AVCodec *codec) return codec && codec -> decode ; int av_codec_is_encoder(const AVCodec *codec) return codec && ( codec -> encode_sub || codec -> encode2 ) ; if ( p -> capabilities & 0x0200 && ! experimental ) experimental = p; return p ; p = p -> next; return experimental ; if ( codec ) return codec -> name ; codec = avcodec_find_encoder ( id ); AVCodec *avcodec_find_encoder(enum AVCodecID id) return find_encdec ( id , 1 ) ; static AVCodec *find_encdec(enum AVCodecID id,int encoder) AVCodec * p ; AVCodec * experimental = ( ( void * ) 0 ) ; p = first_avcodec; id = remap_deprecated_codec_id ( id ); while ( p ) if ( ( ( encoder ? av_codec_is_encoder ( p ) : av_codec_is_decoder ( p ) ) ) && ( p -> id ) == id ) if ( p -> capabilities & 0x0200 && ! experimental ) experimental = p; return p ; p = p -> next; return experimental ; if ( codec ) return codec -> name ; return "unknown_codec" ; if ( enc -> profile != - 'c' ) if ( enc -> codec ) p = enc -> codec; p = ( ( encode ? avcodec_find_encoder ( enc -> codec_id ) : avcodec_find_decoder ( enc -> codec_id ) ) ); AVCodec *avcodec_find_decoder(enum AVCodecID id) return find_encdec ( id , 0 ) ; AVCodec *avcodec_find_encoder(enum AVCodecID id) return find_encdec ( id , 1 ) ; if ( p ) profile = av_get_profile_name ( p , enc -> profile ); const char *av_get_profile_name(const AVCodec *codec,int profile) const AVProfile * p ; if ( profile == - 'c' || ! codec -> profiles ) return ( ( void * ) 0 ) ; for (p = codec -> profiles; p -> profile != - 'c'; p++) if ( p -> profile == profile ) return p -> name ; return ( ( void * ) 0 ) ; snprintf ( buf , buf_size , "%s: %s%s" , ( codec_type ? codec_type : "unknown" ) , codec_name , ( enc -> mb_decision ? " (hq)" : "" ) ); buf [ 0 ] ^= 'a' ^ 'A'; if ( profile ) snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , " (%s)" , profile ); if ( enc -> codec_tag ) char tag_buf [ 32 ] ; snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , " (%s / 0x%04X)" , tag_buf , enc -> codec_tag ); switch ( enc -> codec_type ) if ( ( enc -> pix_fmt ) != AV_PIX_FMT_NONE ) snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", %s" , av_get_pix_fmt_name ( enc -> pix_fmt ) ); if ( enc -> bits_per_raw_sample && enc -> bits_per_raw_sample <= av_pix_fmt_desc_get ( enc -> pix_fmt ) -> comp [ 0 ] . depth_minus1 ) snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , " (%d bpc)" , enc -> bits_per_raw_sample ); if ( enc -> width ) snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", %dx%d" , enc -> width , enc -> height ); if ( enc -> sample_aspect_ratio . num ) snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , " [SAR %d:%d DAR %d:%d]" , enc -> sample_aspect_ratio . num , enc -> sample_aspect_ratio . den , display_aspect_ratio . num , display_aspect_ratio . den ); if ( av_log_get_level ( ) >= 48 ) int g = ( av_gcd ( enc -> time_base . num , enc -> time_base . den ) ) ; snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", %d/%d" , enc -> time_base . num / g , enc -> time_base . den / g ); if ( encode ) snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", q=%d-%d" , enc -> qmin , enc -> qmax ); snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", %d Hz" , enc -> sample_rate ); av_strlcat ( buf , ", " , buf_size ); av_get_channel_layout_string ( buf + strlen ( buf ) , ( buf_size - strlen ( buf ) ) , enc -> channels , enc -> channel_layout ); snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", %s" , av_get_sample_fmt_name ( enc -> sample_fmt ) ); snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", %d/%d" , enc -> time_base . num / g , enc -> time_base . den / g ); snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", pass 1" ); snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", pass 2" ); snprintf ( buf + strlen ( buf ) , buf_size - strlen ( buf ) , ", %d kb/s" , bitrate / 1000 );
150417/utils.c
SARD
0
static void goodB2G() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; CWE134_Uncontrolled_Format_String__char_file_fprintf_84_goodB2G * goodB2GObject = new CWE134_Uncontrolled_Format_String__char_file_fprintf_84_goodB2G ( data ) ; CWE134_Uncontrolled_Format_String__char_file_fprintf_84_goodB2G::CWE134_Uncontrolled_Format_String__char_file_fprintf_84_goodB2G(char * dataCopy) data = dataCopy; size_t dataLen = strlen ( data ) ; FILE * pFile ; if ( 100 - dataLen > 1 ) pFile = fopen ( FILENAME , "r" ); if ( pFile != NULL ) fclose ( pFile );
80009/CWE134_Uncontrolled_Format_String__char_file_fprintf_84_goodB2G.cpp
SARD
0
static void goodG2B2() char * data ; if ( GLOBAL_CONST_FIVE == 5 ) data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; strncpy ( data , source , 100 - 1 ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
71420/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_char_ncpy_13.c
SARD
0
static void good1() if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; char dataBuffer [ 100 ] = "" ; char * data = dataBuffer ; if ( fgets ( data , 100 , stdin ) == NULL ) printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
92099/CWE252_Unchecked_Return_Value__char_fgets_12.c
SARD
0
void CWE194_Unexpected_Sign_Extension__fgets_memmove_21_bad() short data ; data = 0; data = badSource ( data ); static short badSource(short data) if ( badStatic ) char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = ( short ) atoi ( inputBuffer ); return data ; char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) memmove ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
86592/CWE194_Unexpected_Sign_Extension__fgets_memmove_21.c
SARD
20
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; size_t dataLen = strlen ( data ) ; recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; pFile = FOPEN ( data , "wb+" ); if ( pFile != NULL ) fclose ( pFile );
96505/CWE36_Absolute_Path_Traversal__char_listen_socket_fopen_08.cpp
SARD
4
void CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_cpy_63_bad() wchar_t * data ; data = ( wchar_t * ) malloc ( 10 * sizeof ( wchar_t ) ); CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_cpy_63b_badSink ( & data ); void CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_cpy_63b_badSink(wchar_t * * dataPtr) wchar_t * data = * dataPtr ; wcscpy ( data , source ); printWLine ( data ); void printWLine (const wchar_t * line) if ( line != NULL ) wprintf ( L "%ls\n" , line ) free ( data );
71011/CWE122_Heap_Based_Buffer_Overflow__c_CWE193_wchar_t_cpy_63a.c
SARD
0
static void goodG2B1() size_t data ; data = 0; if ( globalReturnsFalse ( ) ) int globalReturnsFalse() return 0 ; data = 20; if ( globalReturnsTrue ( ) ) int globalReturnsTrue() return 1 ; char * myString ; 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
117617/CWE789_Uncontrolled_Mem_Alloc__new_char_listen_socket_11.cpp
SARD
0
void CWE401_Memory_Leak__malloc_realloc_struct_twoIntsStruct_13_bad() if ( GLOBAL_CONST_FIVE == 5 ) struct _twoIntsStruct * data = ( struct _twoIntsStruct * ) malloc ( 100 * sizeof ( struct _twoIntsStruct ) ) ; data [ 0 ] . intOne = 0; data [ 0 ] . intTwo = 0; data = ( struct _twoIntsStruct * ) realloc ( data , ( 130000 ) * sizeof ( struct _twoIntsStruct ) ); if ( data != NULL ) data [ 0 ] . intOne = 1; data [ 0 ] . intTwo = 1; printStructLine ( ( twoIntsStruct * ) & data [ 0 ] ); void printStructLine (const twoIntsStruct * structTwoIntsStruct) printf ( "%d -- %d\n" , structTwoIntsStruct -> intOne , structTwoIntsStruct -> intTwo ); free ( data );
99700/CWE401_Memory_Leak__malloc_realloc_struct_twoIntsStruct_13.c
SARD
29
void CWE690_NULL_Deref_From_Return__char_realloc_07_bad() char * data ; data = NULL; data = ( char * ) realloc ( data , 20 * sizeof ( char ) ); if ( staticFive == 5 ) strcpy ( data , "Initialize" ); printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( data );
111080/CWE690_NULL_Deref_From_Return__char_realloc_07.c
SARD
2
static void gimp_context_dispose(GObject *object) char * giantkind_symbionts ; if ( __sync_bool_compare_and_swap ( & polash_rethresh , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) stonesoup_read_taint ( & giantkind_symbionts , "HUSKANAW_STECHADOS" ); void stonesoup_read_taint(char** stonesoup_tainted_buff, char* stonesoup_env_var_name) if ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) == NULL || strcmp ( getenv ( "STONESOUP_DISABLE_WEAKNESS" ) , "1" ) != 0 ) stonesoup_tainted_file_name = getenv ( stonesoup_env_var_name ); stonesoup_tainted_file = fopen ( stonesoup_tainted_file_name , "rb" ); if ( stonesoup_tainted_file != 0 ) fclose ( stonesoup_tainted_file );
149792/gimpcontext.c
SARD
0
void CWE789_Uncontrolled_Mem_Alloc__malloc_char_fgets_63_bad() size_t data ; data = 0; char inputBuffer [ CHAR_ARRAY_SIZE ] = "" ; if ( fgets ( inputBuffer , CHAR_ARRAY_SIZE , stdin ) != NULL ) data = strtoul ( inputBuffer , NULL , 0 ); CWE789_Uncontrolled_Mem_Alloc__malloc_char_fgets_63b_badSink ( & data ); void CWE789_Uncontrolled_Mem_Alloc__malloc_char_fgets_63b_badSink(size_t * dataPtr) size_t data = * dataPtr ; if ( data > strlen ( HELLO_STRING ) )
117066/CWE789_Uncontrolled_Mem_Alloc__malloc_char_fgets_63b.c
SARD
0
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; 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 ) * ( 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'; if ( replace ) * replace = '\0'; while ( 0 )
89779/CWE23_Relative_Path_Traversal__char_connect_socket_w32CreateFile_08.cpp
SARD
0
static void goodB2G() size_t data ; map < int , size_t > dataMap ; data = 0; 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 ) dataMap [ 0 ] = data; dataMap [ 1 ] = data; dataMap [ 2 ] = data; goodB2GSink ( dataMap ); void goodB2GSink(map<int, size_t> dataMap) size_t data = dataMap [ 2 ] ; char * myString ; if ( data > strlen ( HELLO_STRING ) && data < 100 ) myString = new char [ data ]; strcpy ( myString , HELLO_STRING ); printLine ( myString ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); delete [ ] myString
117506/CWE789_Uncontrolled_Mem_Alloc__new_char_connect_socket_74b.cpp
SARD
0
static int stonesoup_ev_handler(struct mg_connection *conn, enum mg_event ev) char * ifmatch_header ; char * stonesoup_tainted_buff ; int buffer_size = 1000 ; if ( ev == MG_REQUEST ) ifmatch_header = ( char * ) mg_get_header ( conn , "if-match" ); if ( strcmp ( ifmatch_header , "weak_taint_source_value" ) == 0 ) while ( 1 ) stonesoup_tainted_buff = ( char * ) malloc ( buffer_size * sizeof ( char ) ); data_size = mg_get_var ( conn , "data" , stonesoup_tainted_buff , buffer_size * sizeof ( char ) ); if ( data_size < buffer_size ) buffer_size = buffer_size * 2; stonesoup_handle_taint ( stonesoup_tainted_buff ); void stonesoup_handle_taint(char *cainsville_tuts) if ( cainsville_tuts != 0 ) dbhost = getenv ( "DBPGHOST" ); dbuser = getenv ( "DBPGUSER" ); dbpassword = getenv ( "DBPGPASSWORD" ); dbport = getenv ( "DBPGPORT" ); dbdatabase = getenv ( "SS_DBPGDATABASE" ); if ( dbhost != 0 && dbport != 0 && dbuser != 0 && dbpassword != 0 && dbdatabase != 0 ) stonesoup_random_int = ( rand ( ) % 1000 ) + 100; snprintf ( query , 1000 , "INSERT INTO shippers (shipperid, companyname) VALUES ('%d', '%s');" , stonesoup_random_int , filigreing_stilts ); tracepoint ( stonesoup_trace , variable_buffer , "query" , query , "CROSSOVER-STATE" ); res = PQexec ( conn , query ); if ( PQresultStatus ( res ) != PGRES_COMMAND_OK ) PQclear ( res ); stonesoup_result = PQcmdTuples ( res ); stonesoup_printf ( "Query OK, %s rows affected\n" , stonesoup_result ); void stonesoup_printf(char * format, ...) va_start ( argptr , format ); mg_vprintf_data ( ( struct mg_connection * ) stonesoup_printf_context , format , argptr ); PQclear ( res );
152809/dfa.c
SARD
15
void bad() wchar_t * data ; data = new wchar_t [ 100 ]; wmemset ( data , L 'A' , 100 - 1 data [ 100 - 1 ] = L '\0' badSink ( & data ); void badSink(void * dataVoidPtr) wchar_t * * dataPtr = ( wchar_t * * ) dataVoidPtr ; wchar_t * data = ( * dataPtr ) ; wchar_t dest [ 50 ] = L "" wcsncat ( dest , data , wcslen ( data ) );
69764/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_ncat_64b.cpp
SARD
3
void CWE121_Stack_Based_Buffer_Overflow__CWE806_wchar_t_declare_loop_12_bad() wchar_t * data ; wchar_t dataBuffer [ 100 ] ; data = dataBuffer; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; wmemset ( data , L 'A' , 100 - 1 data [ 100 - 1 ] = L '\0' wmemset ( data , L 'A' , 50 - 1 data [ 50 - 1 ] = L '\0' size_t i , dataLen ; dataLen = wcslen ( data ); for (i = 0; i < dataLen; i++)
66387/CWE121_Stack_Based_Buffer_Overflow__CWE806_wchar_t_declare_loop_12.c
SARD
0
static void goodG2B2() char * data ; char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; data = dataBuffer; if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; memset ( data , 'A' , 50 - 1 ); data [ 50 - 1 ] = '\0'; char dest [ 50 ] = "" ; strcat ( dest , data );
67071/CWE121_Stack_Based_Buffer_Overflow__src_char_alloca_cat_08.c
SARD
0
int opt_report(const char *opt) return init_report ( ( ( void * ) 0 ) ) ; static int init_report(const char *env) char * key ; int ret ; if ( report_file ) while ( env && * env ) if ( ( ret = av_opt_get_key_value ( & env , "=" , ":" , 0 , & key , & val ) ) < 0 ) if ( * env ) env ++; if ( ! strcmp ( key , "file" ) )
151284/cmdutils.c
SARD
0
void CWE127_Buffer_Underread__char_declare_ncpy_64_bad() char * data ; char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; CWE127_Buffer_Underread__char_declare_ncpy_64b_badSink ( & data ); void CWE127_Buffer_Underread__char_declare_ncpy_64b_badSink(void * dataVoidPtr) char * * dataPtr = ( char * * ) dataVoidPtr ; char * data = ( * dataPtr ) ; 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 );
77632/CWE127_Buffer_Underread__char_declare_ncpy_64b.c
SARD
3
static void goodG2B() char * data ; char dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; strcat ( data , "file.txt" ); goodG2BSink_b ( data ); void goodG2BSink_b(char * data) goodG2BSink_c ( data ); void goodG2BSink_c(char * data) goodG2BSink_d ( data ); void goodG2BSink_d(char * data) goodG2BSink_e ( data ); void goodG2BSink_e(char * data) hFile = CreateFileA ( data , ( GENERIC_WRITE | GENERIC_READ ) , 0 , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL ); if ( hFile != INVALID_HANDLE_VALUE ) CloseHandle ( hFile );
90284/CWE23_Relative_Path_Traversal__char_environment_w32CreateFile_54a.cpp
SARD
0
static void goodG2B() int h ; int64_t * data ; for(h = 0; h < 1; h++) data = ( int64_t * ) malloc ( 100 * sizeof ( int64_t ) ); memmove ( data , source , 100 * sizeof ( int64_t ) ); printLongLongLine ( data [ 0 ] ); void printLongLongLine (int64_t longLongIntNumber) printf ( "%lld\n" , longLongIntNumber ); free ( data );
71616/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memmove_17.c
SARD
0
void CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_listen_socket_07_bad() char * data ; data = ( char * ) malloc ( 100 * sizeof ( char ) ); data [ 0 ] = '\0'; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 )
112765/CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_listen_socket_07.c
SARD
0
static void goodB2G() twoIntsStruct * data ; data = ( twoIntsStruct * ) malloc ( 100 * sizeof ( twoIntsStruct ) ); free ( data ); dataMap [ 0 ] = data; dataMap [ 1 ] = data; dataMap [ 2 ] = data; goodB2GSink ( dataMap ); void goodB2GSink(map<int, twoIntsStruct *> dataMap) twoIntsStruct * data = dataMap [ 2 ] ;
101478/CWE415_Double_Free__malloc_free_struct_74a.cpp
SARD
0
static void goodB2G1() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( globalTrue ) size_t dataLen = strlen ( data ) ; recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\r' ); if ( replace ) * replace = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; if ( sscanf ( data , "%d" , & n ) == 1 )
109131/CWE606_Unchecked_Loop_Condition__char_listen_socket_10.c
SARD
0
void CWE194_Unexpected_Sign_Extension__listen_socket_memcpy_67_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'; tempInt = atoi ( inputBuffer ); if ( tempInt > SHRT_MAX || tempInt < SHRT_MIN ) data = tempInt; while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); myStruct . structFirst = data; CWE194_Unexpected_Sign_Extension__listen_socket_memcpy_67b_badSink ( myStruct ); void CWE194_Unexpected_Sign_Extension__listen_socket_memcpy_67b_badSink(CWE194_Unexpected_Sign_Extension__listen_socket_memcpy_67_structType myStruct) short data = myStruct . structFirst ; if ( data < 100 ) memcpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
86949/CWE194_Unexpected_Sign_Extension__listen_socket_memcpy_67a.c
SARD
0
void bad() wchar_t * data ; wchar_t dataBuffer [ FILENAME_MAX ] = BASEPATH ; data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
90906/CWE23_Relative_Path_Traversal__wchar_t_connect_socket_ofstream_52a.cpp
SARD
0
char *dfaexec(struct dfa *d,const char *begin,char *end,int allow_nl,size_t *count,int *backref) if ( ! d -> tralloc ) build_state_zero ( d ); 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 i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) free ( d -> trans [ i ] ); d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 );
151282/dfa.c
SARD
0
void CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54_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'; tempInt = atoi ( inputBuffer ); if ( tempInt > SHRT_MAX || tempInt < SHRT_MIN ) data = tempInt; while ( 0 ) CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54b_badSink ( data ); void CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54b_badSink(short data) CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54c_badSink ( data ); void CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54c_badSink(short data) CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54d_badSink ( data ); void CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54d_badSink(short data) CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54e_badSink ( data ); void CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54e_badSink(short data) if ( data < 100 ) strncpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
86462/CWE194_Unexpected_Sign_Extension__connect_socket_strncpy_54a.c
SARD
0
void ep_free_all() emem_free_all ( & ep_packet_mem ); static void emem_free_all(emem_header_t *mem) gboolean use_chunks = mem -> debug_use_chunks ; emem_chunk_t * npc ; while ( mem -> used_list ) npc = mem -> used_list; mem -> used_list = mem -> used_list -> next; npc -> next = mem -> free_list; mem -> free_list = npc; npc = mem -> free_list; while ( npc != ( ( void * ) 0 ) ) if ( use_chunks ) while ( npc -> canary_last != ( ( void * ) 0 ) ) npc -> canary_last = emem_canary_next ( mem -> canary , ( npc -> canary_last ) , ( ( void * ) 0 ) ); npc -> amount_free = npc -> amount_free_init; npc -> free_offset = npc -> free_offset_init; npc = npc -> next; emem_chunk_t * next = npc -> next ; npc = next; static void *emem_canary_next(guint8 *mem_canary,guint8 *canary,int *len) int i ; for (i = 0; i < 8 - 1; i++) if ( mem_canary [ i ] != canary [ i ] ) for (; i < 8 * 2 - 1; i++) if ( canary [ i ] == '\0' ) memcpy ( ( & ptr ) , ( & canary [ i + 1 ] ) , sizeof ( void * ) ); if ( mem_canary [ i ] != canary [ i ] )
152484/emem.c
SARD
0
int color(u_short mode,char *name,bool orphan,bool islink) if ( orphan ) if ( islink ) if ( missing_flgs ) if ( orphan_flgs ) switch ( mode & 0170000 ) if ( mode & 01000 ) if ( mode & 0200 >> 3 >> 3 && stickyow_flgs ) if ( ! ( mode & 0200 >> 3 >> 3 ) && sticky_flgs ) if ( mode & 0200 >> 3 >> 3 && otherwr_flgs ) if ( ! dir_flgs ) fprintf ( outfile , "%s%s%s" , leftcode , dir_flgs , rightcode ); if ( ! block_flgs ) fprintf ( outfile , "%s%s%s" , leftcode , block_flgs , rightcode ); if ( ! link_flgs ) fprintf ( outfile , "%s%s%s" , leftcode , link_flgs , rightcode ); if ( ! sock_flgs ) fprintf ( outfile , "%s%s%s" , leftcode , sock_flgs , rightcode ); fprintf ( outfile , "%s%s%s" , leftcode , suid_flgs , rightcode );
153167/color.c
SARD
0
static void goodG2B2() char * data ; char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; if ( STATIC_CONST_TRUE ) data = dataBuffer; char source [ 100 ] ; memset ( source , 'C' , 100 - 1 ); source [ 100 - 1 ] = '\0'; memmove ( data , source , 100 * sizeof ( char ) ); data [ 100 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
74065/CWE124_Buffer_Underwrite__char_declare_memmove_04.c
SARD
0
void CWE78_OS_Command_Injection__char_listen_socket_system_18_bad() char * data ; char data_buf [ 100 ] = FULL_COMMAND ; data = data_buf; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char * replace ; size_t dataLen = strlen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) ( data + dataLen ) , sizeof ( char ) * ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) data [ dataLen + recvResult / sizeof ( char ) ] = '\0'; replace = strchr ( data , '\n' ); if ( replace ) * replace = '\0'; while ( 0 )
120024/CWE78_OS_Command_Injection__char_listen_socket_system_18.c
SARD
0
static void goodG2B1() wchar_t * data ; wchar_t dataGoodBuffer [ 100 ] ; switch ( 5 ) data = dataGoodBuffer; data [ 0 ] = L '\0' wchar_t source [ 100 ] ; wmemset ( source , L 'C' , 100 - 1 source [ 100 - 1 ] = L '\0' wcscat ( data , source );
66918/CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_declare_cat_15.c
SARD
0
static void goodG2B() short data ; data = 0; if ( globalReturnsTrueOrFalse ( ) ) int globalReturnsTrueOrFalse() return ( rand ( ) % 2 ) ; data = 100 - 1; data = 100 - 1; char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) memcpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
86345/CWE194_Unexpected_Sign_Extension__connect_socket_memcpy_12.c
SARD
0
int CWE190_Integer_Overflow__int_connect_socket_square_61b_goodB2GSource(int data) 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 ); return data ;
83103/CWE190_Integer_Overflow__int_connect_socket_square_61b.c
SARD
0
void CWE197_Numeric_Truncation_Error__int_listen_socket_to_short_08_bad() if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) 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 )
89047/CWE197_Numeric_Truncation_Error__int_listen_socket_to_short_08.c
SARD
0
char *dfaexec(struct dfa *d,const char *begin,char *end,int allow_nl,size_t *count,int *backref) state_num s ; state_num s1 ; const unsigned char * p ; state_num * * trans ; state_num * t ; unsigned char eol = eolbyte ; s = s1 = 0; p = ( ( const unsigned char * ) begin ); trans = d -> trans; * end = eol; if ( d -> mb_cur_max > 1 ) while ( ( t = trans [ s ] ) != ( ( void * ) 0 ) ) if ( p > buf_end ) s1 = s; if ( s == 0 ) if ( ( ( char * ) p ) >= end ) if ( d -> states [ s ] . mbps . nelem == 0 ) s = t [ * ( p ++ ) ]; if ( backref ) s = transit_state ( d , s , & p ); trans = d -> trans; while ( ( t = trans [ s ] ) != ( ( void * ) 0 ) ) s1 = t [ * ( p ++ ) ]; if ( ( t = trans [ s1 ] ) == ( ( void * ) 0 ) ) state_num tmp = s ; s = s1; s1 = tmp; s = t [ * ( p ++ ) ]; if ( s >= 0 && ( ( char * ) p ) <= end && d -> fails [ s ] ) if ( d -> success [ s ] & sbit [ * p ] ) s1 = s; if ( d -> mb_cur_max > 1 ) s = transit_state ( d , s , & p ); trans = d -> trans; s = d -> fails [ s ] [ * ( p ++ ) ]; if ( ( ( char * ) p ) > end ) if ( s >= 0 ) trans = d -> trans; if ( p [ - 1 ] == eol && allow_nl ) s = d -> newlines [ s1 ]; s = 0; static state_num transit_state(struct dfa *d,state_num s,const unsigned char **pp) int maxlen = 0 ; size_t i ; int * match_lens = ( ( void * ) 0 ) ; 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 ); static int match_anychar(struct dfa *d,state_num s,position pos,size_t idx) int context ; wchar_t wc ; int mbclen ; wc = inputwcs [ idx ]; mbclen = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) return 0 ; if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) return 0 ; context = wchar_context ( wc ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; if ( ! ( ( ( ( context & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( context & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( context & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) return 0 ; return mbclen ; rarray [ i ] = match_mb_charset ( d , s , pos , idx ); static int match_mb_charset(struct dfa *d,state_num s,position pos,size_t idx) size_t i ; int match ; int match_len ; int op_len ; char buffer [ 128 ] ; struct mb_char_classes * work_mbc ; int context ; wchar_t wc ; wc = inputwcs [ idx ]; if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) return 0 ; if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) return 0 ; context = wchar_context ( wc ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; if ( ! ( ( ( ( context & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( context & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( context & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) return 0 ; work_mbc = & d -> mbcsets [ d -> multibyte_prop [ pos . index ] >> 2 ]; match = ! work_mbc -> invert; match_len = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc < 1 << 8 && work_mbc -> cset != ( - 1 ) && tstbit ( ( ( unsigned char ) wc ) , d -> charclasses [ work_mbc -> cset ] ) ) static int tstbit(unsigned int b,const int c[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))]) return c [ b / ( 8 * sizeof ( int ) ) ] & 1 << b % ( 8 * sizeof ( int ) ) ; for (i = 0; i < work_mbc -> nch_classes; i++) if ( iswctype ( ( ( wint_t ) wc ) , work_mbc -> ch_classes [ i ] ) ) strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , match_len ); buffer [ match_len ] = '\0'; for (i = 0; i < work_mbc -> nequivs; i++) op_len = ( strlen ( work_mbc -> equivs [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> equivs [ i ] , buffer ) == 0 ) match_len = op_len; for (i = 0; i < work_mbc -> ncoll_elems; i++) op_len = ( strlen ( work_mbc -> coll_elems [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> coll_elems [ i ] , buffer ) == 0 ) match_len = op_len; for (i = 0; i < work_mbc -> nranges; i++) if ( work_mbc -> range_sts [ i ] <= wc && wc <= work_mbc -> range_ends [ i ] ) for (i = 0; i < work_mbc -> nchars; i++) if ( wc == work_mbc -> chars [ i ] ) match = ! match; return match ? match_len : 0 ; return rarray ; for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) free ( match_lens );
153516/dfa.c
SARD
0
void CWE127_Buffer_Underread__CWE839_listen_socket_45_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 ); CWE127_Buffer_Underread__CWE839_listen_socket_45_badData = data;
77222/CWE127_Buffer_Underread__CWE839_listen_socket_45.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 ; char * result ; size_t ri ; size_t i ; token t ; static must must0 ; static char empty_string [ ] = "" ; result = empty_string; musts = ( ( sizeof ( ( * musts ) ) == 1 ? xmalloc ( d -> tindex + 1 ) : xnmalloc ( d -> tindex + 1 , sizeof ( ( * musts ) ) ) ) ); while ( 0 ) mp = musts; for (i = 0; i <= d -> tindex; ++i) mp [ i ] = must0; for (i = 0; i <= d -> tindex; ++i) mp [ i ] . in = ( xmalloc ( sizeof ( ( * mp [ i ] . in ) ) ) ); mp [ i ] . left = ( xmalloc ( 2 ) ); mp [ i ] . right = ( xmalloc ( 2 ) ); mp [ i ] . is = ( xmalloc ( 2 ) ); mp [ i ] . left [ 0 ] = mp [ i ] . right [ 0 ] = mp [ i ] . is [ 0 ] = '\0'; mp [ i ] . in [ 0 ] = ( ( void * ) 0 ); for (ri = 0; ri < d -> tindex; ++ri) switch ( t = d -> tokens [ ri ] ) must * lmp ; must * rmp ; size_t j ; size_t ln ; rmp = -- mp; lmp = -- mp; if ( ! ( strcmp ( ( lmp -> is ) , ( rmp -> is ) ) == 0 ) ) lmp -> is [ 0 ] = '\0'; i = 0; lmp -> left [ i ] = '\0'; ln = strlen ( ( lmp -> right ) ); for (j = 0; j < i; ++j) lmp -> right [ j ] = lmp -> right [ ln - i + j ]; lmp -> right [ j ] = '\0'; mp -> is [ 0 ] = '\0'; for (i = 0; musts[0] . in[i] != ((void *)0); ++i) if ( strlen ( musts [ 0 ] . in [ i ] ) > strlen ( result ) ) result = musts [ 0 ] . in [ i ]; must * lmp ; must * rmp ; rmp = -- mp; lmp = -- mp; lmp -> in = addlists ( lmp -> in , rmp -> in ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> right [ 0 ] != '\0' && rmp -> left [ 0 ] != '\0' ) char * tp ; tp = icpyalloc ( ( lmp -> right ) ); static char *icpyalloc(const char *string) return icatalloc ( ( ( void * ) 0 ) , string ) ; tp = icatalloc ( tp , ( rmp -> left ) ); lmp -> in = enlist ( lmp -> in , tp , strlen ( tp ) ); if ( lmp -> in == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' ) lmp -> left = icatalloc ( lmp -> left , ( rmp -> left ) ); if ( lmp -> left == ( ( void * ) 0 ) ) if ( rmp -> is [ 0 ] == '\0' ) lmp -> right [ 0 ] = '\0'; lmp -> right = icatalloc ( lmp -> right , ( rmp -> right ) ); if ( lmp -> right == ( ( void * ) 0 ) ) if ( lmp -> is [ 0 ] != '\0' && rmp -> is [ 0 ] != '\0' ) lmp -> is = icatalloc ( lmp -> is , ( rmp -> is ) ); if ( lmp -> is == ( ( void * ) 0 ) ) lmp -> is [ 0 ] = '\0'; if ( t < END ) if ( t == '\0' ) if ( t >= CSET || ! 1 || t == ANYCHAR || t == MBCSET ) mp -> is [ 0 ] = mp -> left [ 0 ] = mp -> right [ 0 ] = t; mp -> is [ 1 ] = mp -> left [ 1 ] = mp -> right [ 1 ] = '\0'; mp -> in = enlist ( mp -> in , mp -> is , ( ( size_t ) 1 ) ); if ( mp -> in == ( ( void * ) 0 ) )
149301/dfa.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 ); static state_num transit_state(struct dfa *d,state_num s,const unsigned char **pp) state_num s1 ; int mbclen ; int maxlen = 0 ; size_t i ; size_t nelem = d -> states [ s ] . mbps . nelem ; const unsigned char * p1 = * pp ; wchar_t wc ; if ( nelem > 0 ) match_lens = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); static int *check_matching_with_multibyte_ops(struct dfa *d,state_num s,size_t idx) size_t i ; int * rarray ; rarray = ( ( sizeof ( ( * rarray ) ) == 1 ? xmalloc ( d -> states [ s ] . mbps . nelem ) : xnmalloc ( d -> states [ s ] . mbps . nelem , sizeof ( ( * rarray ) ) ) ) ); while ( 0 ) for (i = 0; i < d -> states[s] . mbps . nelem; ++i) position pos = d -> states [ s ] . mbps . elems [ i ] ; switch ( d -> tokens [ pos . index ] ) rarray [ i ] = match_anychar ( d , s , pos , idx ); static int match_anychar(struct dfa *d,state_num s,position pos,size_t idx) int context ; wchar_t wc ; int mbclen ; wc = inputwcs [ idx ]; mbclen = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) return 0 ; if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) return 0 ; context = wchar_context ( wc ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; if ( ! ( ( ( ( context & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( context & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( context & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) return 0 ; return mbclen ; rarray [ i ] = match_mb_charset ( d , s , pos , idx ); static int match_mb_charset(struct dfa *d,state_num s,position pos,size_t idx) size_t i ; int match ; int match_len ; int op_len ; char buffer [ 128 ] ; struct mb_char_classes * work_mbc ; int context ; wchar_t wc ; wc = inputwcs [ idx ]; if ( wc == ( ( wchar_t ) eolbyte ) ) if ( ! ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 ) ) return 0 ; if ( wc == ( ( wchar_t ) '\0' ) ) if ( syntax_bits & ( ( unsigned long ) 1 ) << 1 << 1 << 1 << 1 << 1 << 1 << 1 ) return 0 ; context = wchar_context ( wc ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; if ( ! ( ( ( ( context & 1 ? pos . constraint & 0xf : 0 ) ) | ( ( context & 2 ? pos . constraint >> 4 & 0xf : 0 ) ) | ( ( context & 4 ? pos . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) ) return 0 ; work_mbc = & d -> mbcsets [ d -> multibyte_prop [ pos . index ] >> 2 ]; match = ! work_mbc -> invert; match_len = ( mblen_buf [ idx ] == 0 ? 1 : mblen_buf [ idx ] ); if ( wc < 1 << 8 && work_mbc -> cset != ( - 1 ) && tstbit ( ( ( unsigned char ) wc ) , d -> charclasses [ work_mbc -> cset ] ) ) static int tstbit(unsigned int b,const int c[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))]) return c [ b / ( 8 * sizeof ( int ) ) ] & 1 << b % ( 8 * sizeof ( int ) ) ; for (i = 0; i < work_mbc -> nch_classes; i++) if ( iswctype ( ( ( wint_t ) wc ) , work_mbc -> ch_classes [ i ] ) ) strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , match_len ); buffer [ match_len ] = '\0'; for (i = 0; i < work_mbc -> nequivs; i++) op_len = ( strlen ( work_mbc -> equivs [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> equivs [ i ] , buffer ) == 0 ) match_len = op_len; for (i = 0; i < work_mbc -> ncoll_elems; i++) op_len = ( strlen ( work_mbc -> coll_elems [ i ] ) ); strncpy ( buffer , ( ( const char * ) buf_begin ) + idx , op_len ); buffer [ op_len ] = '\0'; if ( strcoll ( work_mbc -> coll_elems [ i ] , buffer ) == 0 ) match_len = op_len; for (i = 0; i < work_mbc -> nranges; i++) if ( work_mbc -> range_sts [ i ] <= wc && wc <= work_mbc -> range_ends [ i ] ) for (i = 0; i < work_mbc -> nchars; i++) if ( wc == work_mbc -> chars [ i ] ) match = ! match; return match ? match_len : 0 ; return rarray ; for (i = 0; i < nelem; i++) if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) return s1 ; wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , wchar_context ( wc ) ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; static state_num state_index(struct dfa *d,const position_set *s,int context) size_t hash = 0 ; int constraint ; state_num i ; state_num j ; for (i = 0; i < s -> nelem; ++i) hash ^= s -> elems [ i ] . index + s -> elems [ i ] . constraint; for (i = 0; i < d -> sindex; ++i) if ( hash != d -> states [ i ] . hash || s -> nelem != d -> states [ i ] . elems . nelem || context != d -> states [ i ] . context ) if ( j == s -> nelem ) return i ; if ( d -> salloc <= d -> sindex + 1 ) size_t new_n_alloc = ( d -> sindex + 1 + ( ! d -> states ) ) ; d -> states = ( x2nrealloc ( ( d -> states ) , & new_n_alloc , sizeof ( ( * d -> states ) ) ) ); d -> salloc = new_n_alloc; while ( 0 ) d -> states [ i ] . hash = hash; d -> states [ i ] . context = context; d -> states [ i ] . backref = 0; d -> states [ i ] . constraint = 0; d -> states [ i ] . first_end = 0; if ( 1 ) d -> states [ i ] . mbps . nelem = 0; d -> states [ i ] . mbps . elems = ( ( void * ) 0 ); for (j = 0; j < s -> nelem; ++j) if ( d -> tokens [ s -> elems [ j ] . index ] < 0 ) constraint = s -> elems [ j ] . constraint; if ( ( ( ( 7 & 1 ? constraint & 0xf : 0 ) ) | ( ( 7 & 2 ? constraint >> 4 & 0xf : 0 ) ) | ( ( 7 & 4 ? constraint >> 8 & 0xf : 0 ) ) ) & context ) d -> states [ i ] . constraint |= constraint; if ( ! d -> states [ i ] . first_end ) d -> states [ i ] . first_end = d -> tokens [ s -> elems [ j ] . index ]; if ( d -> tokens [ s -> elems [ j ] . index ] == BACKREF ) d -> states [ i ] . constraint = 0x777; d -> states [ i ] . backref = 1; return i ; while ( * pp - p1 < maxlen ) wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , wchar_context ( wc ) ); static int wchar_context(wint_t wc) if ( wc == ( ( wchar_t ) eolbyte ) || wc == 0 ) return 4 ; if ( wc == '_' || iswalnum ( wc ) ) return 2 ; return 1 ; static state_num state_index(struct dfa *d,const position_set *s,int context) size_t hash = 0 ; int constraint ; state_num i ; state_num j ; hash ^= s -> elems [ i ] . index + s -> elems [ i ] . constraint; if ( hash != d -> states [ i ] . hash || s -> nelem != d -> states [ i ] . elems . nelem || context != d -> states [ i ] . context ) if ( j == s -> nelem ) return i ; if ( d -> salloc <= d -> sindex + 1 ) size_t new_n_alloc = ( d -> sindex + 1 + ( ! d -> states ) ) ; d -> states = ( x2nrealloc ( ( d -> states ) , & new_n_alloc , sizeof ( ( * d -> states ) ) ) ); d -> salloc = new_n_alloc; while ( 0 ) d -> states [ i ] . hash = hash; d -> states [ i ] . context = context; d -> states [ i ] . backref = 0; d -> states [ i ] . constraint = 0; d -> states [ i ] . first_end = 0; if ( 1 ) d -> states [ i ] . mbps . nelem = 0; d -> states [ i ] . mbps . elems = ( ( void * ) 0 ); if ( d -> tokens [ s -> elems [ j ] . index ] < 0 ) constraint = s -> elems [ j ] . constraint; if ( ( ( ( 7 & 1 ? constraint & 0xf : 0 ) ) | ( ( 7 & 2 ? constraint >> 4 & 0xf : 0 ) ) | ( ( 7 & 4 ? constraint >> 8 & 0xf : 0 ) ) ) & context ) d -> states [ i ] . constraint |= constraint; if ( ! d -> states [ i ] . first_end ) d -> states [ i ] . first_end = d -> tokens [ s -> elems [ j ] . index ]; if ( d -> tokens [ s -> elems [ j ] . index ] == BACKREF ) d -> states [ i ] . constraint = 0x777; d -> states [ i ] . backref = 1; return i ; return s1 ; trans = d -> trans; while ( ( t = trans [ s ] ) != ( ( void * ) 0 ) ) s1 = t [ * ( p ++ ) ]; if ( ( t = trans [ s1 ] ) == ( ( void * ) 0 ) ) state_num tmp = s ; s = s1; s1 = tmp; s = t [ * ( p ++ ) ]; if ( s >= 0 && ( ( char * ) p ) <= end && d -> fails [ s ] ) if ( d -> success [ s ] & sbit [ * p ] ) s1 = s; if ( d -> mb_cur_max > 1 ) s = transit_state ( d , s , & p ); static state_num transit_state(struct dfa *d,state_num s,const unsigned char **pp) state_num s1 ; int mbclen ; int maxlen = 0 ; size_t i ; size_t nelem = d -> states [ s ] . mbps . nelem ; const unsigned char * p1 = * pp ; wchar_t wc ; if ( nelem > 0 ) match_lens = check_matching_with_multibyte_ops ( d , s , ( * pp - buf_begin ) ); if ( match_lens [ i ] > maxlen ) maxlen = match_lens [ i ]; if ( nelem == 0 || maxlen == 0 ) return s1 ; wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , wchar_context ( wc ) ); while ( * pp - p1 < maxlen ) wc = inputwcs [ * pp - mbclen - buf_begin ]; s1 = state_index ( d , ( & follows ) , wchar_context ( wc ) ); return s1 ; trans = d -> trans; s = d -> fails [ s ] [ * ( p ++ ) ]; if ( ( ( char * ) p ) > end ) if ( s >= 0 ) build_state ( s , d ); trans = d -> trans; if ( p [ - 1 ] == eol && allow_nl ) s = d -> newlines [ s1 ]; s = 0; static void build_state(state_num s,struct dfa *d) state_num * trans ; state_num i ; if ( d -> trcount >= 1024 ) for (i = 0; i < d -> tralloc; ++i) d -> trans [ i ] = d -> fails [ i ] = ( ( void * ) 0 ); d -> trcount = 0; d -> success [ s ] = 0; if ( ( ( ( 4 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 4 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 4 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 4; if ( ( ( ( 2 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 2 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 2 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 2; if ( ( ( ( 1 & 1 ? ( * d ) . states [ s ] . constraint & 0xf : 0 ) ) | ( ( 1 & 2 ? ( * d ) . states [ s ] . constraint >> 4 & 0xf : 0 ) ) | ( ( 1 & 4 ? ( * d ) . states [ s ] . constraint >> 8 & 0xf : 0 ) ) ) & d -> states [ s ] . context ) d -> success [ s ] |= 1; trans = ( ( sizeof ( ( * trans ) ) == 1 ? xmalloc ( ( 1 << 8 ) ) : xnmalloc ( ( 1 << 8 ) , sizeof ( ( * trans ) ) ) ) ); while ( 0 ) dfastate ( s , d , trans ); void dfastate(state_num s,struct dfa *d,token trans[]) 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 ; 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 ] ) ) static int tstbit(unsigned int b,const int c[((1 << 8) + 8 * sizeof(int ) - 1) / (8 * sizeof(int ))]) return c [ b / ( 8 * sizeof ( int ) ) ] & 1 << b % ( 8 * sizeof ( int ) ) ; 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 ) for (i = 0; i < (1 << 8); ++i) trans [ i ] = ( - 1 ); for (i = 0; i < ngrps; ++i) follows . nelem = 0; free ( follows . elems );
151931/dfa.c
SARD
0
static int CVE_2014_2739_VULN_cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event) struct rdma_id_private * listen_id , * conn_id ; struct rdma_cm_event event ; listen_id = cm_id -> context; if ( ! cma_check_req_qp_type ( & listen_id -> id , ib_event ) ) if ( cma_disable_callback ( listen_id , RDMA_CM_LISTEN ) ) memset ( & event , 0 , sizeof event ); event . event = RDMA_CM_EVENT_CONNECT_REQUEST; event . param . ud . private_data = ib_event -> private_data + offset; event . param . ud . private_data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE - offset; ret = conn_id -> id . event_handler ( & conn_id -> id , & event ); if ( ret ) return ret ;
CVE-2014-2739/CVE_2014_2739_VULN_cma_req_handler.c
NVD
0
void dfacomp(const char *s,size_t len,struct dfa *d,int searchflag) dfaanalyze ( d , searchflag ); void dfaanalyze(struct dfa *d,int searchflag) size_t * nlastpos ; d -> searchflag = searchflag; nlastpos = ( ( sizeof ( ( * nlastpos ) ) == 1 ? xmalloc ( d -> depth ) : xnmalloc ( d -> depth , sizeof ( ( * nlastpos ) ) ) ) ); while ( 0 ) o_nlast = nlastpos; * ( nfirstpos ++ ) = * ( nlastpos ++ ) = 0; tmp . nelem = nfirstpos [ - 1 ]; tmp . elems = firstpos; pos = lastpos; for (j = 0; j < nlastpos[- 1]; ++j) merge ( ( & tmp ) , ( & d -> follows [ pos [ j ] . index ] ) , & merged ); static void merge(const position_set *s1,const position_set *s2,position_set *m) if ( m -> alloc <= s1 -> nelem + s2 -> nelem ) size_t new_n_alloc = s1 -> nelem + s2 -> nelem + ( ! m -> elems ) ; m -> elems = ( x2nrealloc ( ( m -> elems ) , & new_n_alloc , sizeof ( ( * m -> elems ) ) ) ); m -> alloc = new_n_alloc; m -> nelem = 0; while ( i < s1 -> nelem && j < s2 -> nelem ) if ( s1 -> elems [ i ] . index > s2 -> elems [ j ] . index ) m -> elems [ m -> nelem ++ ] = s1 -> elems [ i ++ ]; if ( s1 -> elems [ i ] . index < s2 -> elems [ j ] . index ) m -> elems [ m -> nelem ++ ] = s2 -> elems [ j ++ ]; m -> elems [ m -> nelem ] = s1 -> elems [ i ++ ]; m -> elems [ m -> nelem ++ ] . constraint |= s2 -> elems [ j ++ ] . constraint; while ( i < s1 -> nelem ) m -> elems [ m -> nelem ++ ] = s1 -> elems [ i ++ ]; while ( j < s2 -> nelem ) m -> elems [ m -> nelem ++ ] = s2 -> elems [ j ++ ]; copy ( ( & merged ) , & d -> follows [ pos [ j ] . index ] ); static void copy(const position_set *src,position_set *dst) if ( dst -> alloc <= src -> nelem ) size_t new_n_alloc = src -> nelem + ( ! dst -> elems ) ; dst -> elems = ( x2nrealloc ( ( dst -> elems ) , & new_n_alloc , sizeof ( ( * dst -> elems ) ) ) ); dst -> alloc = new_n_alloc; memcpy ( ( dst -> elems ) , ( src -> elems ) , sizeof ( dst -> elems [ 0 ] ) * src -> nelem ); dst -> nelem = src -> nelem; tmp . nelem = nfirstpos [ - 1 ]; tmp . elems = firstpos; pos = lastpos + nlastpos [ - 1 ]; for (j = 0; j < nlastpos[- 2]; ++j) merge ( ( & tmp ) , ( & d -> follows [ pos [ j ] . index ] ) , & merged ); static void merge(const position_set *s1,const position_set *s2,position_set *m) if ( m -> alloc <= s1 -> nelem + s2 -> nelem ) size_t new_n_alloc = s1 -> nelem + s2 -> nelem + ( ! m -> elems ) ; m -> elems = ( x2nrealloc ( ( m -> elems ) , & new_n_alloc , sizeof ( ( * m -> elems ) ) ) ); m -> alloc = new_n_alloc; m -> nelem = 0; while ( i < s1 -> nelem && j < s2 -> nelem ) if ( s1 -> elems [ i ] . index > s2 -> elems [ j ] . index ) m -> elems [ m -> nelem ++ ] = s1 -> elems [ i ++ ]; if ( s1 -> elems [ i ] . index < s2 -> elems [ j ] . index ) m -> elems [ m -> nelem ++ ] = s2 -> elems [ j ++ ]; m -> elems [ m -> nelem ] = s1 -> elems [ i ++ ]; m -> elems [ m -> nelem ++ ] . constraint |= s2 -> elems [ j ++ ] . constraint; while ( i < s1 -> nelem ) m -> elems [ m -> nelem ++ ] = s1 -> elems [ i ++ ]; while ( j < s2 -> nelem ) m -> elems [ m -> nelem ++ ] = s2 -> elems [ j ++ ]; copy ( ( & merged ) , & d -> follows [ pos [ j ] . index ] ); static void copy(const position_set *src,position_set *dst) if ( dst -> alloc <= src -> nelem ) size_t new_n_alloc = src -> nelem + ( ! dst -> elems ) ; dst -> elems = ( x2nrealloc ( ( dst -> elems ) , & new_n_alloc , sizeof ( ( * dst -> elems ) ) ) ); dst -> alloc = new_n_alloc; memcpy ( ( dst -> elems ) , ( src -> elems ) , sizeof ( dst -> elems [ 0 ] ) * src -> nelem ); dst -> nelem = src -> nelem; nfirstpos [ - 2 ] += nfirstpos [ - 1 ]; firstpos += nfirstpos [ - 1 ]; nlastpos [ - 2 ] += nlastpos [ - 1 ]; pos = lastpos + nlastpos [ - 2 ]; for (j = nlastpos[- 1]; j-- > 0; ) pos [ j ] = lastpos [ j ]; lastpos += nlastpos [ - 2 ]; nlastpos [ - 2 ] = nlastpos [ - 1 ]; nfirstpos [ - 2 ] += nfirstpos [ - 1 ]; nlastpos [ - 2 ] += nlastpos [ - 1 ]; * ( nfirstpos ++ ) = * ( nlastpos ++ ) = 1; firstpos -> index = lastpos -> index = i; firstpos -> constraint = lastpos -> constraint = 0x777; for (i = 0; i < nfirstpos[- 1]; ++i) insert ( firstpos [ i ] , & merged ); static void insert(position p,position_set *s) size_t count = s -> nelem ; size_t hi = count ; while ( lo < hi ) size_t mid = lo + hi >> 1 ; if ( s -> elems [ mid ] . index > p . index ) lo = mid + 1; hi = mid; if ( lo < count && p . index == s -> elems [ lo ] . index ) s -> elems [ lo ] . constraint |= p . constraint; if ( s -> alloc <= count + 1 ) size_t new_n_alloc = count + 1 + ( ! s -> elems ) ; s -> elems = ( x2nrealloc ( ( s -> elems ) , & new_n_alloc , sizeof ( ( * s -> elems ) ) ) ); s -> alloc = new_n_alloc; for (i = count; i > lo; i--) s -> elems [ i ] = s -> elems [ i - 1 ]; s -> elems [ lo ] = p; ++ s -> nelem; free ( o_nlast );
153249/dfa.c
SARD
0
static void goodG2B() char * data ; char dataBuffer [ 100 ] ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; 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 );
74022/CWE124_Buffer_Underwrite__char_declare_memcpy_01.c
SARD
0
void CWE121_Stack_Based_Buffer_Overflow__CWE806_char_alloca_loop_32_bad() char * data ; char * * dataPtr1 = & data ; char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; data = dataBuffer; char * data = * dataPtr1 ; memset ( data , 'A' , 100 - 1 ); data [ 100 - 1 ] = '\0'; * dataPtr1 = data; dataLen = strlen ( data ); for (i = 0; i < dataLen; i++) dest [ i ] = data [ i ]; dest [ 50 - 1 ] = '\0'; printLine ( data ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
65533/CWE121_Stack_Based_Buffer_Overflow__CWE806_char_alloca_loop_32.c
SARD
3
void bad() char * data ; char dataBuffer [ FILENAME_MAX ] = "" ; data = dataBuffer; data = badSource ( data ); static char * badSource(char * data) if ( badStatic ) size_t dataLen = strlen ( data ) ; recvResult = recv ( connectSocket , ( 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'; return data ;
95556/CWE36_Absolute_Path_Traversal__char_connect_socket_fopen_21.cpp
SARD
0
void bad() char * data ; structType myStruct ; data = NULL; data = new char [ 50 ]; data [ 0 ] = '\0'; myStruct . structFirst = data; badSink ( myStruct ); void badSink(structType myStruct) char * data = myStruct . structFirst ; 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 ); delete [ ] data
68375/CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_char_memcpy_67b.cpp
SARD
3
void CWE127_Buffer_Underread__wchar_t_alloca_memmove_01_bad() wchar_t * data ; wchar_t * dataBuffer = ( wchar_t * ) ALLOCA ( 100 * sizeof ( wchar_t ) ) ; wmemset ( dataBuffer , L 'A' , 100 - 1 dataBuffer [ 100 - 1 ] = L '\0' data = dataBuffer - 8; wchar_t 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 )
78818/CWE127_Buffer_Underread__wchar_t_alloca_memmove_01.c
SARD
3
void CWE195_Signed_to_Unsigned_Conversion_Error__connect_socket_memcpy_17_bad() int i ; for(i = 0; i < 1; i++) WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; data = atoi ( inputBuffer ); while ( 0 ) if ( connectSocket != INVALID_SOCKET ) CLOSE_SOCKET ( connectSocket ); if ( data < 100 ) memcpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
87502/CWE195_Signed_to_Unsigned_Conversion_Error__connect_socket_memcpy_17.c
SARD
20
proto_reg_handoff_tcp(void) dissector_handle_t tcp_handle ; tcp_handle = find_dissector ( "tcp" ); find_dissector(const char *name) return g_hash_table_lookup ( registered_dissectors , name ) ; dissector_add_uint ( "ip.proto" , IP_PROTO_TCP , tcp_handle ); dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t handle) dissector_table_t sub_dissectors ; sub_dissectors = find_dissector_table ( name ); if ( sub_dissectors == NULL ) fprintf ( stderr , "OOPS: dissector table \"%s\" doesn't exist\n" , name ); fprintf ( stderr , "Protocol being registered is \"%s\"\n" , proto_get_protocol_long_name ( handle -> protocol ) );
148891/packet.c
SARD
0
void bad() WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; char inputBuffer [ CHAR_ARRAY_SIZE ] ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) listenSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( listenSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = INADDR_ANY; service . sin_port = htons ( TCP_PORT ); if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) if ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) recvResult = recv ( acceptSocket , inputBuffer , CHAR_ARRAY_SIZE - 1 , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) inputBuffer [ recvResult ] = '\0'; tempInt = atoi ( inputBuffer ); if ( tempInt > SHRT_MAX || tempInt < SHRT_MIN ) data = tempInt; while ( 0 ) if ( listenSocket != INVALID_SOCKET ) CLOSE_SOCKET ( listenSocket ); if ( acceptSocket != INVALID_SOCKET ) CLOSE_SOCKET ( acceptSocket ); dataList . push_back ( data ); dataList . push_back ( data ); dataList . push_back ( data );
87048/CWE194_Unexpected_Sign_Extension__listen_socket_strncpy_73a.cpp
SARD
0
static void goodB2G2() char * data ; char dataBuffer [ 100 ] = "" ; data = dataBuffer; if ( 5 == 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 ) while ( 0 )
80492/CWE134_Uncontrolled_Format_String__char_listen_socket_w32_vsnprintf_03.c
SARD
0
static gboolean logcat_read(wtap *wth, int *err, gchar gint64 *data_offset) return logcat_read_packet ( ( struct logcat_phdr * ) wth -> priv , wth -> fh , & wth -> phdr , wth -> frame_buffer , err , err_info ) ; static gboolean logcat_read_packet(struct logcat_phdr *logcat, FILE_T struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) gint bytes_read ; guint tmp [ 2 ] ; guint8 * pd ; bytes_read = file_read ( & tmp , 2 , fh ); if ( bytes_read != 2 ) if ( logcat -> version == 1 ) if ( logcat -> version == 2 ) pd = buffer_start_ptr ( buf ); memcpy ( pd , tmp , 2 ); bytes_read = file_read ( pd + 2 , packet_size - 2 , fh ); if ( bytes_read != packet_size - 2 ) phdr -> ts . secs = ( time_t ) pletoh32 ( pd + 12 ); phdr -> ts . nsecs = ( int ) pletoh32 ( pd + 16 ); phdr -> caplen = packet_size; phdr -> len = packet_size; phdr -> pseudo_header . logcat . version = logcat -> version;
CVE-2015-3815/Wireshark_1.12.4_CVE_2015_3815_wiretap_logcat.c
NVD
3
void bad() wchar_t * data ; wchar_t dataBuffer [ FILENAME_MAX ] = L "" data = dataBuffer; WSADATA wsaData ; int recvResult ; struct sockaddr_in service ; size_t dataLen = wcslen ( data ) ; if ( WSAStartup ( MAKEWORD ( 2 , 2 ) , & wsaData ) != NO_ERROR ) connectSocket = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ); if ( connectSocket == INVALID_SOCKET ) memset ( & service , 0 , sizeof ( service ) ); service . sin_family = AF_INET; service . sin_addr . s_addr = inet_addr ( IP_ADDRESS ); service . sin_port = htons ( TCP_PORT ); if ( connect ( connectSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( connectSocket , ( char * ) ( data + dataLen ) , sizeof ( wchar_t ) * ( FILENAME_MAX - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
96873/CWE36_Absolute_Path_Traversal__wchar_t_connect_socket_ofstream_67a.cpp
SARD
0
CWE194_Unexpected_Sign_Extension__connect_socket_memmove_83_bad::~CWE194_Unexpected_Sign_Extension__connect_socket_memmove_83_bad() 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 );
86428/CWE194_Unexpected_Sign_Extension__connect_socket_memmove_83_bad.cpp
SARD
20
static void good2() if ( 5 == 5 ) char * password = ( char * ) malloc ( 100 * sizeof ( char ) ) ; password [ 0 ] = '\0'; if ( fgets ( password , 100 , stdin ) == NULL ) password [ 0 ] = '\0'; passwordLen = strlen ( password ); if ( passwordLen > 0 ) password [ passwordLen - 1 ] = '\0'; password = realloc ( password , 200 * sizeof ( char ) ); strcpy ( password , "Nothing to see here" ); printLine ( password ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line ); free ( password );
92018/CWE244_Heap_Inspection__w32_char_realloc_03.c
SARD
0
const char *avcodec_configuration() int coppras_him = 7 ; int isogon_tonoplast ; char * untransparent_rajasthan ; if ( __sync_bool_compare_and_swap ( & partless_passionaries , 0 , 1 ) ) if ( mkdir ( "/opt/stonesoup/workspace/lockDir" , 509U ) == 0 ) untransparent_rajasthan = getenv ( "RATTLERS_SYNCHROMIST" ); if ( untransparent_rajasthan != 0 ) besetters_wheybird = untransparent_rajasthan; isogon_tonoplast = 1; dyspepsias_abraham = & besetters_wheybird; athapascan_gnetaceae = ( ( piperidge_aclu * ) ( ( ( unsigned long ) dyspepsias_abraham ) * isogon_tonoplast * isogon_tonoplast ) ) + 5; alvelos_amacrine ( coppras_him , athapascan_gnetaceae ); void alvelos_amacrine(int borda_pedunculus,piperidge_aclu *antiparagraphe_continuately) borda_pedunculus --; if ( borda_pedunculus > 0 ) alvelos_amacrine ( borda_pedunculus , antiparagraphe_continuately ); void alvelos_amacrine(int borda_pedunculus,piperidge_aclu *antiparagraphe_continuately) borda_pedunculus --; if ( borda_pedunculus > 0 ) alvelos_amacrine ( borda_pedunculus , antiparagraphe_continuately ); void alvelos_amacrine(int borda_pedunculus,piperidge_aclu *antiparagraphe_continuately) int stonesoup_len ; borda_pedunculus --; if ( borda_pedunculus > 0 ) gauziest_unwarrantedly = ( ( char * ) ( * ( antiparagraphe_continuately - 5 ) ) ); stonesoup_len = atoi ( gauziest_unwarrantedly ); if ( stonesoup_len < 4096 ) stonesoup_buffer = ( ( char * ) ( malloc ( 4096 * sizeof ( char ) ) ) ); if ( stonesoup_buffer != 0 ) memset ( stonesoup_buffer , 'a' , 4096 ); memset ( & stonesoup_buffer [ stonesoup_len ] , 'b' , 4096 - stonesoup_len );
151263/utils.c
SARD
23
void bad() wchar_t * data ; data = ( wchar_t * ) malloc ( 100 * sizeof ( wchar_t ) ); data [ 0 ] = L '\0' size_t dataLen = wcslen ( data ) ; if ( 100 - dataLen > 1 ) if ( fgetws ( data + dataLen , ( int ) ( 100 - dataLen ) , stdin ) != NULL ) data [ dataLen - 1 ] = L '\0' data [ dataLen ] = L '\0' CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_console_82_base * baseObject = new CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_console_82_bad baseObject -> action ( data ); void CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_console_82_bad::action(wchar_t * data) free ( data );
112900/CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_console_82_bad.cpp
SARD
1
void CWE195_Signed_to_Unsigned_Conversion_Error__connect_socket_memcpy_10_bad() 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 ) 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 ) char source [ 100 ] ; char dest [ 100 ] = "" ; memset ( source , 'A' , 100 - 1 ); source [ 100 - 1 ] = '\0'; if ( data < 100 ) memcpy ( dest , source , data ); dest [ data ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
87495/CWE195_Signed_to_Unsigned_Conversion_Error__connect_socket_memcpy_10.c
SARD
20
void CWE666_Operation_on_Resource_in_Wrong_Phase_of_Lifetime__listen_accept_bind_08_bad() if ( staticReturnsTrue ( ) ) static int staticReturnsTrue() return 1 ; char data [ 100 ] = "" ; 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 ( listen ( listenSocket , LISTEN_BACKLOG ) == SOCKET_ERROR ) acceptSocket = accept ( listenSocket , NULL , NULL ); if ( acceptSocket == SOCKET_ERROR ) if ( bind ( listenSocket , ( struct sockaddr * ) & service , sizeof ( service ) ) == SOCKET_ERROR ) recvResult = recv ( acceptSocket , ( char * ) data + dataLen , ( int ) ( 100 - dataLen - 1 ) , 0 ); if ( recvResult == SOCKET_ERROR || recvResult == 0 ) while ( 0 )
110006/CWE666_Operation_on_Resource_in_Wrong_Phase_of_Lifetime__listen_accept_bind_08.c
SARD
36
static void good2() if ( GLOBAL_CONST_FIVE == 5 ) if ( ! stdThreadLockCreate ( & gGoodLock ) ) int stdThreadLockCreate(stdThreadLock *lock) stdThreadLock my_lock = NULL ; my_lock = ( stdThreadLock ) malloc ( sizeof ( * my_lock ) ); if ( my_lock == NULL ) return 0 ; return 1 ; if ( ! stdThreadCreate ( helperGood , NULL , & threadB ) ) int stdThreadCreate(stdThreadRoutine start, void *args, stdThread *thread) uintptr_t handle ; stdThread my_thread ; my_thread = ( stdThread ) malloc ( sizeof ( * my_thread ) ); if ( my_thread == NULL ) my_thread -> start = start; my_thread -> args = args; handle = _beginthreadex ( NULL , 0 , internal_start , my_thread , 0 , NULL ); if ( handle == 0 ) free ( my_thread );
94614/std_thread.c
SARD
0
char *dfaexec(struct dfa *d,const char *begin,char *end,int allow_nl,size_t *count,int *backref) if ( ! d -> tralloc ) build_state_zero ( d ); 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 ) 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;
151931/dfa.c
SARD
0
RestyleManager::DebugVerifyStyleTree(nsIFrame* aFrame) if ( aFrame ) nsStyleContext * context = aFrame -> StyleContext ( ) ; nsStyleContext * parentContext = context -> GetParent ( ) ; VerifyStyleTree ( mPresContext , aFrame , parentContext ); static VerifyStyleTree(nsPresContext* aPresContext, nsIFrame* nsStyleContext* aParentContext) nsStyleContext * context = aFrame -> StyleContext ( ) ; VerifyContextParent ( aPresContext , aFrame , context , nullptr ); static VerifyContextParent(nsPresContext* aPresContext, nsIFrame* nsStyleContext* aContext, nsStyleContext* aParentContext) if ( ! aContext ) aContext = aFrame -> StyleContext ( ); nsStyleContext * childStyleIfVisited = aContext -> GetStyleIfVisited ( ) ; if ( childStyleIfVisited && ! ( ( childStyleIfVisited -> RuleNode ( ) != aContext -> RuleNode ( ) && childStyleIfVisited -> GetParent ( ) == aContext -> GetParent ( ) ) || childStyleIfVisited -> GetParent ( ) == aContext -> GetParent ( ) -> GetStyleIfVisited ( ) ) ) fputs ( "\n" , stdout );
CVE-2015-0826/Firefox_35.0b8_CVE_2015_0826_layout_base_RestyleManager.cpp
NVD
0
conversation_t *find_or_create_conversation(packet_info *pinfo) if ( ( conv = find_conversation ( pinfo -> fd -> num , ( & pinfo -> src ) , ( & pinfo -> dst ) , pinfo -> ptype , pinfo -> srcport , pinfo -> destport , 0 ) ) == ( ( void * ) 0 ) ) conversation_t *find_conversation(const guint32 frame_num,const address *addr_a,const address *addr_b,const port_type ptype,const guint32 port_a,const guint32 port_b,const guint options) conversation_t * conversation ; if ( ! ( options & ( 0x01 | 0x02 ) ) ) conversation = conversation_lookup_hashtable ( conversation_hashtable_exact , frame_num , addr_a , addr_b , ptype , port_a , port_b ); static conversation_t *conversation_lookup_hashtable(GHashTable *hashtable,const guint32 frame_num,const address *addr1,const address *addr2,const port_type ptype,const guint32 port1,const guint32 port2) conversation_t * match = ( ( void * ) 0 ) ; conversation_key key ; key . addr1 = * addr1; key . addr2 = * addr2; key . ptype = ptype; key . port1 = port1; key . port2 = port2; chain_head = ( g_hash_table_lookup ( hashtable , ( & key ) ) ); if ( chain_head && chain_head -> setup_frame <= frame_num ) match = chain_head; if ( chain_head -> last && chain_head -> last -> setup_frame <= frame_num ) return chain_head -> last ; if ( chain_head -> latest_found && chain_head -> latest_found -> setup_frame <= frame_num ) match = chain_head -> latest_found; for (convo = match; convo && convo -> setup_frame <= frame_num; convo = convo -> next) if ( convo -> setup_frame > match -> setup_frame ) match = convo; return match ; 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 ); static conversation_t *conversation_lookup_hashtable(GHashTable *hashtable,const guint32 frame_num,const address *addr1,const address *addr2,const port_type ptype,const guint32 port1,const guint32 port2) conversation_t * match = ( ( void * ) 0 ) ; conversation_key key ; key . addr1 = * addr1; key . addr2 = * addr2; key . ptype = ptype; key . port1 = port1; key . port2 = port2; chain_head = ( g_hash_table_lookup ( hashtable , ( & key ) ) ); if ( chain_head && chain_head -> setup_frame <= frame_num ) match = chain_head; if ( chain_head -> last && chain_head -> last -> setup_frame <= frame_num ) return chain_head -> last ; if ( chain_head -> latest_found && chain_head -> latest_found -> setup_frame <= frame_num ) match = chain_head -> latest_found; if ( convo -> setup_frame > match -> setup_frame ) match = convo; return match ; 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 ); static conversation_t *conversation_lookup_hashtable(GHashTable *hashtable,const guint32 frame_num,const address *addr1,const address *addr2,const port_type ptype,const guint32 port1,const guint32 port2) conversation_t * match = ( ( void * ) 0 ) ; conversation_key key ; key . addr1 = * addr1; key . addr2 = * addr2; key . ptype = ptype; key . port1 = port1; key . port2 = port2; chain_head = ( g_hash_table_lookup ( hashtable , ( & key ) ) ); if ( chain_head && chain_head -> setup_frame <= frame_num ) match = chain_head; if ( chain_head -> last && chain_head -> last -> setup_frame <= frame_num ) return chain_head -> last ; if ( chain_head -> latest_found && chain_head -> latest_found -> setup_frame <= frame_num ) match = chain_head -> latest_found; if ( convo -> setup_frame > match -> setup_frame ) match = convo; return match ; 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 ); static conversation_t *conversation_lookup_hashtable(GHashTable *hashtable,const guint32 frame_num,const address *addr1,const address *addr2,const port_type ptype,const guint32 port1,const guint32 port2) conversation_t * match = ( ( void * ) 0 ) ; conversation_key key ; key . addr1 = * addr1; key . addr2 = * addr2; key . ptype = ptype; key . port1 = port1; key . port2 = port2; chain_head = ( g_hash_table_lookup ( hashtable , ( & key ) ) ); if ( chain_head && chain_head -> setup_frame <= frame_num ) match = chain_head; if ( chain_head -> last && chain_head -> last -> setup_frame <= frame_num ) return chain_head -> last ; if ( chain_head -> latest_found && chain_head -> latest_found -> setup_frame <= frame_num ) match = chain_head -> latest_found; if ( convo -> setup_frame > match -> setup_frame ) match = convo; return match ; if ( conversation != ( ( void * ) 0 ) ) if ( ! ( conversation -> options & 0x01 ) && ptype != PT_UDP ) if ( ! ( conversation -> options & 0x08 ) ) conversation_set_addr2 ( conversation , addr_b ); void conversation_set_addr2(conversation_t *conv,const address *addr) if ( ! ( conv -> options & 0x01 ) ) guint8 * SE_COPY_ADDRESS_data ; SE_COPY_ADDRESS_data = ( se_alloc ( ( addr -> len ) ) ); memcpy ( SE_COPY_ADDRESS_data , addr -> data , ( addr -> len ) ); ( & conv -> key_ptr -> addr2 ) -> data = SE_COPY_ADDRESS_data; if ( conv -> options & 0x02 ) conversation_insert_into_hashtable ( conversation_hashtable_no_port2 , conv ); void conversation_insert_into_hashtable(GHashTable *hashtable,conversation_t *conv) chain_head = ( ( conversation_t * ) ( g_hash_table_lookup ( hashtable , ( conv -> key_ptr ) ) ) ); if ( ( ( void * ) 0 ) == chain_head ) conv -> next = ( ( void * ) 0 ); conv -> last = conv; g_hash_table_insert ( hashtable , ( conv -> key_ptr ) , conv ); chain_tail = chain_head -> last; if ( conv -> setup_frame >= chain_tail -> setup_frame ) conv -> next = ( ( void * ) 0 ); conv -> last = ( ( void * ) 0 ); chain_tail -> next = conv; chain_head -> last = conv; cur = chain_head; for (; conv -> setup_frame > cur -> setup_frame && cur -> next; (prev = cur , cur = cur -> next)) if ( ( ( void * ) 0 ) == prev ) conv -> next = chain_head; conv -> last = chain_tail; chain_head -> last = ( ( void * ) 0 ); g_hash_table_insert ( hashtable , ( conv -> key_ptr ) , conv ); conv -> next = cur; conv -> last = ( ( void * ) 0 ); prev -> next = conv; conversation_insert_into_hashtable ( conversation_hashtable_exact , conv ); void conversation_insert_into_hashtable(GHashTable *hashtable,conversation_t *conv) chain_head = ( ( conversation_t * ) ( g_hash_table_lookup ( hashtable , ( conv -> key_ptr ) ) ) ); if ( ( ( void * ) 0 ) == chain_head ) conv -> next = ( ( void * ) 0 ); conv -> last = conv; g_hash_table_insert ( hashtable , ( conv -> key_ptr ) , conv ); chain_tail = chain_head -> last; if ( conv -> setup_frame >= chain_tail -> setup_frame ) conv -> next = ( ( void * ) 0 ); conv -> last = ( ( void * ) 0 ); chain_tail -> next = conv; chain_head -> last = conv; cur = chain_head; if ( ( ( void * ) 0 ) == prev ) conv -> next = chain_head; conv -> last = chain_tail; chain_head -> last = ( ( void * ) 0 ); g_hash_table_insert ( hashtable , ( conv -> key_ptr ) , conv ); conv -> next = cur; conv -> last = ( ( void * ) 0 ); prev -> next = conv;
150083/conversation.c
SARD
0
CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_83_goodG2B::~CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_83_goodG2B() 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 );
117317/CWE789_Uncontrolled_Mem_Alloc__malloc_wchar_t_fgets_83_goodG2B.cpp
SARD
0
void CWE127_Buffer_Underread__char_alloca_loop_18_bad() char * dataBuffer = ( char * ) ALLOCA ( 100 * sizeof ( char ) ) ; memset ( dataBuffer , 'A' , 100 - 1 ); dataBuffer [ 100 - 1 ] = '\0'; data = dataBuffer - 8; dest [ i ] = data [ i ]; dest [ 100 - 1 ] = '\0'; printLine ( dest ); void printLine (const char * line) if ( line != NULL ) printf ( "%s\n" , line );
77299/CWE127_Buffer_Underread__char_alloca_loop_18.c
SARD
3