external/fontconfig/UnpackedTarball_fontconfig.mk |    3 +++
 external/fontconfig/ubsan.patch                   |   11 +++++++++++
 sc/source/core/opencl/op_financial.cxx            |   14 ++++++++++++--
 sc/source/core/opencl/op_math.cxx                 |    2 ++
 sc/source/core/opencl/op_statistical.cxx          |    4 ++--
 5 files changed, 30 insertions(+), 4 deletions(-)

New commits:
commit 2dca86cde303ca41f835132ce03105cbedde4cce
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Tue Sep 20 07:41:14 2022 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Tue Sep 20 08:45:16 2022 +0200

    external/fontconfig: Avoid UBSan invalid-null-argument
    
    ...as seen when CppunitTest_services is run while instdir/share/fonts/ 
happens
    to still be unpopulated (which is otherwise not an issue for that test),
    
    > fcdir.c:268:11: runtime error: null pointer passed as argument 1, which 
is declared to never be null
    > /usr/include/stdlib.h:852:30: note: nonnull attribute specified here
    >  #0 in FcDirScanConfig at 
workdir/UnpackedTarball/fontconfig/src/fcdir.c:268:5
    >  #1 in FcDirCacheScan at 
workdir/UnpackedTarball/fontconfig/src/fcdir.c:354:10
    >  #2 in FcDirCacheRead at 
workdir/UnpackedTarball/fontconfig/src/fcdir.c:462:10
    >  #3 in FcConfigAddDirList at 
workdir/UnpackedTarball/fontconfig/src/fccfg.c:537:10
    >  #4 in FcConfigAppFontAddDir at 
workdir/UnpackedTarball/fontconfig/src/fccfg.c:2912:10
    >  #5 in psp::PrintFontManager::addFontconfigDir(rtl::OString const&) at 
vcl/unx/generic/fontmanager/fontconfig.cxx:748:20
    >  #6 in psp::PrintFontManager::initialize() at 
vcl/unx/generic/fontmanager/fontmanager.cxx:711:17
    >  #7 in GenericUnixSalData::InitPrintFontManager() at 
vcl/unx/generic/app/gendata.cxx:51:26
    >  #8 in GenericUnixSalData::GetPrintFontManager() at 
vcl/inc/unx/gendata.hxx:88:13
    >  #9 in psp::PrintFontManager::get() at 
vcl/unx/generic/fontmanager/fontmanager.cxx:108:23
    >  #10 in 
GenPspGraphics::GetDevFontListHelper(vcl::font::PhysicalFontCollection*) at 
vcl/unx/generic/print/genpspgraphics.cxx:264:35
    >  #11 in 
FreeTypeTextRenderImpl::GetDevFontList(vcl::font::PhysicalFontCollection*) at 
vcl/unx/generic/gdi/freetypetextrender.cxx:110:5
    >  #12 in 
SvpSalGraphics::GetDevFontList(vcl::font::PhysicalFontCollection*) at 
vcl/headless/svptext.cxx:51:23
    >  #13 in OutputDevice::ImplInitFontList() const at 
vcl/source/outdev/font.cxx:651:17
    >  #14 in OutputDevice::GetDefaultFont(DefaultFontType, 
o3tl::strong_int<unsigned short, LanguageTypeTag>, GetDefaultFontFlags, 
OutputDevice const*) at vcl/source/outdev/font.cxx:532:22
    >  #15 in SwStdFontConfig::GetDefaultFor(unsigned short, 
o3tl::strong_int<unsigned short, LanguageTypeTag>) at 
sw/source/uibase/config/fontcfg.cxx:245:23
    >  #16 in SwStdFontConfig::SwStdFontConfig() at 
sw/source/uibase/config/fontcfg.cxx:91:30
    >  #17 in SwModule::SwModule(SfxObjectFactory*, SfxObjectFactory*, 
SfxObjectFactory*) at sw/source/uibase/app/swmodule.cxx:150:32
    >  #18 in std::__detail::_MakeUniq<SwModule>::__single_object 
std::make_unique<SwModule, SfxObjectFactory*&, SfxObjectFactory*&, 
SfxObjectFactory*&>(SfxObjectFactory*&, SfxObjectFactory*&, SfxObjectFactory*&) 
at 
~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/13.0.0/../../../../include/c++/13.0.0/bits/unique_ptr.h:1076:34
    >  #19 in SwDLL::SwDLL() at sw/source/uibase/app/swdll.cxx:98:26
    >  #20 in (anonymous namespace)::SwDLLInstance::SwDLLInstance() at 
sw/source/uibase/app/swdll.cxx:57:212
    >  #21 in rtl::Static<(anonymous namespace)::SwDLLInstance, (anonymous 
namespace)::theSwDLLInstance>::get() at include/rtl/instance.hxx:399:18
    >  #22 in SwGlobals::ensure() at sw/source/uibase/app/swdll.cxx:70:9
    >  #23 in SwXAutoTextContainer_get_implementation at 
