[Forensics-changes] [yara] 116/135: Improve error reporting when a function is called with wrong number of arguments
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:27:38 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.1.0
in repository yara.
commit 2d04878168cf58c8374e123138b97840507108c7
Author: Victor M. Alvarez <plusvic at gmail.com>
Date: Fri Aug 22 13:35:29 2014 +0200
Improve error reporting when a function is called with wrong number of arguments
---
libyara/compiler.c | 27 +++++++++++----------------
libyara/include/yara/error.h | 1 +
libyara/parser.c | 30 ++++++++++++++++++++++--------
3 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/libyara/compiler.c b/libyara/compiler.c
index d303e1f..b096390 100644
--- a/libyara/compiler.c
+++ b/libyara/compiler.c
@@ -720,13 +720,6 @@ char* yr_compiler_get_error_message(
"unreferenced string \"%s\"",
compiler->last_error_extra_info);
break;
- case ERROR_WRONG_TYPE:
- snprintf(
- buffer,
- buffer_size,
- "%s",
- compiler->last_error_extra_info);
- break;
case ERROR_NOT_A_STRUCTURE:
snprintf(
buffer,
@@ -754,15 +747,6 @@ char* yr_compiler_get_error_message(
buffer_size,
"wrong use of anonymous string");
break;
- case ERROR_INVALID_HEX_STRING:
- case ERROR_INVALID_REGULAR_EXPRESSION:
- case ERROR_SYNTAX_ERROR:
- snprintf(
- buffer,
- buffer_size,
- "%s",
- compiler->last_error_extra_info);
- break;
case ERROR_INCLUDES_CIRCULAR_REFERENCE:
snprintf(
buffer,
@@ -791,6 +775,17 @@ char* yr_compiler_get_error_message(
"unknown module \"%s\"",
compiler->last_error_extra_info);
break;
+ case ERROR_INVALID_HEX_STRING:
+ case ERROR_INVALID_REGULAR_EXPRESSION:
+ case ERROR_SYNTAX_ERROR:
+ case ERROR_WRONG_TYPE:
+ case ERROR_WRONG_NUMBER_OF_ARGUMENTS:
+ snprintf(
+ buffer,
+ buffer_size,
+ "%s",
+ compiler->last_error_extra_info);
+ break;
case ERROR_INTERNAL_FATAL_ERROR:
snprintf(
buffer,
diff --git a/libyara/include/yara/error.h b/libyara/include/yara/error.h
index 6a8d343..35bedd6 100644
--- a/libyara/include/yara/error.h
+++ b/libyara/include/yara/error.h
@@ -59,6 +59,7 @@ limitations under the License.
#define ERROR_NOT_A_FUNCTION 37
#define ERROR_INVALID_FORMAT 38
#define ERROR_TOO_MANY_ARGUMENTS 39
+#define ERROR_WRONG_NUMBER_OF_ARGUMENTS 40
#define FAIL_ON_ERROR(x) { \
diff --git a/libyara/parser.c b/libyara/parser.c
index ec442e0..a30dd7d 100644
--- a/libyara/parser.c
+++ b/libyara/parser.c
@@ -175,21 +175,35 @@ int yr_parser_check_types(
i = 0;
- while (*expected != '\0' && actual != '\0')
+ while (*expected != '\0' || *actual != '\0')
{
i++;
if (*expected != *actual)
{
- snprintf(
- message,
- sizeof(message),
- "wrong type for argument %i of \"%s\"",
- i,
- function->identifier);
+ if (*expected == '\0' || *actual == '\0')
+ {
+ snprintf(
+ message,
+ sizeof(message),
+ "wrong number of arguments for \"%s\"",
+ function->identifier);
+
+ compiler->last_result = ERROR_WRONG_NUMBER_OF_ARGUMENTS;
+ }
+ else
+ {
+ snprintf(
+ message,
+ sizeof(message),
+ "wrong type for argument %i of \"%s\"",
+ i,
+ function->identifier);
+
+ compiler->last_result = ERROR_WRONG_TYPE;
+ }
yr_compiler_set_error_extra_info(compiler, message);
- compiler->last_result = ERROR_WRONG_TYPE;
break;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git
More information about the forensics-changes
mailing list