From: Igor Sysoev Date: Thu, 24 Mar 2016 11:22:08 +0000 (+0300) Subject: Issues found by Coverity Scan in Regex have been fixed. X-Git-Tag: 0.1.0~42 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=a26603885c4639af38729f86232af4d34d28db57;p=njs.git Issues found by Coverity Scan in Regex have been fixed. --- diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index 71815587..7e81708c 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -36,6 +36,8 @@ static int njs_regexp_pattern_compile(pcre **code, pcre_extra **extra, u_char *source, int options); static njs_ret_t njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, u_char *string, int *captures, nxt_uint_t utf8); +static njs_ret_t njs_regexp_string_create(njs_vm_t *vm, njs_value_t *value, + u_char *start, uint32_t size, int32_t length); njs_ret_t @@ -436,7 +438,7 @@ njs_regexp_prototype_source(njs_vm_t *vm, njs_value_t *value) size = strlen((char *) source) - pattern->flags; length = nxt_utf8_length(source, size); - return njs_string_create(vm, &vm->retval, source, size, length); + return njs_regexp_string_create(vm, &vm->retval, source, size, length); } @@ -454,7 +456,7 @@ njs_regexp_prototype_to_string(njs_vm_t *vm, njs_value_t *args, size = strlen((char *) source); length = nxt_utf8_length(source, size); - return njs_string_create(vm, &vm->retval, source, size, length); + return njs_regexp_string_create(vm, &vm->retval, source, size, length); } @@ -621,7 +623,8 @@ njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, u_char *string, break; } - ret = njs_string_create(vm, &array->start[i], start, size, length); + ret = njs_regexp_string_create(vm, &array->start[i], + start, size, length); if (nxt_slow_path(ret != NXT_OK)) { return NXT_ERROR; } @@ -684,6 +687,19 @@ njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, u_char *string, } +static njs_ret_t +njs_regexp_string_create(njs_vm_t *vm, njs_value_t *value, u_char *start, + uint32_t size, int32_t length) +{ + if (nxt_fast_path(length >= 0)) { + return njs_string_create(vm, value, start, size, length); + } + + vm->exception = &njs_exception_internal_error; + return NXT_ERROR; +} + + static const njs_object_prop_t njs_regexp_constructor_properties[] = { /* RegExp.name == "RegExp". */