提交 50b9ba29 authored 作者: Peter Olsson's avatar Peter Olsson

mod_v8: In FileIO, make sure to initialize buffer with NULL, and add extra space…

mod_v8: In FileIO, make sure to initialize buffer with NULL, and add extra space for terminating NULL char
上级 f4a4ba17
...@@ -140,7 +140,8 @@ JS_FILEIO_FUNCTION_IMPL(Read) ...@@ -140,7 +140,8 @@ JS_FILEIO_FUNCTION_IMPL(Read)
if (bytes) { if (bytes) {
if (!_buf || _bufsize < bytes) { if (!_buf || _bufsize < bytes) {
_buf = (char *)switch_core_alloc(_pool, bytes); _buf = (char *)switch_core_alloc(_pool, bytes+1);
memset(_buf, 0, bytes+1);
_bufsize = bytes; _bufsize = bytes;
} }
...@@ -156,7 +157,12 @@ JS_FILEIO_FUNCTION_IMPL(Read) ...@@ -156,7 +157,12 @@ JS_FILEIO_FUNCTION_IMPL(Read)
JS_FILEIO_FUNCTION_IMPL(GetData) JS_FILEIO_FUNCTION_IMPL(GetData)
{ {
HandleScope handle_scope(info.GetIsolate()); HandleScope handle_scope(info.GetIsolate());
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), js_safe_str(_buf)));
if (!_buflen || !_buf) {
info.GetReturnValue().Set(false);
} else {
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), _buf));
}
} }
JS_FILEIO_FUNCTION_IMPL(Write) JS_FILEIO_FUNCTION_IMPL(Write)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论