Pull in md5.c directly to avoid early NSS initialization (bug 338590) r=darin

This commit is contained in:
bryner%brianryner.com 2006-05-25 22:58:03 +00:00
Родитель 505b01b9e9
Коммит 4ad105cdbf
4 изменённых файлов: 105 добавлений и 12 удалений

Просмотреть файл

@ -59,7 +59,6 @@ REQUIRES = xpcom \
layout \
widget \
libbz2 \
caps \
xulapp \
extensions \
rdf \
@ -81,6 +80,11 @@ else
REQUIRES += bookmarks
endif
CSRCS = \
md5.c \
nssstubs.c \
$(NULL)
CPPSRCS = \
nsLoadCollector.cpp \
nsMetricsConfig.cpp \
@ -108,3 +112,8 @@ EXTRA_DSO_LDOPTS += -NODEFAULTLIB:MSVCRT \
endif
include $(topsrcdir)/config/rules.mk
export:: $(topsrcdir)/security/nss/lib/freebl/md5.c
$(INSTALL) $^ .
LOCAL_INCLUDES += -I$(srcdir) -I$(DIST)/public/nss -I$(DIST)/private/nss

Просмотреть файл

@ -65,7 +65,8 @@
#include "nsIDOMDocument.h"
#include "nsIDOMSerializer.h"
#include "nsIVariant.h"
#include "nsICryptoHash.h"
#include "blapi.h"
#include "plbase64.h"
#include "nsISimpleEnumerator.h"
#include "nsIInputStreamChannel.h"
#include "nsIFileStreams.h"
@ -282,7 +283,8 @@ nsMetricsService::BadCertListener::GetInterface(const nsIID &uuid,
//-----------------------------------------------------------------------------
nsMetricsService::nsMetricsService()
: mEventCount(0),
: mMD5Context(nsnull),
mEventCount(0),
mSuspendCount(0),
mUploading(PR_FALSE),
mNextWindowID(0),
@ -305,6 +307,8 @@ nsMetricsService::~nsMetricsService()
NS_ASSERTION(sMetricsService == this, ">1 MetricsService object created");
mCollectorMap.EnumerateRead(DetachCollector, nsnull);
MD5_DestroyContext(mMD5Context, PR_TRUE);
sMetricsService = nsnull;
}
@ -945,8 +949,8 @@ nsMetricsService::ProfileStartup()
rv = FlushIntPref(kSessionIDPref, sessionID);
NS_ENSURE_SUCCESS(rv, rv);
mCryptoHash = do_CreateInstance("@mozilla.org/security/hash;1");
NS_ENSURE_TRUE(mCryptoHash, NS_ERROR_FAILURE);
mMD5Context = MD5_NewContext();
NS_ENSURE_TRUE(mMD5Context, NS_ERROR_FAILURE);
// Set up our hashtables
NS_ENSURE_TRUE(mWindowMap.Init(32), NS_ERROR_OUT_OF_MEMORY);
@ -1380,13 +1384,26 @@ nsresult
nsMetricsService::HashBytes(const PRUint8 *bytes, PRUint32 length,
nsACString &result)
{
nsresult rv = mCryptoHash->Init(nsICryptoHash::MD5);
NS_ENSURE_SUCCESS(rv, rv);
unsigned char buf[HASH_LENGTH_MAX];
unsigned int resultLength = 0;
rv = mCryptoHash->Update(bytes, length);
NS_ENSURE_SUCCESS(rv, rv);
MD5_Begin(mMD5Context);
MD5_Update(mMD5Context, bytes, length);
MD5_End(mMD5Context, buf, &resultLength, sizeof(buf));
return mCryptoHash->Finish(PR_TRUE, result);
// Base64-encode the result. The maximum result length is calculated
// as described in plbase64.h.
char *resultBuffer;
if (NS_CStringGetMutableData(
result, ((resultLength + 2) / 3) * 4, &resultBuffer) == 0) {
return NS_ERROR_OUT_OF_MEMORY;
}
PL_Base64Encode(NS_REINTERPRET_CAST(char*, buf), resultLength, resultBuffer);
// Size the string to its null-terminated length
result.SetLength(strlen(resultBuffer));
return NS_OK;
}
PRBool

Просмотреть файл

@ -59,12 +59,12 @@
#include "nsDataHashtable.h"
#include "nsInterfaceHashtable.h"
#include "nsPtrHashKey.h"
#include "blapit.h"
class nsILocalFile;
class nsIDOMWindow;
class nsIDOMDocument;
class nsIDOMNode;
class nsICryptoHash;
class nsIMetricsCollector;
#ifdef PR_LOGGING
@ -237,7 +237,7 @@ private:
nsCOMPtr<nsIDOMNode> mRoot;
// MD5 hashing object for collectors to use
nsCOMPtr<nsICryptoHash> mCryptoHash;
MD5Context *mMD5Context;
// Window to incrementing-id map. The keys are nsIDOMWindow*.
nsDataHashtable< nsPtrHashKey<nsIDOMWindow>, PRUint32 > mWindowMap;

Просмотреть файл

@ -0,0 +1,67 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Metrics extension.
*
* The Initial Developer of the Original Code is Google Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* This file contains trivial implementations of the NSS PORT_* functions
* that md5.c uses.
*/
#include "prmem.h"
#include "prerror.h"
void*
PORT_Alloc(size_t bytes)
{
/* Always allocate a non-zero amount of bytes */
return (void *)PR_Malloc(bytes ? bytes : 1);
}
void
PORT_Free(void *ptr)
{
if (ptr) {
PR_Free(ptr);
}
}
void
PORT_SetError(int value)
{
PR_SetError(value, 0);
return;
}