aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoff Gustafson <geoff@linux.intel.com>2017-03-14 17:21:43 -0700
committerJimmy Huang <jimmy.huang@linux.intel.com>2017-03-15 17:30:51 -0700
commit7952b999b253364753f55f260d431edb50760361 (patch)
tree32ea2fb6b3e2e3ea16f00e1da3197f1e8db6383d
parent8448eac65cec038f91fc71c6abb58af34f948df8 (diff)
[util] Fix bug in argument validation caught by new unit tests
The check for valid range of the type index was wrong and would have allowed calling functions at bogus offsets in my array. Really, I caught it because of looking at the code carefully again while developing the tests. But it still made writing the tests worth it. Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
-rw-r--r--src/zjs_util.c4
-rw-r--r--src/zjs_util.h2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/zjs_util.c b/src/zjs_util.c
index 5802d06..effa99e 100644
--- a/src/zjs_util.c
+++ b/src/zjs_util.c
@@ -424,8 +424,8 @@ static int zjs_validate_arg(const char *expectation, jerry_value_t arg)
// NOTE: This relies on Z_ANY to Z_UNDEFINED being consecutive and
// Z_UNDEFINED being the last one
int type_index = expectation[index] - Z_ANY[0];
- if (type_index < 0 || type_index > Z_UNDEFINED[0]) {
- ERR_PRINT("invalid argument type: '%c'", expectation[index]);
+ if (type_index < 0 || expectation[index] > Z_UNDEFINED[0]) {
+ ERR_PRINT("invalid argument type: '%c'\n", expectation[index]);
return ZJS_INTERNAL_ERROR;
}
diff --git a/src/zjs_util.h b/src/zjs_util.h
index 5c6aece..6878a8d 100644
--- a/src/zjs_util.h
+++ b/src/zjs_util.h
@@ -112,13 +112,13 @@ void zjs_print_error_message(jerry_value_t error);
// Z_ANY matches any type (i.e. ignores it) - only makes sense for required arg
#define Z_ANY "a"
-
// the rest all match specific type by calling jerry_value_is_* function
#define Z_ARRAY "b"
#define Z_BOOL "c"
#define Z_FUNCTION "d"
#define Z_NULL "e"
#define Z_NUMBER "f"
+// NOTE: Z_OBJECT will match arrays and functions too, because they are objects
#define Z_OBJECT "g"
#define Z_STRING "h"
#define Z_UNDEFINED "i"