javaruntimes/midp/runtimestarter/src/midpruntimestarter.cpp
branchRCL_3
changeset 25 9ac0a0a7da70
parent 24 0fd27995241b
child 34 71c436fe3ce0
equal deleted inserted replaced
24:0fd27995241b 25:9ac0a0a7da70
   588     return heapSize;
   588     return heapSize;
   589 }
   589 }
   590 
   590 
   591 std::wstring MidpRuntimeStarter::encodeArgs(const std::wstring& str)
   591 std::wstring MidpRuntimeStarter::encodeArgs(const std::wstring& str)
   592 {
   592 {
   593     // Modify the places where the following characters are used to prevent
   593     // Encode each 16 bit (or 8 bit) character to 4 (or 2) safe characters to prevent
   594     // possible security problems when this string is passed as an command line
   594     // possible security problems when this string is passed as an command line
   595     // system property parameter to JVM
   595     // system property parameter to JVM
   596     const std::wstring specials(L"= -%");
       
   597 
       
   598     std::string::size_type idx = str.find_first_of(specials);
       
   599     std::string::size_type cur = 0;
       
   600 
       
   601     std::wstring res;
   596     std::wstring res;
   602     std::string convBuf;
   597     int len = str.length();
   603 
   598 
   604     while (idx != std::string::npos)
   599     for (int pos = 0; pos < len; ++pos)
   605     {
   600     {
   606         // Add all characters up to and including the current special char to
   601         wchar_t c = str[pos];
   607         // final result string
   602         if (c & 0xFF00)
   608         if (idx >= cur)
   603         {
   609         {
   604             // 16 bit char, must send all bits
   610             res.append(str.substr(cur, (idx - cur) + 1));
   605             res += ( L'A' + (c >> 12) );
   611         }
   606             res += ( L'A' + ((c & 0x0F00) >> 8) );
   612 
   607             res += ( L'A' + ((c & 0x00F0) >> 4) );
   613         // Encode all special characters 'X' in same way.
   608             res += ( L'A' + ((c & 0x000F)) );
   614         // "X" -> "X%"
   609         }
   615         res.append(L"%");
   610         else
   616 
   611         {
   617         cur = idx + 1;
   612             // 8 bit char, send only lowest 8 bits
   618         idx = str.find_first_of(specials, cur);
   613             res += ( L'a' + ((c & 0x00F0) >> 4) );
   619     }
   614             res += ( L'a' + ((c & 0x000F)) );
   620 
   615         }
   621     // Add characters after last special character if any
   616     }
   622     res.append(str.substr(cur, str.length() - cur));
       
   623 
   617 
   624     return res;
   618     return res;
   625 }
   619 }
   626 
   620 
   627 void MidpRuntimeStarter::getMIDletSuiteUidFromStorage(java::storage::JavaStorage& storage)
   621 void MidpRuntimeStarter::getMIDletSuiteUidFromStorage(java::storage::JavaStorage& storage)