From 84b3e80cbb16e356979b1c55b01552924ada75a0 Mon Sep 17 00:00:00 2001 From: ler762 Date: Mon, 10 Sep 2018 17:39:34 -0400 Subject: [PATCH 1/2] change the processing of init files - add a new "-no-config" command line option to not read any initialization file - refactor init file processing so that only one file is read The search order is: 1. command line "-config xxx" or "-no-config" options 2. environment variable HTML_TIDY=xxx 3. ~/.tidyrc 4. /etc/tidy.conf --- console/tidy.c | 85 ++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index a7880f6f9..505e0a2ff 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -2075,6 +2075,7 @@ int main( int argc, char** argv ) ctmbstr cfgfil = NULL, errfil = NULL, htmlfil = NULL; TidyDoc tdoc = NULL; int status = 0; + int configSpecified = 0; uint contentErrors = 0; uint contentWarnings = 0; @@ -2104,44 +2105,6 @@ int main( int argc, char** argv ) SetConsoleOutputCP(CP_UTF8); #endif - /* - * Look for default configuration files using any of - * the following possibilities: - * - TIDY_CONFIG_FILE - from tidyplatform.h, typically /etc/tidy.conf - * - HTML_TIDY - environment variable - * - TIDY_USER_CONFIG_FILE - from tidyplatform.h, typically ~/tidy.conf - */ - -#ifdef TIDY_CONFIG_FILE - if ( tidyFileExists( tdoc, TIDY_CONFIG_FILE) ) - { - status = tidyLoadConfig( tdoc, TIDY_CONFIG_FILE ); - if ( status != 0 ) { - fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status); - fprintf(errout, "\n"); - } - } -#endif /* TIDY_CONFIG_FILE */ - - if ( (cfgfil = getenv("HTML_TIDY")) != NULL ) - { - status = tidyLoadConfig( tdoc, cfgfil ); - if ( status != 0 ) { - fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status); - fprintf(errout, "\n"); - } - } -#ifdef TIDY_USER_CONFIG_FILE - else if ( tidyFileExists( tdoc, TIDY_USER_CONFIG_FILE) ) - { - status = tidyLoadConfig( tdoc, TIDY_USER_CONFIG_FILE ); - if ( status != 0 ) { - fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status); - fprintf(errout, "\n"); - } - } -#endif /* TIDY_USER_CONFIG_FILE */ - /* * Read command line @@ -2332,6 +2295,7 @@ int main( int argc, char** argv ) { ctmbstr post; + configSpecified = 1; tidyLoadConfig( tdoc, argv[2] ); /* Set new error output stream if setting changed */ @@ -2347,6 +2311,11 @@ int main( int argc, char** argv ) } } + else if ( strcasecmp(arg, "no-config") == 0 ) + { + configSpecified = 1; + } + else if ( strcasecmp(arg, "output") == 0 || strcasecmp(arg, "-output-file") == 0 || strcasecmp(arg, "o") == 0 ) @@ -2485,6 +2454,46 @@ int main( int argc, char** argv ) continue; } + if ( ! configSpecified ) + { + /* + * Configuration file not specified on the command line so + * look for a configuration file in the order of + * - HTML_TIDY - environment variable + * - TIDY_USER_CONFIG_FILE - from tidyplatform.h, default: ~/.tidyrc + * - TIDY_CONFIG_FILE - from tidyplatform.h, default: /etc/tidy.conf + */ + + if ( (cfgfil = getenv("HTML_TIDY")) != NULL ) + { + status = tidyLoadConfig( tdoc, cfgfil ); + if ( status != 0 ) { + fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status); + fprintf(errout, "\n"); + } + } +#ifdef TIDY_USER_CONFIG_FILE + else if ( tidyFileExists( tdoc, TIDY_USER_CONFIG_FILE) ) + { + status = tidyLoadConfig( tdoc, TIDY_USER_CONFIG_FILE ); + if ( status != 0 ) { + fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status); + fprintf(errout, "\n"); + } + } +#endif /* TIDY_USER_CONFIG_FILE */ +#ifdef TIDY_CONFIG_FILE + else if ( tidyFileExists( tdoc, TIDY_CONFIG_FILE) ) + { + status = tidyLoadConfig( tdoc, TIDY_CONFIG_FILE ); + if ( status != 0 ) { + fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status); + fprintf(errout, "\n"); + } + } +#endif /* TIDY_CONFIG_FILE */ + } /* endif ( ! configSpecified ) */ + if ( argc > 1 ) { From 66b7ed544a147f8dd8ccf8799ea157a271d25bb2 Mon Sep 17 00:00:00 2001 From: ler762 Date: Sat, 15 Sep 2018 20:46:23 -0400 Subject: [PATCH 2/2] enable optimization, DEP and ASLR if building with gcc optimization, data execution prevention and address space layout randomization all seem like Good Things To Have Enabled --- CMakeLists.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 631f0fd59..eee63ee4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,11 +197,27 @@ if(WIN32 AND MSVC) set( CMAKE_DEBUG_POSTFIX "d" ) # little effect in unix else() # add any gcc flags + + set ( CFLAGS "${CFLAGS} -O2") +# -O2: GCC performs nearly all supported optimizations that do not involve +# a space-speed tradeoff. As compared to '-O', this option increases +# both compilation time and the performance of the generated code. + + set ( LDFLAGS "${LDFLAGS} -Wl,--nxcompat") +# https://en.wikipedia.org/wiki/Data_Execution_Prevention +# Enable DEP with -Wl,--nxcompat + + set ( LDFLAGS "-Wl,--dynamicbase,--export-all-symbols") +# https://en.wikipedia.org/wiki/Address_space_layout_randomization +# https://stackoverflow.com/questions/24283918/how-can-i-enable-aslr-dep-and-safeseh-on-an-exe-in-codeblocks-using-mingw +# ASLR with gcc has a problem: -Wl,--dynamicbase doesn't emit the necessary relocation table. +# As a workaround, you can pass -Wl,--dynamicbase,--export-all-symbols + endif() set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" ) -set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}" ) +set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDFLAGS} ${MSVC_LD_FLAGS}" ) #------------------------------------------------------------------------