summaryrefslogtreecommitdiffstats
path: root/mozglue
diff options
context:
space:
mode:
Diffstat (limited to 'mozglue')
-rw-r--r--mozglue/android/NSSBridge.cpp114
-rw-r--r--mozglue/android/NSSBridge.h4
-rw-r--r--mozglue/build/WindowsDllBlocklist.cpp11
-rw-r--r--mozglue/misc/TimeStamp_windows.cpp56
4 files changed, 59 insertions, 126 deletions
diff --git a/mozglue/android/NSSBridge.cpp b/mozglue/android/NSSBridge.cpp
index 2a9b5771d..3343ad1b2 100644
--- a/mozglue/android/NSSBridge.cpp
+++ b/mozglue/android/NSSBridge.cpp
@@ -37,6 +37,10 @@ NSS_WRAPPER_INT(PL_Base64Encode)
NSS_WRAPPER_INT(PL_Base64Decode)
NSS_WRAPPER_INT(PL_strfree)
+SECStatus doCrypto(JNIEnv* jenv, const char *path, const char *value, char** result, bool doEncrypt);
+SECStatus encode(const uint8_t* data, uint32_t srclen, char** result);
+SECStatus decode(const char* data, uint8_t** result, uint32_t* length);
+
int
setup_nss_functions(void *nss_handle,
void *nspr_handle,
@@ -189,41 +193,40 @@ doCrypto(JNIEnv* jenv, const char *path, const char *value, char** result, bool
keyid.len = 0;
rv = f_PK11SDR_Encrypt(&keyid, &request, &reply, nullptr);
- if (rv != SECSuccess) {
+ if (rv == SECSuccess) {
+ rv = encode(reply.data, reply.len, result);
+ if (rv == SECSuccess) {
+ LOG("Encrypted: %s\n", *result);
+ } else {
+ throwError(jenv, "encode");
+ }
+ } else {
throwError(jenv, "PK11SDR_Encrypt");
- goto done;
}
- rv = encode(reply.data, reply.len, result);
- if (rv != SECSuccess) {
- throwError(jenv, "encode");
- goto done;
- }
- LOG("Encrypted: %s\n", *result);
} else {
LOG("Decoding: %s\n", value);
- rv = decode(value, &request.data, (int32_t*)&request.len);
+ rv = decode(value, &request.data, &request.len);
if (rv != SECSuccess) {
throwError(jenv, "decode");
return rv;
}
rv = f_PK11SDR_Decrypt(&request, &reply, nullptr);
- if (rv != SECSuccess) {
- throwError(jenv, "PK11SDR_Decrypt");
- goto done;
- }
- *result = (char *)malloc(reply.len+1);
- strncpy(*result, (char *)reply.data, reply.len);
- (*result)[reply.len] = '\0';
+ if (rv == SECSuccess) {
+ *result = static_cast<char*>(malloc(reply.len + 1));
+ strncpy(*result, reinterpret_cast<char*>(reply.data), reply.len);
+ (*result)[reply.len] = '\0';
- // This can print sensitive data. Uncomment if you need it.
- // LOG("Decoded %i letters: %s\n", reply.len, *result);
+ // This can print sensitive data. Uncomment if you need it.
+ // LOG("Decoded %i letters: %s\n", reply.len, *result);
+ } else {
+ throwError(jenv, "PK11SDR_Decrypt");
+ }
free(request.data);
}
-done:
f_SECITEM_ZfreeItem(&reply, false);
return rv;
}
@@ -232,64 +235,51 @@ done:
* Base64 encodes the data passed in. The caller must deallocate _retval using free();
*/
SECStatus
-encode(const unsigned char *data, int32_t dataLen, char **_retval)
+encode(const uint8_t* data, uint32_t srclen, char** result)
{
- SECStatus rv = SECSuccess;
- char *encoded = f_PL_Base64Encode((const char *)data, dataLen, nullptr);
- if (!encoded)
- rv = SECFailure;
- if (!*encoded)
- rv = SECFailure;
-
- if (rv == SECSuccess) {
- *_retval = (char *)malloc(strlen(encoded)+1);
- strcpy(*_retval, encoded);
+ if (srclen > (PR_UINT32_MAX / 4) * 3) {
+ return SECFailure;
}
- if (encoded) {
- f_PR_Free(encoded);
+ const uint32_t dstlen = ((srclen + 2) / 3) * 4;
+ char* const buffer = static_cast<char*>(malloc(dstlen + 1));
+
+ if (!buffer || !f_PL_Base64Encode(reinterpret_cast<const char*>(data), srclen, buffer)) {
+ free(buffer);
+ *result = nullptr;
+ return SECFailure;
}
- return rv;
+ buffer[dstlen] = '\0';
+ *result = buffer;
+ return SECSuccess;
}
/*
* Base64 decodes the data passed in. The caller must deallocate result using free();
*/
SECStatus
-decode(const char *data, unsigned char **result, int32_t *length)
+decode(const char* data, uint8_t** result, uint32_t* length)
{
- SECStatus rv = SECSuccess;
- uint32_t len = strlen(data);
- int adjust = 0;
-
- /* Compute length adjustment */
- if (len > 0 && data[len-1] == '=') {
- adjust++;
- if (data[len-2] == '=') adjust++;
+ uint32_t srclen = strlen(data);
+ while (srclen && data[srclen - 1] == '=') {
+ srclen--;
}
- char *decoded;
- decoded = f_PL_Base64Decode(data, len, nullptr);
- if (!decoded) {
- return SECFailure;
- }
- if (!*decoded) {
+ // Avoid overflow when calculating result length.
+ const uint32_t dstlen = (srclen / 4) * 3 + ((srclen % 4) * 3) / 4;
+ // At most 2 extra bytes due to padding in input.
+ uint8_t* const buffer = static_cast<uint8_t*>(malloc(dstlen + 2));
+
+ if (!buffer || !f_PL_Base64Decode(data, srclen, reinterpret_cast<char*>(buffer))) {
+ free(buffer);
+ *result = nullptr;
+ *length = 0;
return SECFailure;
}
- *length = (len*3)/4 - adjust;
- LOG("Decoded %i chars into %i chars\n", len, *length);
-
- *result = (unsigned char*)malloc((size_t)len);
-
- if (!*result) {
- rv = SECFailure;
- } else {
- memcpy((char*)*result, decoded, len);
- }
- f_PR_Free(decoded);
- return rv;
+ buffer[dstlen] = '\0';
+ *result = buffer;
+ *length = dstlen;
+ return SECSuccess;
}
-
-
diff --git a/mozglue/android/NSSBridge.h b/mozglue/android/NSSBridge.h
index 77bcd1172..83ec8d749 100644
--- a/mozglue/android/NSSBridge.h
+++ b/mozglue/android/NSSBridge.h
@@ -39,8 +39,4 @@ NSS_WRAPPER(PK11_GetInternalKeySlot, PK11SlotInfo *, void)
NSS_WRAPPER(PK11_NeedUserInit, PRBool, PK11SlotInfo *)
NSS_WRAPPER(PK11_InitPin, SECStatus, PK11SlotInfo*, const char*, const char*)
-bool setPassword(PK11SlotInfo *slot);
-SECStatus doCrypto(JNIEnv* jenv, const char *path, const char *value, char** result, bool doEncrypt);
-SECStatus encode(const unsigned char *data, int32_t dataLen, char **_retval);
-SECStatus decode(const char *data, unsigned char **result, int32_t * _retval);
#endif /* NSS_h */
diff --git a/mozglue/build/WindowsDllBlocklist.cpp b/mozglue/build/WindowsDllBlocklist.cpp
index a3c662723..9b63d6673 100644
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -67,7 +67,6 @@ struct DllBlockInfo {
enum {
FLAGS_DEFAULT = 0,
BLOCK_WIN8PLUS_ONLY = 1,
- BLOCK_XP_ONLY = 2,
USE_TIMESTAMP = 4,
} flags;
};
@@ -156,9 +155,6 @@ static DllBlockInfo sWindowsDllBlocklist[] = {
// Topcrash with Conduit SearchProtect, bug 944542
{ "spvc32.dll", ALL_VERSIONS },
- // XP topcrash with F-Secure, bug 970362
- { "fs_ccf_ni_umh32.dll", MAKE_VERSION(1, 42, 101, 0), DllBlockInfo::BLOCK_XP_ONLY },
-
// Topcrash with V-bates, bug 1002748 and bug 1023239
{ "libinject.dll", UNVERSIONED },
{ "libinject2.dll", 0x537DDC93, DllBlockInfo::USE_TIMESTAMP },
@@ -676,11 +672,6 @@ patched_LdrLoadDll (PWCHAR filePath, PULONG flags, PUNICODE_STRING moduleFileNam
goto continue_loading;
}
- if ((info->flags == DllBlockInfo::BLOCK_XP_ONLY) &&
- IsWin2003OrLater()) {
- goto continue_loading;
- }
-
unsigned long long fVersion = ALL_VERSIONS;
if (info->maxVersion != ALL_VERSIONS) {
@@ -749,7 +740,7 @@ continue_loading:
return STATUS_DLL_NOT_FOUND;
}
- if (IsVistaOrLater() && !CheckASLR(full_fname.get())) {
+ if (!CheckASLR(full_fname.get())) {
printf_stderr("LdrLoadDll: Blocking load of '%s'. XPCOM components must support ASLR.\n", dllName);
return STATUS_DLL_NOT_FOUND;
}
diff --git a/mozglue/misc/TimeStamp_windows.cpp b/mozglue/misc/TimeStamp_windows.cpp
index cd519affd..683c2209a 100644
--- a/mozglue/misc/TimeStamp_windows.cpp
+++ b/mozglue/misc/TimeStamp_windows.cpp
@@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Implement TimeStamp::Now() with QueryPerformanceCounter() controlled with
-// values of GetTickCount().
+// values of GetTickCount64().
#include "mozilla/MathAlgorithms.h"
#include "mozilla/TimeStamp.h"
@@ -69,7 +69,7 @@ static const DWORD kDefaultTimeIncrement = 156001;
* further just referred as [mt], meaning milli-ticks.
*
* This is needed to preserve maximum precision of the performance frequency
- * representation. GetTickCount values in milliseconds are multiplied with
+ * representation. GetTickCount64 values in milliseconds are multiplied with
* frequency per second. Therefor we need to multiply QPC value by 1000 to
* have the same units to allow simple arithmentic with both QPC and GTC.
*/
@@ -156,41 +156,8 @@ static CRITICAL_SECTION sTimeStampLock;
// Kept in [mt]
static ULONGLONG sFaultIntoleranceCheckpoint = 0;
-// Used only when GetTickCount64 is not available on the platform.
-// Last result of GetTickCount call.
-//
-// Kept in [ms]
-static DWORD sLastGTCResult = 0;
-
-// Higher part of the 64-bit value of MozGetTickCount64,
-// incremented atomically.
-static DWORD sLastGTCRollover = 0;
-
namespace mozilla {
-typedef ULONGLONG (WINAPI* GetTickCount64_t)();
-static GetTickCount64_t sGetTickCount64 = nullptr;
-
-// Function protecting GetTickCount result from rolling over,
-// result is in [ms]
-static ULONGLONG WINAPI
-MozGetTickCount64()
-{
- DWORD GTC = ::GetTickCount();
-
- // Cheaper then CMPXCHG8B
- AutoCriticalSection lock(&sTimeStampLock);
-
- // Pull the rollover counter forward only if new value of GTC goes way
- // down under the last saved result
- if ((sLastGTCResult > GTC) && ((sLastGTCResult - GTC) > (1UL << 30))) {
- ++sLastGTCRollover;
- }
-
- sLastGTCResult = GTC;
- return ULONGLONG(sLastGTCRollover) << 32 | sLastGTCResult;
-}
-
// Result is in [mt]
static inline ULONGLONG
PerformanceCounter()
@@ -355,7 +322,7 @@ TimeStampValue::CheckQPC(const TimeStampValue& aOther) const
if (duration < sHardFailureLimit) {
// Interval between the two time stamps is very short, consider
// QPC as unstable and record a failure.
- uint64_t now = ms2mt(sGetTickCount64());
+ uint64_t now = ms2mt(GetTickCount64());
AutoCriticalSection lock(&sTimeStampLock);
@@ -485,17 +452,6 @@ TimeStamp::Startup()
gInitialized = true;
- // Decide which implementation to use for the high-performance timer.
-
- HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
- sGetTickCount64 = reinterpret_cast<GetTickCount64_t>(
- GetProcAddress(kernelDLL, "GetTickCount64"));
- if (!sGetTickCount64) {
- // If the platform does not support the GetTickCount64 (Windows XP doesn't),
- // then use our fallback implementation based on GetTickCount.
- sGetTickCount64 = MozGetTickCount64;
- }
-
InitializeCriticalSectionAndSpinCount(&sTimeStampLock, kLockSpinCount);
sHasStableTSC = HasStableTSC();
@@ -504,10 +460,10 @@ TimeStamp::Startup()
LARGE_INTEGER freq;
sUseQPC = ::QueryPerformanceFrequency(&freq);
if (!sUseQPC) {
- // No Performance Counter. Fall back to use GetTickCount.
+ // No Performance Counter. Fall back to use GetTickCount64.
InitResolution();
- LOG(("TimeStamp: using GetTickCount"));
+ LOG(("TimeStamp: using GetTickCount64"));
return;
}
@@ -534,7 +490,7 @@ TimeStamp::Now(bool aHighResolution)
// Both values are in [mt] units.
ULONGLONG QPC = useQPC ? PerformanceCounter() : uint64_t(0);
- ULONGLONG GTC = ms2mt(sGetTickCount64());
+ ULONGLONG GTC = ms2mt(GetTickCount64());
return TimeStamp(TimeStampValue(GTC, QPC, useQPC));
}