1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <tools/extendapplicationenvironment.hxx>
13 #include <cppuhelper/bootstrap.hxx>
14 #include <comphelper/processfactory.hxx>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
17 #include <com/sun/star/uno/XComponentContext.hpp>
18 #include <unotools/configmgr.hxx>
19 #include <rtl/bootstrap.hxx>
20 #include <rtl/strbuf.hxx>
21 #include <osl/file.hxx>
22 #include <osl/process.h>
23 #include <vcl/graph.hxx>
24 #include <vcl/print.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/wmf.hxx>
29 #include "headless/svpgdi.hxx"
30 #include "unx/fontmanager.hxx"
31 #include "unx/glyphcache.hxx"
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
39 OUString
getExecutableDir()
42 if (osl_getExecutableFile(&uri
.pData
) != osl_Process_E_None
) {
45 sal_Int32 lastDirSeperatorPos
= uri
.lastIndexOf('/');
46 if (lastDirSeperatorPos
>= 0) {
47 uri
= uri
.copy(0, lastDirSeperatorPos
+ 1);
52 OUString
getExecutableName()
55 if (osl_getExecutableFile(&uri
.pData
) != osl_Process_E_None
) {
58 return uri
.copy(uri
.lastIndexOf('/') + 1);
61 void setFontConfigConf(const OUString
&execdir
)
63 osl::File
aFontConfig("file:///tmp/wmffuzzerfonts.conf");
64 if (aFontConfig
.open(osl_File_OpenFlag_Create
| osl_File_OpenFlag_Write
) == osl::File::E_None
)
67 osl::FileBase::getSystemPathFromFileURL(execdir
, sExecDir
);
69 OStringBuffer
aBuffer("<?xml version=\"1.0\"?>\n<fontconfig><dir>");
70 aBuffer
.append(OUStringToOString(sExecDir
+ getExecutableName() + ".fonts", osl_getThreadTextEncoding()));
71 aBuffer
.append("</dir><cachedir>/tmp/cache/fontconfig</cachedir></fontconfig>");
72 OString aConf
= aBuffer
.makeStringAndClear();
73 sal_uInt64 aBytesWritten
;
74 aFontConfig
.write(aConf
.getStr(), aConf
.getLength(), aBytesWritten
);
75 assert(aBytesWritten
== aConf
.getLength());
77 setenv("FONTCONFIG_FILE", "/tmp/wmffuzzerfonts.conf", 0);
83 __attribute__((weak
)) void __lsan_disable();
84 __attribute__((weak
)) void __lsan_enable();
87 void CommonInitialize(int *argc
, char ***argv
)
89 setenv("SAL_USE_VCLPLUGIN", "svp", 1);
90 setenv("JPEGMEM", "768M", 1);
91 setenv("SC_MAX_MATRIX_ELEMENTS", "60000000", 1);
92 setenv("SC_NO_THREADED_CALCULATION", "1", 1);
93 setenv("SAL_WMF_COMPLEXCLIP_VIA_REGION", "1", 1);
94 setenv("SAL_DISABLE_PRINTERLIST", "1", 1);
95 setenv("SAL_DISABLE_DEFAULTPRINTER", "1", 1);
96 setenv("SAL_NO_FONT_LOOKUP", "1", 1);
98 //allow bubbling of max input len to fuzzer targets
100 for (int i
= 0; i
< *argc
; ++i
)
102 if (strncmp((*argv
)[i
], "-max_len=", 9) == 0)
103 nMaxLen
= atoi((*argv
)[i
] + 9);
105 setenv("FUZZ_MAX_INPUT_LEN", "1", nMaxLen
);
107 osl_setCommandArgs(*argc
, *argv
);
109 OUString sExecDir
= getExecutableDir();
110 rtl::Bootstrap::set("BRAND_BASE_DIR", sExecDir
);
111 setFontConfigConf(sExecDir
);
113 tools::extendApplicationEnvironment();
115 Reference
< XComponentContext
> xContext
=
116 defaultBootstrap_InitialComponentContext(sExecDir
+ getExecutableName() + ".unorc");
117 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
118 if( !xServiceManager
.is() )
119 Application::Abort( "Failed to bootstrap" );
120 comphelper::setProcessServiceFactory( xServiceManager
);
121 utl::ConfigManager::EnableFuzzing();
122 Application::EnableHeadlessMode(false);
125 //we don't have a de-init, so inside this leak disabled region...
127 psp::PrintFontManager::get();
128 //get the printer info
129 Printer::GetPrinterQueues();
132 void TypicalFuzzerInitialize(int *argc
, char ***argv
)
137 CommonInitialize(argc
, argv
);
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */