Index: fpdfsdk/src/javascript/app.cpp |
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp |
index 3b92a992d9d0be2b46db2266d0e51847b0a34fdd..92e08ff48fba0eece261177cafbf5c0bb77b34c3 100644 |
--- a/fpdfsdk/src/javascript/app.cpp |
+++ b/fpdfsdk/src/javascript/app.cpp |
@@ -1037,15 +1037,13 @@ FX_BOOL app::response(OBJ_METHOD_PARAMS) |
CFX_WideString swTitle = L"PDF"; |
#endif |
CFX_WideString swDefault = L""; |
- CFX_WideString swResponse = L""; |
bool bPassWord = false; |
- |
+ |
v8::Isolate* isolate = GetIsolate(cc); |
- |
- int iLength = params.size(); |
+ |
+ int iLength = params.size(); |
if (iLength > 0 && params[0].GetType() == VT_object) |
{ |
- |
JSObject pObj = (JSObject )params[0]; |
v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion"); |
swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString(); |
@@ -1101,22 +1099,23 @@ FX_BOOL app::response(OBJ_METHOD_PARAMS) |
CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
ASSERT(pApp != NULL); |
- int nLength = 2048; |
- char* pBuff = new char[nLength]; |
- nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength); |
- if(nLength<=0) |
+ |
+ const int kMaxInputBytes = 2048; |
jun_fang
2014/07/29 18:12:24
It's suggested to use uppercase like MAX_INPUT_BYP
|
+ char* pBuff = new char[kMaxInputBytes + 2]; |
+ if (!pBuff) |
+ return FALSE; |
+ |
+ memset(pBuff, 0, kMaxInputBytes + 2); |
+ int nLengthBytes = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, kMaxInputBytes); |
+ if (nLengthBytes <= 0 || nLengthBytes > kMaxInputBytes) |
jun_fang
2014/07/29 18:03:36
I saw the comments for the function of app_respons
|
{ |
- delete[] pBuff; |
vRet.SetNull(); |
+ delete[] pBuff; |
return FALSE; |
} |
- else |
- { |
- nLength = nLength > sizeof(pBuff) ? sizeof(pBuff) : nLength; |
- vRet = swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength / 2); |
- } |
- delete[] pBuff; |
+ vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes / 2); |
+ delete[] pBuff; |
return TRUE; |
} |