]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_v8: In FileIO, make sure to initialize buffer with NULL, and add extra space...
authorPeter Olsson <peter@olssononline.se>
Wed, 15 Jan 2014 16:46:14 +0000 (17:46 +0100)
committerPeter Olsson <peter@olssononline.se>
Wed, 15 Jan 2014 16:47:16 +0000 (17:47 +0100)
src/mod/languages/mod_v8/src/fsfileio.cpp

index ec8fb591c5e04759d0f1cd75e0615b608abf3de1..a89d1ae8923e5b5f4c9e9fd2f26ebc604f6eb295 100644 (file)
@@ -140,7 +140,8 @@ JS_FILEIO_FUNCTION_IMPL(Read)
 
        if (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;
                }
 
@@ -156,7 +157,12 @@ JS_FILEIO_FUNCTION_IMPL(Read)
 JS_FILEIO_FUNCTION_IMPL(GetData)
 {
        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)