]> git.kaiwu.me - njs.git/commitdiff
Fixed one byte overread in njs_string_to_c_string().
authorValentin Bartenev <vbart@nginx.com>
Thu, 25 Jul 2019 17:17:42 +0000 (20:17 +0300)
committerValentin Bartenev <vbart@nginx.com>
Thu, 25 Jul 2019 17:17:42 +0000 (20:17 +0300)
Short strings are packed quite tight in njs_value_t, so there's
no one more byte to test.

    struct {
        njs_value_type_t              type:8;

        uint8_t                       size:4;
        uint8_t                       length:4;

        u_char                        start[14];
    } short_string;

With 14 bytes string this occupies 16 bytes, which is equal
to sizeof(njs_value_t).

njs/njs_string.c

index 31ca7b221aeacf68463ac665e68ee81fb654fe68..6425d0af8e15b0743c9ad7d2c8f7f5ba93c4c09e 100644 (file)
@@ -3906,10 +3906,7 @@ njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value)
         start = value->short_string.start;
         size = value->short_string.size;
 
-        if (start[size] == '\0') {
-            return start;
-
-        } else if (size < NJS_STRING_SHORT) {
+        if (size < NJS_STRING_SHORT) {
             start[size] = '\0';
             return start;
         }