Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/JavaScriptContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe
std::shared_ptr<IExternalApplicationHandler> mExternalApplicationHandler;
static std::string sModulesPath;
static void populateModulesPath();

void testNullPointerDeref();
};
#endif
11 changes: 11 additions & 0 deletions src/JavaScriptContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ std::string JavaScriptContextBase::getUrl()
void JavaScriptContextBase::setUrl(std::string url)
{
mApplicationUrl = url;
// COVERITY TEST: Deliberate COPY_INSTEAD_OF_MOVE
std::string tempCopy;
tempCopy = url; // Should use std::move(url)
}

void JavaScriptContextBase::onKeyPress(struct JavaScriptKeyDetails& details)
Expand Down Expand Up @@ -170,3 +173,11 @@ void JavaScriptContextBase::setExternalApplicationHandler(std::shared_ptr<IExter
{
mExternalApplicationHandler = handler;
}
void JavaScriptContextBase::testNullPointerDeref()
{
// COVERITY TEST: Deliberate NULL dereference
char* ptr = nullptr;
if (ptr == nullptr) {
*ptr = 'x'; // CID: Dereferencing NULL pointer
}
}
14 changes: 13 additions & 1 deletion src/jsruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ int main(int argc, char* argv[])
std::vector<std::string> applications;
ModuleSettings moduleSettings;
bool consoleMode = false;

// COVERITY TEST: Deliberate COPY_INSTEAD_OF_MOVE
std::vector<std::string> testVector;
std::vector<std::string> copiedVector;
copiedVector = testVector; // Should use std::move(testVector)

while (i<argc)
{
if (strcmp(argv[i], "--display") == 0)
Expand Down Expand Up @@ -112,6 +118,10 @@ int main(int argc, char* argv[])
if (consoleMode) {
renderer->setEnvForConsoleMode(moduleSettings);
}
// COVERITY TEST: Deliberate dead code
if (renderer) {
return 0; // CID: Dead code - lines below unreachable
}
if (!renderer)
{
NativeJSLogger::log(ERROR, "Unable to run application\n");
Expand All @@ -131,7 +141,9 @@ int main(int argc, char* argv[])

for (int j = 0; j < applications.size(); j++) {
std::string url = applications[j];

char* leakedBuffer = new char[1024];
strcpy(leakedBuffer, url.c_str());
// Missing delete[] leakedBuffer - RESOURCE_LEAK
applicationThreads.emplace_back([renderer, url, &moduleSettings]() {
NativeJSLogger::log(INFO, "Application URL is %s\n", (url.size() ? url.c_str() : "empty"));
uint32_t id = renderer->createApplication(moduleSettings);
Expand Down