mirror of
https://github.com/VirusTotal/yara.git
synced 2026-10-12 02:10:00 +00:00
Add yr_get_version to report the version of the library loaded at runtime (#2247)
YR_MAJOR_VERSION, YR_MINOR_VERSION and YR_MICRO_VERSION are fixed when the caller is compiled, so a program linked against a shared libyara has no way to tell which version it actually loaded. Distros ship libyara.so in its own package precisely so it can be updated independently of its consumers, which is exactly the case the macros cannot describe. Add yr_get_version(), which reports the version of the library that is actually loaded. Any argument may be NULL if the caller does not need that component, and since the function touches no global state it can be called before yr_initialize. Closes #2136 --------- Co-authored-by: Victor M. Alvarez <[email protected]>
This commit is contained in:
co-authored by
Victor M. Alvarez
parent
25a50bd63c
commit
5e8a8ea41f
@@ -42,6 +42,28 @@ int main(int argc, char **argv)
|
||||
|
||||
int result = strcmp(PACKAGE_VERSION, YR_VERSION);
|
||||
|
||||
// yr_get_version must report the same version the macros carry, and must
|
||||
// work before yr_initialize and with any argument omitted.
|
||||
|
||||
int major = -1, minor = -1, micro = -1;
|
||||
|
||||
yr_get_version(&major, &minor, µ);
|
||||
|
||||
if (major != YR_MAJOR_VERSION || minor != YR_MINOR_VERSION ||
|
||||
micro != YR_MICRO_VERSION)
|
||||
result = 1;
|
||||
|
||||
major = minor = micro = -1;
|
||||
|
||||
yr_get_version(&major, NULL, NULL);
|
||||
yr_get_version(NULL, &minor, NULL);
|
||||
yr_get_version(NULL, NULL, µ);
|
||||
yr_get_version(NULL, NULL, NULL);
|
||||
|
||||
if (major != YR_MAJOR_VERSION || minor != YR_MINOR_VERSION ||
|
||||
micro != YR_MICRO_VERSION)
|
||||
result = 1;
|
||||
|
||||
YR_DEBUG_FPRINTF(
|
||||
1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user