From b299b3449289389ff7dcaa2708abbe87c617bb25 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 10 Jan 2020 18:17:14 +0100 Subject: [PATCH 1/3] Issue #1338 - Un-bust building of NSS after update to 3.48 on Linux. --- security/nss/coreconf/Linux.mk | 2 +- security/nss/coreconf/config.gypi | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/security/nss/coreconf/Linux.mk b/security/nss/coreconf/Linux.mk index d07f8a3c5e..854d3ca96e 100644 --- a/security/nss/coreconf/Linux.mk +++ b/security/nss/coreconf/Linux.mk @@ -21,7 +21,7 @@ ifeq ($(USE_PTHREADS),1) endif DEFAULT_COMPILER = gcc -DEFINES += -D_DEFAULT_SOURCE -D_BSD_SOURCE +DEFINES += -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE ifeq ($(OS_TARGET),Android) ifndef ANDROID_NDK diff --git a/security/nss/coreconf/config.gypi b/security/nss/coreconf/config.gypi index 3b049111a8..adb344e795 100644 --- a/security/nss/coreconf/config.gypi +++ b/security/nss/coreconf/config.gypi @@ -357,6 +357,7 @@ 'linux', '_DEFAULT_SOURCE', # for functions, strdup, realpath, and getentropy '_BSD_SOURCE', # for the above in glibc <= 2.19 + '_POSIX_SOURCE', # for ], }], [ 'OS=="dragonfly" or OS=="freebsd"', { From 01ba6b6d82423e0ff8de7abb3f9eb4c6e9596fc9 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 10 Jan 2020 19:40:14 +0100 Subject: [PATCH 2/3] Update GTK clipboard handling - Store the clipboard even if it was set in a GTK dialog. - Fix a GtkTargetList leak. - Notify GTK that the data is no longer available for clipboard_get_cb(), so that GTK will no longer advertise nor attempt to store the data. --- widget/gtk/nsClipboard.cpp | 51 ++++++++++++++++++++++---------------- widget/gtk/nsClipboard.h | 5 ++-- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/widget/gtk/nsClipboard.cpp b/widget/gtk/nsClipboard.cpp index 950be1dc4a..1ae3673b0d 100644 --- a/widget/gtk/nsClipboard.cpp +++ b/widget/gtk/nsClipboard.cpp @@ -120,24 +120,13 @@ NS_IMETHODIMP nsClipboard::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData) { if (strcmp(aTopic, "quit-application") == 0) { - // application is going to quit, save clipboard content - Store(); + // Application is going to quit, save clipboard content + gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); gdk_window_remove_filter(nullptr, selection_request_filter, nullptr); } return NS_OK; } -nsresult -nsClipboard::Store(void) -{ - // Ask the clipboard manager to store the current clipboard content - if (mGlobalTransferable) { - GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); - gtk_clipboard_store(clipboard); - } - return NS_OK; -} - NS_IMETHODIMP nsClipboard::SetData(nsITransferable *aTransferable, nsIClipboardOwner *aOwner, int32_t aWhichClipboard) @@ -152,9 +141,6 @@ nsClipboard::SetData(nsITransferable *aTransferable, return NS_OK; } - // Clear out the clipboard in order to set the new data - EmptyClipboard(aWhichClipboard); - // List of suported targets GtkTargetList *list = gtk_target_list_new(nullptr, 0); @@ -163,8 +149,12 @@ nsClipboard::SetData(nsITransferable *aTransferable, nsresult rv = aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavors)); - if (!flavors || NS_FAILED(rv)) + if (!flavors || NS_FAILED(rv)) { + // Clear references to the any old data and let GTK know that it is no + // longer available. + EmptyClipboard(aWhichClipboard); return NS_ERROR_FAILURE; + } // Add all the flavors to this widget's supported type. bool imagesAdded = false; @@ -232,8 +222,10 @@ nsClipboard::SetData(nsITransferable *aTransferable, } rv = NS_OK; - } - else { + } else { + // Clear references to the any old data and let GTK know that it is no + // longer available. + EmptyClipboard(aWhichClipboard); rv = NS_ERROR_FAILURE; } @@ -373,6 +365,23 @@ nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) NS_IMETHODIMP nsClipboard::EmptyClipboard(int32_t aWhichClipboard) { + if (aWhichClipboard == kSelectionClipboard) { + if (mSelectionTransferable) { + gtk_clipboard_clear(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); + MOZ_ASSERT(!mSelectionTransferable); + } + } else { + if (mGlobalTransferable) { + gtk_clipboard_clear(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); + MOZ_ASSERT(!mGlobalTransferable); + } + } + + return NS_OK; +} + +void +nsClipboard::ClearTransferable(int32_t aWhichClipboard) { if (aWhichClipboard == kSelectionClipboard) { if (mSelectionOwner) { mSelectionOwner->LosingOwnership(mSelectionTransferable); @@ -387,8 +396,6 @@ nsClipboard::EmptyClipboard(int32_t aWhichClipboard) } mGlobalTransferable = nullptr; } - - return NS_OK; } NS_IMETHODIMP @@ -652,7 +659,7 @@ nsClipboard::SelectionClearEvent(GtkClipboard *aGtkClipboard) else return; // THAT AIN'T NO CLIPBOARD I EVER HEARD OF - EmptyClipboard(whichClipboard); + ClearTransferable(whichClipboard); } void diff --git a/widget/gtk/nsClipboard.h b/widget/gtk/nsClipboard.h index 70c866a013..c3129bf208 100644 --- a/widget/gtk/nsClipboard.h +++ b/widget/gtk/nsClipboard.h @@ -39,13 +39,12 @@ private: static GdkAtom GetSelectionAtom (int32_t aWhichClipboard); static GtkSelectionData *GetTargets (GdkAtom aWhichClipboard); - // Save global clipboard content to gtk - nsresult Store (void); - // Get our hands on the correct transferable, given a specific // clipboard nsITransferable *GetTransferable (int32_t aWhichClipboard); + void ClearTransferable(int32_t aWhichClipboard); + // Hang on to our owners and transferables so we can transfer data // when asked. nsCOMPtr mSelectionOwner; From 75fdf9c3b0dde1b60f5e1a519a40070e571871ef Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 10 Jan 2020 20:34:53 +0100 Subject: [PATCH 3/3] Issue #1338 - Followup: certdb: propagate trust information if trust module is loaded afterwards, Summary: When the builtin trust module is loaded after some temp certs being created, these temp certs are usually not accompanied by trust information. This causes a problem in UXP as it loads the module from a separate thread while accessing the network cache which populates temp certs. This change makes it properly roll up the trust information, if a temp cert doesn't have trust information. --- security/nss/lib/pki/pki3hack.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/security/nss/lib/pki/pki3hack.c b/security/nss/lib/pki/pki3hack.c index 29d2fb5a40..eac4a5705e 100644 --- a/security/nss/lib/pki/pki3hack.c +++ b/security/nss/lib/pki/pki3hack.c @@ -921,14 +921,28 @@ stan_GetCERTCertificate(NSSCertificate *c, PRBool forceUpdate) } if (!cc->nssCertificate || forceUpdate) { fill_CERTCertificateFields(c, cc, forceUpdate); - } else if (CERT_GetCertTrust(cc, &certTrust) != SECSuccess && - !c->object.cryptoContext) { - /* if it's a perm cert, it might have been stored before the - * trust, so look for the trust again. But a temp cert can be - * ignored. - */ - CERTCertTrust *trust = NULL; - trust = nssTrust_GetCERTCertTrustForCert(c, cc); + } else if (CERT_GetCertTrust(cc, &certTrust) != SECSuccess) { + CERTCertTrust *trust; + if (!c->object.cryptoContext) { + /* If it's a perm cert, it might have been stored before the + * trust, so look for the trust again. + */ + trust = nssTrust_GetCERTCertTrustForCert(c, cc); + } else { + /* If it's a temp cert, it might have been stored before the + * builtin trust module is loaded, so look for the trust + * again, but don't set the empty trust if it is not found. + */ + NSSTrust *t = nssTrustDomain_FindTrustForCertificate(c->object.cryptoContext->td, c); + if (!t) { + goto loser; + } + trust = cert_trust_from_stan_trust(t, cc->arena); + nssTrust_Destroy(t); + if (!trust) { + goto loser; + } + } CERT_LockCertTrust(cc); cc->trust = trust;