From 6e69b90af51155091190525e1da361a1d883e442 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 13 Dec 2024 03:49:50 +0000 Subject: [PATCH] Bug 1935437 - Check in case libName could be nullptr before passing it inside the std::string constructor in LoadedLibraryInfo constructor r=profiler-reviewers,florian Before the shared-libraries code deduplication, we were using nsCString for the `LoadedLibraryInfo::mName`. After the deduplication we started to use `std::string`. Before, it was fine to pass nullptr as a parameter to nsCString as it could easily handle it and act as if it's an empty string. But it's an undefined behavior on `std::string`. And passing a nullptr actively crashes Firefox when there is a BHR hang detected (as it uses the shared libraries code). So now, instead of directly passing `dl_info->dlpi_name` inside `std::string`, I'm checking if it's a nullptr or not, and if so I'm passing an empty string so we don't crash there. Differential Revision: https://phabricator.services.mozilla.com/D231926 UltraBlame original commit: 2cb187c7d3f15302a7c2665b10157f50155cdbf1 --- .../core/shared-libraries-linux.cc | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mozglue/baseprofiler/core/shared-libraries-linux.cc b/mozglue/baseprofiler/core/shared-libraries-linux.cc index ab7813c268ee..b3f4c3783de8 100644 --- a/mozglue/baseprofiler/core/shared-libraries-linux.cc +++ b/mozglue/baseprofiler/core/shared-libraries-linux.cc @@ -3607,6 +3607,24 @@ end ; } } +const +char +* +libName += +dl_info +- +> +dlpi_name +? +dl_info +- +> +dlpi_name +: +" +" +; libInfoList - > @@ -3614,10 +3632,7 @@ push_back ( LoadedLibraryInfo ( -dl_info -- -> -dlpi_name +libName baseAddress firstMappingStart lastMappingEnd