diff --git a/build/android/escargot/src/main/cpp/JNIGlobals.cpp b/build/android/escargot/src/main/cpp/JNIGlobals.cpp index 38b1fa5e5..36f8be8c9 100644 --- a/build/android/escargot/src/main/cpp/JNIGlobals.cpp +++ b/build/android/escargot/src/main/cpp/JNIGlobals.cpp @@ -86,12 +86,17 @@ static OptionalRef builtinHelperFileRead(OptionalRefthrowException(URIErrorObjectRef::create(state.get(), StringRef::createFromUTF8(msg, strnlen(msg, sizeof msg)))); + const size_t maxNameLength = 990; + if ((strnlen(builtinName, maxNameLength) + strnlen(fileName, maxNameLength)) < maxNameLength) { + char msg[1024]; + snprintf(msg, sizeof(msg), "GlobalObject.%s: cannot open file %s", builtinName, fileName); + state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromUTF8(msg, strnlen(msg, sizeof msg)))); + } else { + state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromASCII("invalid file name"))); + } } else { - LOGD("%s", msg); + LOGE("%s", fileName); } return nullptr; } diff --git a/src/shell/Shell.cpp b/src/shell/Shell.cpp index 07ee8bb86..82b4ea860 100644 --- a/src/shell/Shell.cpp +++ b/src/shell/Shell.cpp @@ -251,12 +251,17 @@ static OptionalRef builtinHelperFileRead(OptionalRefthrowException(URIErrorObjectRef::create(state.get(), StringRef::createFromUTF8(msg, strnlen(msg, sizeof msg)))); + const size_t maxNameLength = 990; + if ((strnlen(builtinName, maxNameLength) + strnlen(fileName, maxNameLength)) < maxNameLength) { + char msg[1024]; + snprintf(msg, sizeof(msg), "GlobalObject.%s: cannot open file %s", builtinName, fileName); + state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromUTF8(msg, strnlen(msg, sizeof msg)))); + } else { + state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromASCII("invalid file name"))); + } } else { - puts(msg); + puts(fileName); } return nullptr; }