Clang/GCC compiler settings update [SECURITY] (#7358)

- Add the following compilation flags for clang
  -fpie
  -fstack-protector-all
  -fstack-check (non-release)

- Add the following compilation flags for gcc
  -fpie
  -fstack-protector-all

- Fix -Wunused-result errors from above compilation flag updates

- Add _FORTIFY_SOURCE=2 to GCC DEFINES

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>
This commit is contained in:
Steve Pham
2022-02-07 09:01:07 -08:00
committed by GitHub
parent a6ddf4164f
commit 4d4f10beb8
10 changed files with 88 additions and 43 deletions
@@ -69,9 +69,11 @@ namespace UnitTest
// Note that ConvertToAbsolutePath will perform a realpath on the result. The result of AZ::Utils::GetExecutableDirectory
// uses AZ::Android::AndroidEnv::Get()->GetAppPrivateStoragePath() which will retrieve the storage path, but that path could
// be symlinked, so we need to perform a real path on it before comparison
char realExecutableDirectory[AZ::IO::MaxPathLength];
ASSERT_TRUE(realpath(executableDirectory, realExecutableDirectory));
char* realExecutableDirectory = realpath(executableDirectory, nullptr);
ASSERT_NE(realExecutableDirectory, nullptr);
EXPECT_STRCASEEQ(realExecutableDirectory, absolutePath->c_str());
free(realExecutableDirectory);
}
}
@@ -383,7 +383,7 @@ namespace AZ::IO::ZipDir
if (!AZ::IO::FileIOBase::GetDirectInstance()->Write(m_fileHandle, ptr, sizeToWrite))
{
char error[1024];
azstrerror_s(error, AZ_ARRAY_SIZE(error), errno);
[[maybe_unused]] auto azStrErrorResult = azstrerror_s(error, AZ_ARRAY_SIZE(error), errno);
AZ_Warning("Archive", false, "Cannot write to zip file!! error = (%d): %s", errno, error);
return ZD_ERROR_IO_FAILED;
}
@@ -531,7 +531,7 @@ namespace AZ::IO::ZipDir
if (!WriteCompressedData((uint8_t*)pUncompressed, nSegmentSize, encrypt))
{
char error[1024];
azstrerror_s(error, AZ_ARRAY_SIZE(error), errno);
[[maybe_unused]] auto azStrErrorResult = azstrerror_s(error, AZ_ARRAY_SIZE(error), errno);
AZ_Warning("Archive", false, "Cannot write to zip file!! error = (%d): %s", errno, error);
return ZD_ERROR_IO_FAILED;
}
@@ -120,7 +120,7 @@ namespace AzFramework
int res = chdir(processLaunchInfo.m_workingDirectory.c_str());
if (res != 0)
{
write(errorPipe[1], &errno, sizeof(int));
[[maybe_unused]] auto writeResult = write(errorPipe[1], &errno, sizeof(int));
// We *have* to _exit as we are the child process and simply
// returning at this point would mean we would start running
// the code from our parent process and that will just wreck
@@ -132,15 +132,19 @@ namespace AzFramework
switch (processLaunchInfo.m_processPriority)
{
case PROCESSPRIORITY_BELOWNORMAL:
nice(1);
{
[[maybe_unused]] auto niceResult = nice(1);
// also reduce disk impact:
// setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_UTILITY);
break;
}
case PROCESSPRIORITY_IDLE:
nice(20);
{
[[maybe_unused]] auto niceResult = nice(20);
// also reduce disk impact:
// setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE);
break;
}
}
startupInfo.SetupHandlesForChildProcess();
@@ -153,7 +157,7 @@ namespace AzFramework
// to stop it from continuing to run as a clone of the parent.
// Communicate the error code back to the parent via a pipe for the
// parent to read.
write(errorPipe[1], &errval, sizeof(errval));
[[maybe_unused]] auto writeResult = write(errorPipe[1], &errval, sizeof(errval));
_exit(0);
}
@@ -317,7 +321,7 @@ namespace AzFramework
// Set up a pipe to communicate the error code from the subprocess's execvpe call
AZStd::array<int, 2> childErrorPipeFds{};
pipe(childErrorPipeFds.data());
[[maybe_unused]] auto pipeResult = pipe(childErrorPipeFds.data());
// This configures the write end of the pipe to close on calls to `exec`
fcntl(childErrorPipeFds[1], F_SETFD, fcntl(childErrorPipeFds[1], F_GETFD) | FD_CLOEXEC);
@@ -71,7 +71,7 @@ namespace AzNetworking
const char* GetNetworkErrorDesc(int32_t errorCode)
{
static AZ_THREAD_LOCAL char buffer[1024];
strerror_r(errorCode, buffer, sizeof(buffer));
[[maybe_unused]] auto strErrorResult = strerror_r(errorCode, buffer, sizeof(buffer));
return buffer;
}
}