mirror of
https://github.com/VirusTotal/yara-x.git
synced 2026-10-12 02:10:01 +00:00
This change significantly improves the safety and usability of the C API by introducing extensive null pointer validation for all input arguments and output pointers. Key improvements include: * **Null Pointer Checks:** Explicitly validate all critical input and output pointers (e.g., compiler, rules, src, buf, callback) for null values. Functions now return `YRX_INVALID_ARGUMENT` and set specific error messages via `yrx_last_error()` if null pointers are detected. * **Detailed Error Messages:** Provide more descriptive error messages for various failure conditions, including invalid arguments, failed C string conversions, and JSON parsing errors. * **Output Pointer Initialization:** Output pointers are now consistently set to `NULL` on error or at the beginning of functions that allocate new objects, preventing dereferencing of uninitialized pointers. * **Robust Error String Handling:** The internal `_yrx_set_last_error` function now sanitizes error strings to ensure valid `CString` creation, even if the source contains embedded nulls. * **Go Bindings Improvement:** Update Go bindings to check for `C.YRX_SUCCESS` generally, rather than specific error codes, and add `runtime.KeepAlive` calls to prevent premature garbage collection of C objects. * **Expanded Test Coverage:** Add new test cases to verify the correct behavior of null argument handling and error reporting across the C API.