[njs] Fixed handling of encode arg in fs.readdir() and fs.realpath().
noreply at nginx.com
noreply at nginx.com
Wed Sep 4 16:38:02 UTC 2024
details: https://github.com/nginx/njs/commit/6259cca26b6747fa8ade15c4b602b9ad190cb14a
branches: master
commit: 6259cca26b6747fa8ade15c4b602b9ad190cb14a
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue, 3 Sep 2024 21:32:33 -0700
description:
Fixed handling of encode arg in fs.readdir() and fs.realpath().
The issue was introduced in 98c6570f3 (0.8.0).
---
external/njs_fs_module.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/external/njs_fs_module.c b/external/njs_fs_module.c
index 5f9a48e2..de378cee 100644
--- a/external/njs_fs_module.c
+++ b/external/njs_fs_module.c
@@ -1940,14 +1940,19 @@ njs_fs_readdir(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
encoding = NULL;
- if (!njs_value_is_string(njs_value_arg(&encode))) {
+
+ if (njs_value_is_string(njs_value_arg(&encode))) {
njs_value_string_get(njs_value_arg(&encode), &s);
- if (!njs_strstr_eq(&s, &string_buffer)) {
- encoding = njs_buffer_encoding(vm, njs_value_arg(&encode), 1);
- if (njs_slow_path(encoding == NULL)) {
- return NJS_ERROR;
- }
+ } else {
+ s.length = 0;
+ s.start = NULL;
+ }
+
+ if (!njs_strstr_eq(&s, &string_buffer)) {
+ encoding = njs_buffer_encoding(vm, njs_value_arg(&encode), 1);
+ if (njs_slow_path(encoding == NULL)) {
+ return NJS_ERROR;
}
}
@@ -2080,14 +2085,18 @@ njs_fs_realpath(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
encoding = NULL;
- if (!njs_value_is_string(njs_value_arg(&encode))) {
+ if (njs_value_is_string(njs_value_arg(&encode))) {
njs_value_string_get(njs_value_arg(&encode), &s);
- if (!njs_strstr_eq(&s, &string_buffer)) {
- encoding = njs_buffer_encoding(vm, njs_value_arg(&encode), 1);
- if (njs_slow_path(encoding == NULL)) {
- return NJS_ERROR;
- }
+ } else {
+ s.length = 0;
+ s.start = NULL;
+ }
+
+ if (!njs_strstr_eq(&s, &string_buffer)) {
+ encoding = njs_buffer_encoding(vm, njs_value_arg(&encode), 1);
+ if (njs_slow_path(encoding == NULL)) {
+ return NJS_ERROR;
}
}
More information about the nginx-devel
mailing list