sw/source/uibase/uno/unoatxt.cxx:1015:5
    
    Change-Id: Ic0d246e6012b3cd2c9a9deb63c2af7258f31f0d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140214
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/external/fontconfig/UnpackedTarball_fontconfig.mk 
b/external/fontconfig/UnpackedTarball_fontconfig.mk
index 6026a817c5ed..f41b21cdf552 100644
--- a/external/fontconfig/UnpackedTarball_fontconfig.mk
+++ b/external/fontconfig/UnpackedTarball_fontconfig.mk
@@ -11,8 +11,11 @@ $(eval $(call gb_UnpackedTarball_UnpackedTarball,fontconfig))
 
 $(eval $(call 
gb_UnpackedTarball_set_tarball,fontconfig,$(FONTCONFIG_TARBALL),,fontconfig))
 
+$(eval $(call gb_UnpackedTarball_set_patchlevel,fontconfig,0))
+
 $(eval $(call gb_UnpackedTarball_add_patches,fontconfig,\
        external/fontconfig/fontconfig-2.12.1.patch.1 \
+       external/fontconfig/ubsan.patch \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/fontconfig/ubsan.patch b/external/fontconfig/ubsan.patch
new file mode 100644
index 000000000000..5951f09fe6dd
--- /dev/null
+++ b/external/fontconfig/ubsan.patch
@@ -0,0 +1,11 @@
+--- src/fcdir.c
++++ src/fcdir.c
+@@ -265,7 +265,7 @@
+     /*
+      * Sort files to make things prettier
+      */
+-    qsort(files->strs, files->num, sizeof(FcChar8 *), cmpstringp);
++    if (files->num != 0) qsort(files->strs, files->num, sizeof(FcChar8 *), 
cmpstringp);
+ 
+     /*
+      * Scan file files to build font patterns
commit b014adf12d70f00369adaf3dc4d836c4c5d17b94
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Mon Sep 19 17:50:50 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Tue Sep 20 08:45:02 2022 +0200

    error handling in openCL FORECAST(), MIRR() and SERIESSUM()
    
    Change-Id: Ied72d13953ebd765fc0ed8838b557487f5f74e2d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140190
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/opencl/op_financial.cxx 
b/sc/source/core/opencl/op_financial.cxx
index 3073ba33195a..83c9472e6c22 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -726,18 +726,28 @@ void MIRR::GenSlidingWindowFunction(
     ss << "double NPV_reinvest = 0.0;\n\t";
     ss << "double Pow_reinvest = 1.0;\n\t";
     ss << "int nCount = 0;\n\t";
+    ss << "bool bHasPosValue = false;\n";
+    ss << "bool bHasNegValue = false;\n";
     GenerateRangeArg( 0, vSubArguments, ss,
         "        if (!isnan(arg))\n"
-        "            {\n"
+        "        {\n"
         "            if (arg > 0.0)\n"
+        "            {\n"
         "                NPV_reinvest += arg * Pow_reinvest;\n"
+        "                bHasPosValue = true;\n"
+        "            }\n"
         "            else if (arg < 0.0)\n"
+        "            {\n"
         "                NPV_invest += arg * Pow_invest;\n"
+        "                bHasNegValue = true;\n"
+        "            }\n"
         "            Pow_reinvest /= reinvest;\n"
         "            Pow_invest /= invest;\n"
         "            nCount++;\n"
-        "            }\n"
+        "        }\n"
         );
+    ss << "if ( !( bHasPosValue && bHasNegValue ) )\n";
+    ss << "    return CreateDoubleError(IllegalArgument);\n";
     ss << "tmp = ";
     ss << "-NPV_reinvest /NPV_invest * pow(reinvest,(double)nCount-1);\n\t";
     ss << "tmp =  pow(tmp, 1.0 / (nCount - 1)) - 1.0;\n\t";
diff --git a/sc/source/core/opencl/op_math.cxx 
b/sc/source/core/opencl/op_math.cxx
index 7c44d7b1e462..249a03416bb5 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -1443,6 +1443,8 @@ void OpSeriesSum::GenSlidingWindowFunction(outputstream 
&ss,
     GenerateArg( "var0", 0, vSubArguments, ss );
     GenerateArg( "var1", 1, vSubArguments, ss );
     GenerateArg( "var2", 2, vSubArguments, ss );
+    ss << "    if( var0 == 0 && var1 == 0 )\n";
+    ss << "        return CreateDoubleError(NoValue);\n"; // pow(0,0)
     ss << "    var[0] = var0;\n";
     ss << "    var[1] = var1;\n";
     ss << "    var[2] = var2;\n";
diff --git a/sc/source/core/opencl/op_statistical.cxx 
b/sc/source/core/opencl/op_statistical.cxx
index 4cb421020ce7..9f14c0bbdd40 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -2756,10 +2756,10 @@ void OpForecast::GenSlidingWindowFunction(outputstream 
&ss,
         ss << ";\n";
     }
     else
-        ss << "return HUGE_VAL";
+        throw Unhandled(__FILE__, __LINE__);
     if(pCur1->GetType() != formula::svDoubleVectorRef ||
         pCur2->GetType() != formula::svDoubleVectorRef)
-        ss << "return HUGE_VAL";
+        throw Unhandled(__FILE__, __LINE__);
     else
     {
         ss<< "    if(isnan(arg0)||(gid0>=";

Reply via email to