-
Notifications
You must be signed in to change notification settings - Fork 1
FIx High level Coverity issue[Test PR] #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -506,8 +506,9 @@ void NativeJSRenderer::run() | |
| if(!mTestFileName.empty()) | ||
| { | ||
| ModuleSettings settings; | ||
| uint32_t testId = createApplicationIdentifier(); | ||
| settings.enableJSDOM = mEnableTestFileDOMSupport; | ||
| ApplicationRequest appRequest(id, RUN, mTestFileName, settings.enableHttp, settings.enableXHR, settings.enableWebSocket, settings.enableWebSocketEnhanced, settings.enableFetch, settings.enableJSDOM, settings.enableWindow, settings.enablePlayer); | ||
| ApplicationRequest appRequest(testId, RUN, mTestFileName, settings.enableHttp, settings.enableXHR, settings.enableWebSocket, settings.enableWebSocketEnhanced, settings.enableFetch, settings.enableJSDOM, settings.enableWindow, settings.enablePlayer); | ||
| NativeJSRenderer::createApplicationInternal(appRequest); | ||
|
Comment on lines
+509
to
512
|
||
| NativeJSRenderer::runApplicationInternal(appRequest); | ||
| mTestFileName = ""; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -314,24 +314,61 @@ rtError rtSetVideoStartTimeBinding(int numArgs, const rtValue* args, rtValue* re | |||||||
|
|
||||||||
| rtError rtReadBinaryBinding(int numArgs, const rtValue* args, rtValue* result, void* context) | ||||||||
| { | ||||||||
| char *buffer = nullptr; | ||||||||
| FILE *ptr = nullptr; | ||||||||
| ptr = fopen("hello.wasm","rb"); // r for read, b for binary | ||||||||
| UNUSED_PARAM(context); | ||||||||
|
|
||||||||
| // 1. Validate numArgs and use args for filename | ||||||||
| if (numArgs < 1 || args[0].getType() != RT_stringType) { | ||||||||
| rtLogError("%s: missing or invalid file path", __FUNCTION__); | ||||||||
| return RT_ERROR_INVALID_ARG; | ||||||||
| } | ||||||||
|
|
||||||||
| const char *fd = "hello.wasm"; | ||||||||
| const char *fd = args[0].toString().cString(); | ||||||||
|
||||||||
| const char *fd = args[0].toString().cString(); | |
| rtString filePath = args[0].toString(); | |
| const char *fd = filePath.cString(); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This binding now reads an arbitrary filesystem path provided by JS (args[0]). That enables scripts to read any readable file on the device (path traversal / sensitive file disclosure), whereas the old code only read a fixed filename.
If this API is exposed to untrusted content, restrict reads to an allowlisted directory, enforce a sandboxed root, or remove the ability to pass arbitrary paths.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code opens the file and then calls stat(fd, ...) on the path, which introduces a TOCTOU race (the path could change between fopen and stat). Prefer fstat(fileno(ptr), &buf) to get the size/metadata of the already-open file descriptor.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buf.st_size is an off_t and may be 64-bit; assigning it to int size can truncate/overflow for large files and break allocation/read logic. Use off_t/size_t (and validate bounds) for the size variable.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buf.st_size is an off_t (often 64-bit) but it’s being narrowed to int. Large files can overflow and lead to undersized allocations/reads.
Use an appropriate unsigned size type (size_t/uint64_t) and validate bounds before allocating/reading.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result->setString(buffer) treats the file contents as a C-string, but buffer is not NUL-terminated and may contain embedded NULs (especially for .wasm). This can truncate data or read past the allocation.
Either allocate size + 1 and NUL-terminate for text files, or return a binary-safe type (e.g., byte array / ArrayBuffer / base64) along with the length.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads raw bytes into buffer and passes it to setString(buffer) without ensuring NUL-termination. For binary files (e.g., wasm) this will truncate at the first '\0' and can also read past the allocation if setString expects a C-string. Consider allocating size + 1 and setting buffer[size] = '\0', or better, use an API that preserves length (e.g., construct an rtString with explicit length / return a byte array type) instead of treating binary data as a C-string.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ownership concern here: manually deleting netMetricsArray is error-prone with ref-counted rtObjects.
Use an rtRef/rtObjectRef for netMetricsArray so it is automatically released on failure paths.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue on this failure path: prefer RAII (rtRef/rtObjectRef) over delete netMetricsArray to match the rest of the codebase’s ref-counted object ownership model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createApplicationIdentifier()uses astatic uint32_t idwithout synchronization. Calling it here (outsidemUserMutex) introduces a data race with other threads that callcreateApplication()(which also callscreateApplicationIdentifier()).Make the counter
std::atomic<uint32_t>or ensure all calls (including this test-file path) are protected by the same mutex.