40 Commits
Author SHA1 Message Date
Victor M. Alvarez 4d696a91b1 Fix test cases 2024-01-15 22:31:18 +01:00
Tomáš Ďuriš d7e67ff54b Added warning on unknown escape sequences (#1880)
* Added warning on unknown escape sequences

* fixed memory leaks and different output when using regex as operand with strict-escape parameter

* Remove some unwanted characters from strict escaping, add testcases
2023-08-23 15:26:43 +02:00
Victor M. Alvarez d4aa53a026 Implement test cases for issue #1631 2022-01-14 14:09:32 +01:00
Hilko BengenandVictor M. Alvarez f5893ea78b tests: Improve error message (#1265)
Co-authored-by: Victor M. Alvarez <[email protected]>
2021-10-28 16:19:37 +02:00
Hilko Bengen 71980e0e7c Tests: Set top_srcdir variable instead of changing directory (#1466) 2021-03-22 10:33:03 +01:00
Victor M. Alvarez ac5eae7137 Simplify test-rules by putting running the all the passes in a single binary.
This makes easier to build the tests with Bazel. Also fix some issues with Bazel configuration.
2021-01-12 20:52:55 +01:00
Victor M. AlvarezandSimon Hardy-Francis cba6932759 Implement non-blocking API (#1428)
With this change the yr_scanner_scan_mem_blocks function can return ERROR_BLOCK_NOT_READY when the YR_MEMORY_BLOCK_ITERATOR that provides memory blocks to the function is not ready to return the next block. After this error the caller can retry the call to yr_scanner_scan_mem_blocks multiple times until the function succeeds or fails with some other error code.

Co-authored-by: Simon Hardy-Francis <[email protected]>
2020-12-24 10:46:09 +01:00
Hilko Bengen 79105efd07 tests: Disable process scanning test on Windows (#1420)
* tests: Disable process scanning test on Windows

There's no sys/wait.h and no fork, so let's just #ifdef it out.

* tests: Open sample files in binary mode

Relevant on Windows.
2020-12-21 12:15:27 +01:00
Wesley Shields 95b43693dc Switch maximum string limit to warning. (#1350)
When we hit the maximum match limit on a string we currently abort all scanning,
which can be problematic since it isn't a good reason to stop all scanning, and
is better off as a warning to the user.

This commit makes it so that when the string match limit is hit a warning is
printed and scanning will continue. The warning message indicates that the
results may be invalid. It is hard to know for certain if they are invalid
because it depends entirely upon the condition. If you use the # or @ operator
then your condition _MAY_ be invalid since the total number of matches and
locations is not known anymore. Just checking that the string exists won't be an
invalid state since we have confirmed the existence of _AT LEAST_ the maximum
number of occurrences, which clearly satisfies the existence of a single
instance of your string.

I decided to implement this as a callback so the user of libyara has some choice
on the default behavior. If they want to consider this a "stop all scanning"
error they are free to return CALLBACK_ERROR in their callback.
2020-12-17 10:10:27 +01:00
Victor M. Alvarez 0bce4bd74d Start using clang-format for formatting the code automatically. 2020-10-07 16:27:30 +02:00
Simon Hardy-Francis 0975ea7d30 Fix linux compiler warnings and refactor common test code (#1366) 2020-10-05 09:47:25 +02:00
Victor M. Alvarez e4187f3587 Review all calls to YR_DEBUG_FPRINTF and make the following changes: (#1363)
* Review all calls to YR_DEBUG_FPRINTF and make the following changes:

* Use PRIx64 and PRIi64 for printing 64-bits values, which is more portable.
* Use %zu for printing size_t types.
* Remove the empty {} at the end of printed messages, as they don't provide that much information and clutter the format string
* Don't use ' in format strings for thousand separators as this is not very portable (https://stackoverflow.com/questions/10234766/warning-using-icc-and-printf-with-thousands-grouping-format-apostrophe)

* Re-introduce the curly braces in YR_DEBUG_FPRINTF messages.
2020-10-02 17:13:44 +02:00
Simon Hardy-Francis bf324e12f6 Fix multi block bugs and test running test-rules with single & multiple blocks
See https://github.com/VirusTotal/yara/issues/1356
2020-10-01 09:31:18 +02:00
plusvic cc72b1aff2 Merge branch 'v4' 2020-03-13 10:06:27 +01:00
plusvic ece08f59d1 Compiler's callback function now receives a pointer the affected YR_RULE
The callback called by the compiler to report errors and warnings now received a pointer to the rule causing the error/warning. This allows richer error messages.
2020-03-12 19:22:28 +01:00
Victor M. Alvarez 47834185c2 Implement SCAN_FLAGS_REPORT_RULES_MATCHING and SCAN_FLAGS_REPORT_RULES_NOT_MATCHING flags.
These flags control whether or not the user-registered callback is called for matching and non-matching rules respectively.
2020-03-03 16:54:44 +01:00
Victor M. Alvarez 2b121b166d Track string matches using YR_SCAN_CONTEXT. 2020-02-27 13:51:47 +01:00
Victor M. Alvarez 7342c51847 Pass the SCAN_FLAGS_NO_TRYCATCH flag in tests.
If not, SIGSEGV exceptions are captured and is more difficult to see the true nature of the error.
2020-02-13 17:23:29 +01:00
Victor M. Alvarez 0e52686008 Add tests for a module automatically generated from a Protocol Buffer. (#1162) 2019-11-13 17:04:24 +01:00
Wesley Shields ce470b7bd4 Improved xor modifier. (#1132)
* Implement improved xor modifier.

* Fix breakage when xor(...) came before another modifier.

* Add documentation for xor improvements.

* Fixes from review by Victor.

- No more changes to lexer.
- Duplicate modifiers are now errors.
- Do not rely on undocumented behavior in bison.

* Apply fix to deal with undocumented bison feature we shouldn't rely on.

* Make xor work properly with other modifiers.

This commit now makes it so that "xor(1-255) wide" will no longer search for the
plaintext wide version of the string, but "xor wide" will because it implies
xor(0-255).

* Add support for xor(X) and tests.
2019-09-18 17:12:46 +02:00
Victor M. Alvarez 5aa70a050e Fix chained strings (#1107)
* Add test case.

* Fix issue with regexps and hex strings that were not splitted correctly.

The function yr_re_ast_split_at_chaining_point was not splitting correctly regexps and hex strings that contained more than one large jump (a.k.a gap). For example, { 01 02 03 [0-1000] 04 05 06 [500-2000] 07 08 09 } was not splitted in three parts as expected, but only in two parts: { 01 02 03 } and { 04 05 06 [500-2000] 07 08 09 } . This didn't affected the correctness of the matches, but it caused ERROR_TOO_MANY_RE_FIBERS in some cases while trying to match { 04 05 06 [500-2000] 07 08 09 } because of the large jump in the pattern. The occurrence of the error depended on the data being scanned.

This commit fixes the aforementioned issue, improves the documentation of related functions and simplifies some portions of the code.

* Avoid putting the same string multiple times in matching_strings_arena.

This fixes a small issue introduced in #1096. The same string could be put more than once in the matching_strings_arena, this doesn't causes any major error nor affect the correctness of the matching, but it could have a negative impact on performance.

* Add more comments.

* Improve documentation for _yr_scan_verify_chained_string_match.
2019-08-12 09:07:33 +02:00
Marek Milkovič bfca2d2c6c Fixed multiple memory leaks in tests (#1033) 2019-03-03 18:31:05 +01:00
Victor M. Alvarez 75f9978969 More adjustments to atom quality heuristic. 2018-08-20 23:02:03 +02:00
Victor M. Alvarez 36e088eef8 Add test cases for atom extraction logic. 2018-08-16 09:51:21 +02:00
Victor M. Alvarez ce1b355673 Link tests with static libyara.
Some tests use function that are not exported with YR_API and therefore are not found when linking with the dynamic library.
2018-08-14 13:24:29 +02:00
Victor M. Alvarez e0c4c6bd10 Fix some warnings. 2018-08-14 13:14:32 +02:00
Victor M. Alvarez 60572c24de Multiple improvements in atom extraction. 2018-08-14 11:45:02 +02:00
Victor M. Alvarez fc857bfdb1 Fix small issue in test cases. 2018-07-25 17:01:28 +02:00
Victor M. Alvarez 1744ea70b0 Fix atom quality heuristic calculation. Rename atom prevalence table to atom quality table. 2018-07-09 08:42:40 +02:00
Victor M. Alvarez 53c9f72a9d Closes issue #834. 2018-02-21 22:02:31 +01:00
plusvic 67ba4ff9c3 Improve test cases dealing with errors. Add test cases for invalid module names. 2017-03-08 16:58:57 +01:00
Hilko Bengen 8b2b6b8f82 Don't unmask signals when setting up exception handler (Unix) (#546)
* YR_TRYCATCH: Remove duplicate initialization of oldmask

* Add test for handling exceptions

With

    #define YR_TRYCATCH(_try_clause_, _catch_clause_) {_try_clause_}

this will cause a bus error on Linux -- as it should.

* tests: Add assert_*_rule_blob_size, make count_matches usable from test code

* test-exception: Block and send SIGUSR1 before 2nd yr_rules_scan_mem call

This seems to reproduce something similar to the symptom described in

$ ./test-exception
Scanning for "aaaa"...
err = 4, matches = 0
Sending blocked SIGUSR1 to ourselves...
Scanning for {00 00 00 00}...
User defined signal 1

* exception (UNIX): Remove unneeded pthread_sigmask() calls

sigsetjmp() already saves the signal mask for us.

Also, setting the signal mask using the (empty) act.sa_mask was wrong
and led to the behavior described in #544.

We still want delivery of all signals to be blocked during execution of
the signal handler.

* Document test-exception
2016-10-31 09:40:38 +01:00
plusvic 3a53f063c6 Change license to 3-clause BSD 2016-06-24 16:35:15 +02:00
plusvic 89a305f91d Fix issue introduced in 23759af0b2
YR_MATCH was keeping a pointer to the original scanned data. With the introduction of iterator logic the original data is not guaranteed to be in memory by the time YR_MATCH is passed to library clients. Now a copy of the matching string is kept alongside the YR_MATCH structure.
2016-06-14 20:29:05 +02:00
plusvic 5b5d280744 Fix memory leaks in tests 2016-05-10 15:29:32 +02:00
plusvic bd35568486 Re-styling changes 2016-03-21 16:19:28 +01:00
Hilko Bengen d68a0968a1 tests: Add code for working with external files 2016-03-16 19:25:59 +01:00
Hilko Bengen 4867806342 tests: Output compile errors 2016-03-01 22:23:43 +01:00
plusvic 2976bacd82 Apply YARA's coding style to tests 2016-02-29 16:37:05 +01:00
Hilko Bengen 485fce9b44 Port most of the the rule-related tests from yara-python
The test code for parsing and behavior of the rule engine belongs with
Yara itself rather than the the Python bindings that have been split
off. Now the tests can be run again when the library is built.
2016-02-28 22:20:09 +01:00