[njs] Fixed njs_error_new() for UTF8 messages.

Dmitry Volyntsev xeioex at nginx.com
Mon Aug 5 15:18:07 UTC 2019


details:   https://hg.nginx.org/njs/rev/bfdf58ec9116
branches:  
changeset: 1105:bfdf58ec9116
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Aug 05 17:10:59 2019 +0300
description:
Fixed njs_error_new() for UTF8 messages.

diffstat:

 src/njs_error.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (35 lines):

diff -r 8eb80902c862 -r bfdf58ec9116 src/njs_error.c
--- a/src/njs_error.c	Mon Aug 05 18:17:15 2019 +0300
+++ b/src/njs_error.c	Mon Aug 05 17:10:59 2019 +0300
@@ -16,20 +16,27 @@ void
 njs_error_new(njs_vm_t *vm, njs_value_t *dst, njs_value_type_t type,
     u_char *start, size_t size)
 {
+    ssize_t        length;
     njs_int_t     ret;
     njs_value_t   string;
     njs_object_t  *error;
 
-    ret = njs_string_new(vm, &string, start, size, size);
+    length = njs_utf8_length(start, size);
+    if (njs_slow_path(length < 0)) {
+        length = 0;
+    }
+
+    ret = njs_string_new(vm, &string, start, size, length);
     if (njs_slow_path(ret != NJS_OK)) {
         return;
     }
 
     error = njs_error_alloc(vm, type, NULL, &string);
+    if (njs_slow_path(error == NULL)) {
+        return;
+    }
 
-    if (njs_fast_path(error != NULL)) {
-        njs_set_type_object(dst, error, type);
-    }
+    njs_set_type_object(dst, error, type);
 }
 
 


More information about the nginx-devel mailing list