Fix YARA compiler move issue in error path
When add_rules_str() fails, the compiler is already consumed. Changed from 'continue' to 'return Err' to avoid trying to use the moved compiler in the next loop iteration. This properly handles the builder pattern where the value is consumed on error.
This commit is contained in:
@@ -171,14 +171,9 @@ impl DynamicYaraEngine {
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("default");
|
||||
|
||||
compiler = match compiler.add_rules_str(&content) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
log::error!("Failed to compile {}: {}", rule_file.display(), e);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
match compiler.add_rules_str(&content) {
|
||||
Ok(c) => {
|
||||
compiler = c;
|
||||
log::info!("Compiled YARA rule: {}", rule_file.display());
|
||||
|
||||
self.rule_metadata.push(YaraRuleMetadata {
|
||||
@@ -190,6 +185,15 @@ impl DynamicYaraEngine {
|
||||
|
||||
rule_count += 1;
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to compile {}: {}", rule_file.display(), e);
|
||||
// Don't continue - compiler was consumed, return with error
|
||||
return Err(GhostError::Configuration {
|
||||
message: format!("Failed to compile {}: {}", rule_file.display(), e),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to read {}: {}", rule_file.display(), e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user