Browse Source

Sanity check added to operator_string_sub

Marco Bambini 8 years ago
parent
commit
49cb978407
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/runtime/gravity_core.c

+ 3 - 1
src/runtime/gravity_core.c

@@ -1528,7 +1528,9 @@ static bool operator_string_sub (gravity_vm *vm, gravity_value_t *args, uint16_t
 	// now check if entire substring must be considered
 	// now check if entire substring must be considered
 	uint32_t flen = (uint32_t)strlen(found);
 	uint32_t flen = (uint32_t)strlen(found);
 	if (flen == s2->len) RETURN_VALUE(VALUE_FROM_STRING(vm, s1->s, (uint32_t)(found - s1->s)), rindex);
 	if (flen == s2->len) RETURN_VALUE(VALUE_FROM_STRING(vm, s1->s, (uint32_t)(found - s1->s)), rindex);
-	
+	// sanity check for malformed strings
+    if (flen < s2->len) RETURN_ERROR("Malformed string.");
+    
 	// substring found but cannot be entirely considered
 	// substring found but cannot be entirely considered
 	uint32_t alloc = MAXNUM(s1->len + s2->len +1, DEFAULT_MINSTRING_SIZE);
 	uint32_t alloc = MAXNUM(s1->len + s2->len +1, DEFAULT_MINSTRING_SIZE);
 	char *s = mem_alloc(alloc);
 	char *s = mem_alloc(alloc);