Chromium Code Reviews| Index: fpdfsdk/src/javascript/app.cpp |
| diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp |
| index 3b92a992d9d0be2b46db2266d0e51847b0a34fdd..59392f7a410fcc6a2d2e1471f974889dc8b30e00 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,25 @@ 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 MAX_INPUT_BYTES = 2048; |
| + char* pBuff = new char[MAX_INPUT_BYTES + 2]; |
| + if (!pBuff) |
| + return FALSE; |
|
jun_fang
2014/07/29 18:31:31
very minor issue here. It's not aligned with other
|
| + |
| + memset(pBuff, 0, MAX_INPUT_BYTES + 2); |
| + int nLengthBytes = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, MAX_INPUT_BYTES); |
| + if (nLengthBytes <= 0) |
| { |
| - 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; |
| + if (nLengthBytes > MAX_INPUT_BYTES) |
| + nLengthBytes = MAX_INPUT_BYTES; |
| + vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes / 2); |
| + delete[] pBuff; |
| return TRUE; |
| } |