Skip to content

Aslr #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Aslr #755

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}" )


#------------------------------------------------------------------------
Expand Down
85 changes: 47 additions & 38 deletions console/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand All @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand Down