details:   https://hg.nginx.org/njs/rev/4fa5ddc91108
branches:  
changeset: 2095:4fa5ddc91108
user:      Dmitry Volyntsev <xei...@nginx.com>
date:      Thu Apr 27 17:28:52 2023 -0700
description:
WebCrypto: fixed retval of crypto.getRandomValues().

Previously, crypto.getRandomValues() did not return any value,
but it has to return its buffer argument.

diffstat:

 external/njs_webcrypto_module.c |  13 +++++++++----
 src/test/njs_unit_test.c        |   4 ++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diffs (44 lines):

diff -r a868f772ef16 -r 4fa5ddc91108 external/njs_webcrypto_module.c
--- a/external/njs_webcrypto_module.c   Wed Apr 26 21:19:48 2023 -0700
+++ b/external/njs_webcrypto_module.c   Thu Apr 27 17:28:52 2023 -0700
@@ -4034,10 +4034,13 @@ static njs_int_t
 njs_ext_get_random_values(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused, njs_value_t *retval)
 {
-    njs_int_t  ret;
-    njs_str_t  fill;
-
-    ret = njs_vm_value_to_bytes(vm, &fill, njs_arg(args, nargs, 1));
+    njs_int_t    ret;
+    njs_str_t    fill;
+    njs_value_t  *buffer;
+
+    buffer = njs_arg(args, nargs, 1);
+
+    ret = njs_vm_value_to_bytes(vm, &fill, buffer);
     if (njs_slow_path(ret != NJS_OK)) {
         return NJS_ERROR;
     }
@@ -4052,6 +4055,8 @@ njs_ext_get_random_values(njs_vm_t *vm, 
         return NJS_ERROR;
     }
 
+    njs_value_assign(retval, buffer);
+
     return NJS_OK;
 }
 
diff -r a868f772ef16 -r 4fa5ddc91108 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c  Wed Apr 26 21:19:48 2023 -0700
+++ b/src/test/njs_unit_test.c  Thu Apr 27 17:28:52 2023 -0700
@@ -21923,6 +21923,10 @@ static njs_unit_test_t  njs_webcrypto_te
               "let condition = bits1 > (mean - 10 * stddev) && bits1 < (mean + 
10 * stddev);"
               "condition ? true : [buf, nbits, bits1, mean, stddev]"),
       njs_str("true") },
+
+    { njs_str("let buf = new Uint32Array(4);"
+              "buf === crypto.getRandomValues(buf)"),
+      njs_str("true") },
 };
 
 
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to