mirror of
https://github.com/VirusTotal/yara.git
synced 2026-10-12 02:10:00 +00:00
Fix race conditions when using the same YR_RULES struct from differen… (#925)
* Fix race conditions when using the same YR_RULES struct from different threads with PROFILING_ENABLED. * Make time_cost signed as InterlockedAdd64 expects a signed integer. Closes #918.
This commit is contained in:
@@ -12,11 +12,21 @@ environment:
|
||||
VisualStudioVersion: 14.0
|
||||
configuration: Release
|
||||
platform: x86
|
||||
- TARGET: vs2015
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
VisualStudioVersion: 14.0
|
||||
configuration: Debug
|
||||
platform: x86
|
||||
- TARGET: vs2015
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
VisualStudioVersion: 14.0
|
||||
platform: x64
|
||||
configuration: Release
|
||||
- TARGET: vs2015
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
VisualStudioVersion: 14.0
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
- TARGET: cygwin
|
||||
|
||||
for:
|
||||
|
||||
+10
-2
@@ -518,7 +518,11 @@ int yr_execute_code(
|
||||
|
||||
#ifdef PROFILING_ENABLED
|
||||
elapsed_time = yr_stopwatch_elapsed_us(&context->stopwatch);
|
||||
rule->time_cost += (elapsed_time - start_time);
|
||||
#ifdef _WIN32
|
||||
InterlockedAdd64(&rule->time_cost, elapsed_time - start_time);
|
||||
#else
|
||||
__sync_fetch_and_add(&rule->time_cost, elapsed_time - start_time);
|
||||
#endif
|
||||
start_time = elapsed_time;
|
||||
#endif
|
||||
|
||||
@@ -1268,7 +1272,11 @@ int yr_execute_code(
|
||||
{
|
||||
#ifdef PROFILING_ENABLED
|
||||
assert(current_rule != NULL);
|
||||
current_rule->time_cost += elapsed_time - start_time;
|
||||
#ifdef _WIN32
|
||||
InterlockedAdd64(&rule->time_cost, elapsed_time - start_time);
|
||||
#else
|
||||
__sync_fetch_and_add(&rule->time_cost, elapsed_time - start_time);
|
||||
#endif
|
||||
#endif
|
||||
result = ERROR_SCAN_TIMEOUT;
|
||||
stop = true;
|
||||
|
||||
@@ -275,13 +275,13 @@ struct YR_STRING
|
||||
YR_MATCHES unconfirmed_matches[YR_MAX_THREADS];
|
||||
|
||||
// Used only when PROFILING_ENABLED is defined
|
||||
uint64_t time_cost;
|
||||
volatile int64_t time_cost;
|
||||
};
|
||||
|
||||
|
||||
struct YR_RULE
|
||||
{
|
||||
int32_t g_flags; // Global flags
|
||||
int32_t g_flags; // Global flags
|
||||
int32_t t_flags[YR_MAX_THREADS]; // Thread-specific flags
|
||||
|
||||
DECLARE_REFERENCE(const char*, identifier);
|
||||
@@ -291,7 +291,7 @@ struct YR_RULE
|
||||
DECLARE_REFERENCE(YR_NAMESPACE*, ns);
|
||||
|
||||
// Used only when PROFILING_ENABLED is defined
|
||||
uint64_t time_cost;
|
||||
volatile int64_t time_cost;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+7
-2
@@ -872,8 +872,13 @@ int yr_scan_verify_match(
|
||||
|
||||
#ifdef PROFILING_ENABLED
|
||||
uint64_t finish_time = yr_stopwatch_elapsed_us(&context->stopwatch);
|
||||
string->time_cost += (finish_time - start_time);
|
||||
string->rule->time_cost += (finish_time - start_time);
|
||||
#ifdef _WIN32
|
||||
InterlockedAdd64(&string->time_cost, finish_time - start_time);
|
||||
InterlockedAdd64(&string->rule->time_cost, finish_time - start_time);
|
||||
#else
|
||||
__sync_fetch_and_add(&string->time_cost, finish_time - start_time);
|
||||
__sync_fetch_and_add(&string->rule->time_cost, finish_time - start_time);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return result;
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;CUCKOO_MODULE;HASH_MODULE;DOTNET_MODULE;HAVE_LIBCRYPTO;USE_WINDOWS_PROC;YR_BUILDING_STATIC_LIB</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;CUCKOO_MODULE;HASH_MODULE;DOTNET_MODULE;HAVE_LIBCRYPTO;USE_WINDOWS_PROC;YR_BUILDING_STATIC_LIB;PROFILING_ENABLED</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\..\..\libyara;..\..\..\libyara\include;..\..\..;..\packages\YARA.Jansson.x86.1.1.0\include;..\packages\YARA.OpenSSL.x86.1.1.0\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4005;4273;4090</DisableSpecificWarnings>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
@@ -105,7 +105,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;CUCKOO_MODULE;HASH_MODULE;DOTNET_MODULE;HAVE_LIBCRYPTO;USE_WINDOWS_PRO;YR_BUILDING_STATIC_LIBC</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;CUCKOO_MODULE;HASH_MODULE;DOTNET_MODULE;HAVE_LIBCRYPTO;USE_WINDOWS_PRO;YR_BUILDING_STATIC_LIBC;PROFILING_ENABLED</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\..\..\libyara;..\..\..\libyara\include;..\..\..;..\packages\YARA.Jansson.x64.1.1.0\include;..\packages\YARA.OpenSSL.x64.1.1.0\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4005;4273;4090</DisableSpecificWarnings>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
|
||||
Reference in New Issue
Block a user