1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Enable additional warnings for C builds.

This commit is contained in:
David Steele 2017-11-06 22:55:34 -05:00
parent b03c26968a
commit bcdfc7d0b5
21 changed files with 198 additions and 139 deletions

View File

@ -39,6 +39,10 @@
<release-item> <release-item>
<p>Add <id>eof</id> to S3 file driver (required for encryption support).</p> <p>Add <id>eof</id> to S3 file driver (required for encryption support).</p>
</release-item> </release-item>
<release-item>
<p>Enable additional warnings for C builds.</p>
</release-item>
</release-refactor-list> </release-refactor-list>
</release-core-list> </release-core-list>

View File

@ -69,7 +69,7 @@ Core context handling macros, only intended to be called from other macros
MemContext *MEM_CONTEXT_XS_memContextOld = memContextSwitch(memContext); \ MemContext *MEM_CONTEXT_XS_memContextOld = memContextSwitch(memContext); \
\ \
/* Store any errors to be croaked to Perl at the end */ \ /* Store any errors to be croaked to Perl at the end */ \
bool MEM_CONTEXT_XS_croak = false; \ volatile bool MEM_CONTEXT_XS_croak = false; \
\ \
/* Try the statement block */ \ /* Try the statement block */ \
ERROR_TRY() ERROR_TRY()

View File

@ -16,10 +16,26 @@ Perl includes
Order is critical here so don't change it. Order is critical here so don't change it.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 8 || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ >= 0)))
#define WARNING_MAYBE_INITIALIZED 1
#elif __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ >= 0)))
#define WARNING_INITIALIZED 1
#endif
#if WARNING_MAYBE_INITIALIZED
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#elif WARNING_INITIALIZED
#pragma GCC diagnostic ignored "-Wuninitialized"
#endif
#include <XSUB.h> #include <XSUB.h>
#include <EXTERN.h> #include <EXTERN.h>
#include <perl.h> #include <perl.h>
#if WARNING_MAYBE_INITIALIZED || WARNING_INITIALIZED
#pragma GCC diagnostic pop
#endif
/*********************************************************************************************************************************** /***********************************************************************************************************************************
C includes C includes
@ -51,8 +67,12 @@ Constant include
Auto generated code that handles exporting C constants to Perl. Auto generated code that handles exporting C constants to Perl.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "const-c.inc" #include "const-c.inc"
#pragma GCC diagnostic warning "-Wunused-parameter"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Module definition Module definition
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -63,12 +83,18 @@ PROTOTYPES: DISABLE
# #
# The XS portion of the code that handles exporting C constants to Perl. # The XS portion of the code that handles exporting C constants to Perl.
# ---------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------
#pragma GCC diagnostic ignored "-Wuninitialized"
INCLUDE: const-xs.inc INCLUDE: const-xs.inc
#pragma GCC diagnostic warning "-Wuninitialized"
# Exported functions and modules # Exported functions and modules
# #
# These modules should map 1-1 with C modules in src directory. # These modules should map 1-1 with C modules in src directory.
# ---------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------
#pragma GCC diagnostic ignored "-Wclobbered"
INCLUDE: xs/cipher/block.xs INCLUDE: xs/cipher/block.xs
INCLUDE: xs/cipher/random.xs INCLUDE: xs/cipher/random.xs
INCLUDE: xs/common/encode.xs INCLUDE: xs/common/encode.xs

View File

@ -100,7 +100,7 @@ WriteMakefile
AUTHOR => 'David Steele <david@pgbackrest.org>', AUTHOR => 'David Steele <david@pgbackrest.org>',
CCFLAGS => join(' ', qw( CCFLAGS => join(' ', qw(
-Wfatal-errors -Wfatal-errors -Wall -Wextra -Wwrite-strings
-o $@ -o $@
-std=c99 -std=c99
-D_FILE_OFFSET_BITS=64 -D_FILE_OFFSET_BITS=64

View File

@ -36,20 +36,21 @@ OUTPUT:
#################################################################################################################################### ####################################################################################################################################
SV * SV *
process(self, svSource) process(self, source)
pgBackRest::LibC::Cipher::Block self pgBackRest::LibC::Cipher::Block self
SV *svSource SV *source
CODE: CODE:
RETVAL = NULL; RETVAL = NULL;
STRLEN tSize;
const unsigned char *pvSource = (const unsigned char *)SvPV(svSource, tSize);
MEM_CONTEXT_XS_BEGIN(self->memContext) MEM_CONTEXT_XS_BEGIN(self->memContext)
{ {
STRLEN tSize;
const unsigned char *sourcePtr = (const unsigned char *)SvPV(source, tSize);
RETVAL = NEWSV(0, cipherBlockProcessSize(self->pxPayload, tSize)); RETVAL = NEWSV(0, cipherBlockProcessSize(self->pxPayload, tSize));
SvPOK_only(RETVAL); SvPOK_only(RETVAL);
SvCUR_set(RETVAL, cipherBlockProcess(self->pxPayload, pvSource, tSize, (unsigned char *)SvPV_nolen(RETVAL))); SvCUR_set(RETVAL, cipherBlockProcess(self->pxPayload, sourcePtr, tSize, (unsigned char *)SvPV_nolen(RETVAL)));
} }
MEM_CONTEXT_XS_END(); MEM_CONTEXT_XS_END();
OUTPUT: OUTPUT:

View File

@ -69,7 +69,7 @@ cipherBlockNew(CipherMode mode, const char *cipherName, const unsigned char *pas
ERROR_THROW(AssertError, "unable to load cipher '%s'", cipherName); ERROR_THROW(AssertError, "unable to load cipher '%s'", cipherName);
// Lookup digest. If not defined it will be set to sha1. // Lookup digest. If not defined it will be set to sha1.
const EVP_MD *digest; const EVP_MD *volatile digest = digest = EVP_sha1();
if (digestName) if (digestName)
digest = EVP_get_digestbyname(digestName); digest = EVP_get_digestbyname(digestName);
@ -111,7 +111,14 @@ Determine how large the destination buffer should be
int int
cipherBlockProcessSize(CipherBlock *this, int sourceSize) cipherBlockProcessSize(CipherBlock *this, int sourceSize)
{ {
return sourceSize + EVP_MAX_BLOCK_LENGTH + CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN; // Destination size is source size plus one extra block
int destinationSize = sourceSize + EVP_MAX_BLOCK_LENGTH;
// On encrypt the header size must be included before the first block
if (this->mode == cipherModeEncrypt && !this->saltDone)
destinationSize += CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN;
return destinationSize;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -75,7 +75,7 @@ Check that the encoded string is valid
bool bool
decodeToBinValid(EncodeType encodeType, const char *source) decodeToBinValid(EncodeType encodeType, const char *source)
{ {
bool valid = true; volatile bool valid = true;
ERROR_TRY() ERROR_TRY()
{ {

View File

@ -92,7 +92,7 @@ decodeToBinBase64(const char *source, unsigned char *destination)
int destinationIdx = 0; int destinationIdx = 0;
// Decode the binary data from four characters to three bytes // Decode the binary data from four characters to three bytes
for (int sourceIdx = 0; sourceIdx < strlen(source); sourceIdx += 4) for (unsigned int sourceIdx = 0; sourceIdx < strlen(source); sourceIdx += 4)
{ {
// Always decode the first character // Always decode the first character
destination[destinationIdx++] = destination[destinationIdx++] =

View File

@ -81,7 +81,7 @@ static void *memReAllocInternal(void *bufferOld, size_t sizeOld, size_t sizeNew,
// Zero the new memory when requested - old memory is left untouched else why bother with a realloc? // Zero the new memory when requested - old memory is left untouched else why bother with a realloc?
if (zeroNew) if (zeroNew)
memset(bufferNew + sizeOld, 0, sizeNew - sizeOld); memset((unsigned char *)bufferNew + sizeOld, 0, sizeNew - sizeOld);
// Return the buffer // Return the buffer
return bufferNew; return bufferNew;

View File

@ -31,7 +31,7 @@ typedef struct ConfigOptionData
const char *name; const char *name;
unsigned int index:5; unsigned int index:5;
ConfigDefineOption defineId:7; unsigned int defineId:7;
} ConfigOptionData; } ConfigOptionData;
#define CONFIG_OPTION_LIST(...) \ #define CONFIG_OPTION_LIST(...) \
@ -58,7 +58,7 @@ Ensure that command id is valid
void void
cfgCommandCheck(ConfigCommand commandId) cfgCommandCheck(ConfigCommand commandId)
{ {
if (commandId < 0 || commandId >= cfgCommandTotal()) if (commandId >= cfgCommandTotal())
ERROR_THROW(AssertError, "command id %d invalid - must be >= 0 and < %d", commandId, cfgCommandTotal()); ERROR_THROW(AssertError, "command id %d invalid - must be >= 0 and < %d", commandId, cfgCommandTotal());
} }
@ -106,7 +106,7 @@ cfgCommandName(ConfigCommand commandId)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
cfgCommandTotal - total number of commands cfgCommandTotal - total number of commands
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
int unsigned int
cfgCommandTotal() cfgCommandTotal()
{ {
return sizeof(configCommandData) / sizeof(ConfigCommandData); return sizeof(configCommandData) / sizeof(ConfigCommandData);
@ -118,7 +118,7 @@ Ensure that option id is valid
void void
cfgOptionCheck(ConfigOption optionId) cfgOptionCheck(ConfigOption optionId)
{ {
if (optionId < 0 || optionId >= cfgOptionTotal()) if (optionId >= cfgOptionTotal())
ERROR_THROW(AssertError, "option id %d invalid - must be >= 0 and < %d", optionId, cfgOptionTotal()); ERROR_THROW(AssertError, "option id %d invalid - must be >= 0 and < %d", optionId, cfgOptionTotal());
} }
@ -199,7 +199,7 @@ cfgOptionName(ConfigOption optionId)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
cfgOptionTotal - total number of configuration options cfgOptionTotal - total number of configuration options
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
int unsigned int
cfgOptionTotal() cfgOptionTotal()
{ {
return sizeof(configOptionData) / sizeof(ConfigOptionData); return sizeof(configOptionData) / sizeof(ConfigOptionData);

View File

@ -15,7 +15,7 @@ Functions
int cfgCommandId(const char *commandName); int cfgCommandId(const char *commandName);
const char *cfgCommandName(ConfigCommand commandId); const char *cfgCommandName(ConfigCommand commandId);
ConfigDefineCommand cfgCommandDefIdFromId(ConfigCommand commandId); ConfigDefineCommand cfgCommandDefIdFromId(ConfigCommand commandId);
int cfgCommandTotal(); unsigned int cfgCommandTotal();
int cfgOptionId(const char *optionName); int cfgOptionId(const char *optionName);
ConfigOption cfgOptionIdFromDefId(ConfigDefineOption optionDefId, int index); ConfigOption cfgOptionIdFromDefId(ConfigDefineOption optionDefId, int index);
@ -23,6 +23,6 @@ int cfgOptionIndex(ConfigOption optionId);
int cfgOptionIndexTotal(ConfigOption optionDefId); int cfgOptionIndexTotal(ConfigOption optionDefId);
const char *cfgOptionName(ConfigOption optionId); const char *cfgOptionName(ConfigOption optionId);
ConfigDefineOption cfgOptionDefIdFromId(ConfigOption optionId); ConfigDefineOption cfgOptionDefIdFromId(ConfigOption optionId);
int cfgOptionTotal(); unsigned int cfgOptionTotal();
#endif #endif

View File

@ -1,6 +1,7 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Command and Option Configuration Definition Command and Option Configuration Definition
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include <limits.h>
#include <string.h> #include <string.h>
#include "common/error.h" #include "common/error.h"
@ -11,7 +12,7 @@ Map command names to ids and vice versa.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct ConfigDefineCommandData typedef struct ConfigDefineCommandData
{ {
char *name; // Command name const char *name; // Command name
} ConfigDefineCommandData; } ConfigDefineCommandData;
// Command macros are intended to make the command definitions easy to read and to produce good diffs. // Command macros are intended to make the command definitions easy to read and to produce good diffs.
@ -30,15 +31,15 @@ Define how an option is parsed and interacts with other options.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct ConfigDefineOptionData typedef struct ConfigDefineOptionData
{ {
char *name; // Option name const char *name; // Option name
unsigned int type:3; // Option type (e.g. string, int, boolean, etc.) unsigned int type:3; // Option type (e.g. string, int, boolean, etc.)
unsigned int indexTotal:4; // 0 normally, > 0 if indexed option (e.g. db1-*) unsigned int indexTotal:4; // 0 normally, > 0 if indexed option (e.g. db1-*)
ConfigDefSection section:2; // Config section (e.g. global, stanza, cmd-line) unsigned int section:2; // Config section (e.g. global, stanza, cmd-line)
bool negate:1; // Can the option be negated? bool negate:1; // Can the option be negated?
bool required:1; // Is the option required? bool required:1; // Is the option required?
bool secure:1; // Does the option need to be redacted on logs and cmd-line? bool secure:1; // Does the option need to be redacted on logs and cmd-line?
unsigned int commandValid:15; // Bitmap for commands that is option is valid for unsigned int commandValid:15; // Bitmap for commands that is option is valid for
void **data; // Optional data and command overrides const void **data; // Optional data and command overrides
} ConfigDefineOptionData; } ConfigDefineOptionData;
// Option macros are intended to make the command definitions easy to read and to produce good diffs. // Option macros are intended to make the command definitions easy to read and to produce good diffs.
@ -82,10 +83,10 @@ typedef enum
} ConfigDefineDataType; } ConfigDefineDataType;
#define CFGDATA_OPTION_OPTIONAL_PUSH_LIST(type, size, data, ...) \ #define CFGDATA_OPTION_OPTIONAL_PUSH_LIST(type, size, data, ...) \
(void *)((uint32)type << 24 | (uint32)size << 16 | (uint32)data), __VA_ARGS__ (const void *)((uint32)type << 24 | (uint32)size << 16 | (uint32)data), __VA_ARGS__
#define CFGDATA_OPTION_OPTIONAL_PUSH(type, size, data) \ #define CFGDATA_OPTION_OPTIONAL_PUSH(type, size, data) \
(void *)((uint32)type << 24 | (uint32)size << 16 | (uint32)data) (const void *)((uint32)type << 24 | (uint32)size << 16 | (uint32)data)
#define CFGDEFDATA_OPTION_COMMAND_LIST(...) \ #define CFGDEFDATA_OPTION_COMMAND_LIST(...) \
.commandValid = 0 __VA_ARGS__, .commandValid = 0 __VA_ARGS__,
@ -94,19 +95,19 @@ typedef enum
| (1 << commandParam) | (1 << commandParam)
#define CFGDEFDATA_OPTION_OPTIONAL_LIST(...) \ #define CFGDEFDATA_OPTION_OPTIONAL_LIST(...) \
.data = (void *[]){__VA_ARGS__ NULL}, .data = (const void *[]){__VA_ARGS__ NULL},
#define CFGDEFDATA_OPTION_OPTIONAL_DEFAULT(defaultValue) \ #define CFGDEFDATA_OPTION_OPTIONAL_DEFAULT(defaultValue) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST(configDefDataTypeDefault, 1, 0, defaultValue), CFGDATA_OPTION_OPTIONAL_PUSH_LIST(configDefDataTypeDefault, 1, 0, defaultValue),
#define CFGDEFDATA_OPTION_OPTIONAL_ALLOW_LIST(...) \ #define CFGDEFDATA_OPTION_OPTIONAL_ALLOW_LIST(...) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \ CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \
configDefDataTypeAllowList, sizeof((char *[]){__VA_ARGS__}) / sizeof(char *), 0, __VA_ARGS__), configDefDataTypeAllowList, sizeof((const char *[]){__VA_ARGS__}) / sizeof(const char *), 0, __VA_ARGS__),
#define CFGDEFDATA_OPTION_OPTIONAL_ALLOW_RANGE(rangeMinParam, rangeMaxParam) \ #define CFGDEFDATA_OPTION_OPTIONAL_ALLOW_RANGE(rangeMinParam, rangeMaxParam) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \ CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \
configDefDataTypeAllowRange, 2, 0, (void *)(intptr_t)(int32)(rangeMinParam * 100), \ configDefDataTypeAllowRange, 2, 0, (const void *)(intptr_t)(int32)(rangeMinParam * 100), \
(void *)(intptr_t)(int32)(rangeMaxParam * 100)), (const void *)(intptr_t)(int32)(rangeMaxParam * 100)),
#define CFGDEFDATA_OPTION_OPTIONAL_NAME_ALT(nameAltParam) \ #define CFGDEFDATA_OPTION_OPTIONAL_NAME_ALT(nameAltParam) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST(configDefDataTypeNameAlt, 1, 0, nameAltParam), CFGDATA_OPTION_OPTIONAL_PUSH_LIST(configDefDataTypeNameAlt, 1, 0, nameAltParam),
@ -119,7 +120,7 @@ typedef enum
#define CFGDEFDATA_OPTION_OPTIONAL_DEPEND_LIST(optionDepend, ...) \ #define CFGDEFDATA_OPTION_OPTIONAL_DEPEND_LIST(optionDepend, ...) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \ CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \
configDefDataTypeDepend, sizeof((char *[]){__VA_ARGS__}) / sizeof(char *), optionDepend, __VA_ARGS__), configDefDataTypeDepend, sizeof((const char *[]){__VA_ARGS__}) / sizeof(const char *), optionDepend, __VA_ARGS__),
#define CFGDEFDATA_OPTION_OPTIONAL_COMMAND_OVERRRIDE(...) \ #define CFGDEFDATA_OPTION_OPTIONAL_COMMAND_OVERRRIDE(...) \
__VA_ARGS__ __VA_ARGS__
@ -140,8 +141,8 @@ Find optional data for a command and option.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static void static void
cfgDefDataFind( cfgDefDataFind(
ConfigDefineDataType typeFind, ConfigDefineCommand commandDefId, void **dataList, bool *dataDefFound, int *dataDef, ConfigDefineDataType typeFind, ConfigDefineCommand commandDefId, const void **dataList, bool *dataDefFound, int *dataDef,
void ***dataDefList, int *dataDefListSize) const void ***dataDefList, int *dataDefListSize)
{ {
*dataDefFound = false; *dataDefFound = false;
@ -152,7 +153,7 @@ cfgDefDataFind(
int offset = 0; int offset = 0;
int size; int size;
int data; int data;
int commandCurrent = -1; unsigned int commandCurrent = UINT_MAX;
// Loop through all data // Loop through all data
do do
@ -173,7 +174,7 @@ cfgDefDataFind(
commandCurrent = data; commandCurrent = data;
} }
// Only find type if not in a command block yet or in the expected command // Only find type if not in a command block yet or in the expected command
else if (type == typeFind && (commandCurrent == -1 || commandCurrent == commandDefId)) else if (type == typeFind && (commandCurrent == UINT_MAX || commandCurrent == commandDefId))
{ {
// Store the data found // Store the data found
*dataDefFound = true; *dataDefFound = true;
@ -196,7 +197,7 @@ cfgDefDataFind(
bool dataDefFound = false; \ bool dataDefFound = false; \
int dataDef = 0; \ int dataDef = 0; \
int dataDefListSize = 0; \ int dataDefListSize = 0; \
void **dataDefList = NULL; \ const void **dataDefList = NULL; \
\ \
cfgDefDataFind( \ cfgDefDataFind( \
type, commandDefId, configDefineOptionData[optionDefId].data, &dataDefFound, &dataDef, &dataDefList, &dataDefListSize); type, commandDefId, configDefineOptionData[optionDefId].data, &dataDefFound, &dataDef, &dataDefList, &dataDefListSize);
@ -204,13 +205,13 @@ cfgDefDataFind(
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Command and option define totals Command and option define totals
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
int unsigned int
cfgDefCommandTotal() cfgDefCommandTotal()
{ {
return sizeof(configDefineCommandData) / sizeof(ConfigDefineCommandData); return sizeof(configDefineCommandData) / sizeof(ConfigDefineCommandData);
} }
int unsigned int
cfgDefOptionTotal() cfgDefOptionTotal()
{ {
return sizeof(configDefineOptionData) / sizeof(ConfigDefineOptionData); return sizeof(configDefineOptionData) / sizeof(ConfigDefineOptionData);
@ -222,14 +223,14 @@ Check that command and option ids are valid
void void
cfgDefCommandCheck(ConfigDefineCommand commandDefId) cfgDefCommandCheck(ConfigDefineCommand commandDefId)
{ {
if (commandDefId < 0 || commandDefId >= cfgDefCommandTotal()) if (commandDefId >= cfgDefCommandTotal())
ERROR_THROW(AssertError, "command def id %d invalid - must be >= 0 and < %d", commandDefId, cfgDefCommandTotal()); ERROR_THROW(AssertError, "command def id %d invalid - must be >= 0 and < %d", commandDefId, cfgDefCommandTotal());
} }
void void
cfgDefOptionCheck(ConfigDefineOption optionDefId) cfgDefOptionCheck(ConfigDefineOption optionDefId)
{ {
if (optionDefId < 0 || optionDefId >= cfgDefOptionTotal()) if (optionDefId >= cfgDefOptionTotal())
ERROR_THROW(AssertError, "option def id %d invalid - must be >= 0 and < %d", optionDefId, cfgDefOptionTotal()); ERROR_THROW(AssertError, "option def id %d invalid - must be >= 0 and < %d", optionDefId, cfgDefOptionTotal());
} }

View File

@ -20,7 +20,7 @@ typedef enum
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
int cfgDefCommandTotal(); unsigned int cfgDefCommandTotal();
void cfgDefCommandCheck(ConfigDefineCommand commandDefId); void cfgDefCommandCheck(ConfigDefineCommand commandDefId);
bool cfgDefOptionAllowList(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionAllowList(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
@ -45,7 +45,7 @@ const char *cfgDefOptionPrefix(ConfigDefineOption optionDefId);
bool cfgDefOptionRequired(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionRequired(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
ConfigDefSection cfgDefOptionSection(ConfigDefineOption optionDefId); ConfigDefSection cfgDefOptionSection(ConfigDefineOption optionDefId);
bool cfgDefOptionSecure(ConfigDefineOption optionDefId); bool cfgDefOptionSecure(ConfigDefineOption optionDefId);
int cfgDefOptionTotal(); unsigned int cfgDefOptionTotal();
int cfgDefOptionType(ConfigDefineOption optionDefId); int cfgDefOptionType(ConfigDefineOption optionDefId);
bool cfgDefOptionValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);

View File

@ -315,7 +315,9 @@ sub run
$self->{oStorageTest}->put("$self->{strGCovPath}/test.c", $strTestC); $self->{oStorageTest}->put("$self->{strGCovPath}/test.c", $strTestC);
my $strGccCommand = my $strGccCommand =
'gcc -Wfatal-errors -std=c99 -fprofile-arcs -ftest-coverage -fPIC -O0 ' . 'gcc -std=c99 -fprofile-arcs -ftest-coverage -fPIC -O0 ' .
'-Wfatal-errors -Wall -Wextra -Wwrite-strings ' .
($self->{oTest}->{&TEST_VM} ne VM_CO6 && $self->{oTest}->{&TEST_VM} ne VM_U12 ? '-Wpedantic ' : '') .
"-I/$self->{strBackRestBase}/src -I/$self->{strBackRestBase}/test/src test.c " . "-I/$self->{strBackRestBase}/src -I/$self->{strBackRestBase}/test/src test.c " .
"/$self->{strBackRestBase}/test/src/common/harnessTest.c " . "/$self->{strBackRestBase}/test/src/common/harnessTest.c " .
join(' ', @stryCFile) . " -l crypto -o test"; join(' ', @stryCFile) . " -l crypto -o test";

View File

@ -26,6 +26,13 @@ testAdd - add a new test
void void
testAdd(int run, bool selected) testAdd(int run, bool selected)
{ {
if (run != testTotal + 1)
{
fprintf(stderr, "ERROR: test run %d is not in order\n", run);
fflush(stderr);
exit(255);
}
testList[testTotal].selected = selected; testList[testTotal].selected = selected;
testTotal++; testTotal++;
} }
@ -41,13 +48,15 @@ testBegin(const char *name)
if (testList[testRun - 1].selected) if (testList[testRun - 1].selected)
{ {
if (testRun != 1) if (testRun != 1)
{
printf("\n"); printf("\n");
}
printf("run %03d - %s\n", testRun, name); printf("run %03d - %s\n", testRun, name);
fflush(stdout); fflush(stdout);
return true;
} }
return false;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -64,7 +64,7 @@ TEST_TYPE_FORMAT - format the test type into the given buffer -- or return verba
char *value##Str = value##StrBuffer; \ char *value##Str = value##StrBuffer; \
\ \
if (TEST_TYPE_PTR(type) && *(void **)&value == NULL) \ if (TEST_TYPE_PTR(type) && *(void **)&value == NULL) \
value##Str = "NULL"; \ value##Str = (char *)"NULL"; \
else if (strcmp(#type, "char *") == 0) \ else if (strcmp(#type, "char *") == 0) \
value##Str = *(char **)&value; \ value##Str = *(char **)&value; \
else \ else \
@ -85,7 +85,7 @@ parameters.
#define TEST_RESULT(statement, resultExpectedValue, type, format, typeOp, ...) \ #define TEST_RESULT(statement, resultExpectedValue, type, format, typeOp, ...) \
{ \ { \
/* Assign expected result to a local variable so the value can be manipulated as a pointer */ \ /* Assign expected result to a local variable so the value can be manipulated as a pointer */ \
type TEST_RESULT_resultExpected = (type)(resultExpectedValue); \ const type TEST_RESULT_resultExpected = (type)(resultExpectedValue); \
\ \
/* Output test info */ \ /* Output test info */ \
printf(" l%04d - ", __LINE__); \ printf(" l%04d - ", __LINE__); \

View File

@ -25,18 +25,19 @@ void testRun()
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_ERROR( TEST_ERROR(
cipherBlockNew( cipherBlockNew(
cipherModeEncrypt, BOGUS_STR, TEST_PASS, TEST_PASS_SIZE, NULL), AssertError, "unable to load cipher 'BOGUS'"); cipherModeEncrypt, BOGUS_STR, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL), AssertError,
"unable to load cipher 'BOGUS'");
TEST_ERROR( TEST_ERROR(
cipherBlockNew(cipherModeEncrypt, NULL, TEST_PASS, TEST_PASS_SIZE, NULL), AssertError, cipherBlockNew(cipherModeEncrypt, NULL, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL), AssertError,
"unable to load cipher '(null)'"); "unable to load cipher '(null)'");
TEST_ERROR( TEST_ERROR(
cipherBlockNew( cipherBlockNew(
cipherModeEncrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, BOGUS_STR), AssertError, cipherModeEncrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, BOGUS_STR), AssertError,
"unable to load digest 'BOGUS'"); "unable to load digest 'BOGUS'");
// Initialization of object // Initialization of object
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
CipherBlock *cipherBlock = cipherBlockNew(cipherModeEncrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); CipherBlock *cipherBlock = cipherBlockNew(cipherModeEncrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_RESULT_STR(memContextName(cipherBlock->memContext), "cipherBlock", "mem context name is valid"); TEST_RESULT_STR(memContextName(cipherBlock->memContext), "cipherBlock", "mem context name is valid");
TEST_RESULT_INT(cipherBlock->mode, cipherModeEncrypt, "mode is valid"); TEST_RESULT_INT(cipherBlock->mode, cipherModeEncrypt, "mode is valid");
TEST_RESULT_INT(cipherBlock->passSize, TEST_PASS_SIZE, "passphrase size is valid"); TEST_RESULT_INT(cipherBlock->passSize, TEST_PASS_SIZE, "passphrase size is valid");
@ -53,16 +54,21 @@ void testRun()
// ----------------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("Encrypt and Decrypt")) if (testBegin("Encrypt and Decrypt"))
{ {
char encryptBuffer[TEST_BUFFER_SIZE]; unsigned char encryptBuffer[TEST_BUFFER_SIZE];
int encryptSize = 0; int encryptSize = 0;
char decryptBuffer[TEST_BUFFER_SIZE]; unsigned char decryptBuffer[TEST_BUFFER_SIZE];
int decryptSize = 0; int decryptSize = 0;
// Encrypt // Encrypt
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
CipherBlock *blockEncrypt = cipherBlockNew(cipherModeEncrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); CipherBlock *blockEncrypt = cipherBlockNew(
cipherModeEncrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
encryptSize = cipherBlockProcess(blockEncrypt, TEST_PLAINTEXT, strlen(TEST_PLAINTEXT), encryptBuffer); TEST_RESULT_INT(
cipherBlockProcessSize(blockEncrypt, strlen(TEST_PLAINTEXT)),
strlen(TEST_PLAINTEXT) + EVP_MAX_BLOCK_LENGTH + CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN, "check process size");
encryptSize = cipherBlockProcess(blockEncrypt, (unsigned char *)TEST_PLAINTEXT, strlen(TEST_PLAINTEXT), encryptBuffer);
TEST_RESULT_BOOL(blockEncrypt->saltDone, true, "salt done is true"); TEST_RESULT_BOOL(blockEncrypt->saltDone, true, "salt done is true");
TEST_RESULT_BOOL(blockEncrypt->processDone, true, "process done is true"); TEST_RESULT_BOOL(blockEncrypt->processDone, true, "process done is true");
@ -71,9 +77,10 @@ void testRun()
TEST_RESULT_INT( TEST_RESULT_INT(
cipherBlockProcessSize(blockEncrypt, strlen(TEST_PLAINTEXT)), cipherBlockProcessSize(blockEncrypt, strlen(TEST_PLAINTEXT)),
strlen(TEST_PLAINTEXT) + EVP_MAX_BLOCK_LENGTH + CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN, "check process size"); strlen(TEST_PLAINTEXT) + EVP_MAX_BLOCK_LENGTH, "check process size");
encryptSize += cipherBlockProcess(blockEncrypt, TEST_PLAINTEXT, strlen(TEST_PLAINTEXT), encryptBuffer + encryptSize); encryptSize += cipherBlockProcess(
blockEncrypt, (unsigned char *)TEST_PLAINTEXT, strlen(TEST_PLAINTEXT), encryptBuffer + encryptSize);
TEST_RESULT_INT( TEST_RESULT_INT(
encryptSize, CIPHER_BLOCK_HEADER_SIZE + EVP_CIPHER_block_size(blockEncrypt->cipher), encryptSize, CIPHER_BLOCK_HEADER_SIZE + EVP_CIPHER_block_size(blockEncrypt->cipher),
"cipher size increases by one block"); "cipher size increases by one block");
@ -87,7 +94,12 @@ void testRun()
// Decrypt in one pass // Decrypt in one pass
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
CipherBlock *blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); CipherBlock *blockDecrypt = cipherBlockNew(
cipherModeDecrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_RESULT_INT(
cipherBlockProcessSize(blockEncrypt, encryptSize),
encryptSize + EVP_MAX_BLOCK_LENGTH, "check process size");
decryptSize = cipherBlockProcess(blockDecrypt, encryptBuffer, encryptSize, decryptBuffer); decryptSize = cipherBlockProcess(blockDecrypt, encryptBuffer, encryptSize, decryptBuffer);
TEST_RESULT_INT(decryptSize, EVP_CIPHER_block_size(blockDecrypt->cipher), "decrypt size is one block"); TEST_RESULT_INT(decryptSize, EVP_CIPHER_block_size(blockDecrypt->cipher), "decrypt size is one block");
@ -100,7 +112,7 @@ void testRun()
// Decrypt in small chunks to test buffering // Decrypt in small chunks to test buffering
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
decryptSize = 0; decryptSize = 0;
memset(decryptBuffer, 0, TEST_BUFFER_SIZE); memset(decryptBuffer, 0, TEST_BUFFER_SIZE);
@ -138,43 +150,51 @@ void testRun()
// Encrypt zero byte file and decrypt it // Encrypt zero byte file and decrypt it
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
blockEncrypt = cipherBlockNew(cipherModeEncrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); blockEncrypt = cipherBlockNew(cipherModeEncrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_RESULT_INT(cipherBlockProcess(blockEncrypt, NULL, 0, encryptBuffer), 16, "process header"); TEST_RESULT_INT(cipherBlockProcess(blockEncrypt, NULL, 0, encryptBuffer), 16, "process header");
TEST_RESULT_INT(cipherBlockFlush(blockEncrypt, encryptBuffer + 16), 16, "flush remaining bytes"); TEST_RESULT_INT(cipherBlockFlush(blockEncrypt, encryptBuffer + 16), 16, "flush remaining bytes");
blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_RESULT_INT(cipherBlockProcess(blockDecrypt, encryptBuffer, 32, decryptBuffer), 0, "0 bytes processed"); TEST_RESULT_INT(cipherBlockProcess(blockDecrypt, encryptBuffer, 32, decryptBuffer), 0, "0 bytes processed");
TEST_RESULT_INT(cipherBlockFlush(blockDecrypt, decryptBuffer), 0, "0 bytes on flush"); TEST_RESULT_INT(cipherBlockFlush(blockDecrypt, decryptBuffer), 0, "0 bytes on flush");
// Invalid cipher header // Invalid cipher header
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_ERROR(cipherBlockProcess(blockDecrypt, "1234567890123456", 16, decryptBuffer), CipherError, "cipher header invalid"); TEST_ERROR(
cipherBlockProcess(
blockDecrypt, (unsigned char *)"1234567890123456", 16, decryptBuffer), CipherError, "cipher header invalid");
// Invalid encrypted data cannot be flushed // Invalid encrypted data cannot be flushed
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_RESULT_INT(cipherBlockProcess(blockDecrypt, CIPHER_BLOCK_MAGIC "12345678", 16, decryptBuffer), 0, "process header"); TEST_RESULT_INT(
TEST_RESULT_INT(cipherBlockProcess(blockDecrypt, "1234567890123456", 16, decryptBuffer), 0, "process 0 bytes"); cipherBlockProcess(
blockDecrypt, (unsigned char *)(CIPHER_BLOCK_MAGIC "12345678"), 16, decryptBuffer), 0, "process header");
TEST_RESULT_INT(
cipherBlockProcess(
blockDecrypt, (unsigned char *)"1234567890123456", 16, decryptBuffer), 0, "process 0 bytes");
TEST_ERROR(cipherBlockFlush(blockDecrypt, decryptBuffer), CipherError, "unable to flush"); TEST_ERROR(cipherBlockFlush(blockDecrypt, decryptBuffer), CipherError, "unable to flush");
// File with no header should not flush // File with no header should not flush
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_RESULT_INT(cipherBlockProcess(blockDecrypt, NULL, 0, decryptBuffer), 0, "no header processed"); TEST_RESULT_INT(cipherBlockProcess(blockDecrypt, NULL, 0, decryptBuffer), 0, "no header processed");
TEST_ERROR(cipherBlockFlush(blockDecrypt, decryptBuffer), CipherError, "cipher header missing"); TEST_ERROR(cipherBlockFlush(blockDecrypt, decryptBuffer), CipherError, "cipher header missing");
// File with header only should error // File with header only should error
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, TEST_PASS, TEST_PASS_SIZE, NULL); blockDecrypt = cipherBlockNew(cipherModeDecrypt, TEST_CIPHER, (unsigned char *)TEST_PASS, TEST_PASS_SIZE, NULL);
TEST_RESULT_INT(cipherBlockProcess(blockDecrypt, CIPHER_BLOCK_MAGIC "12345678", 16, decryptBuffer), 0, "0 bytes processed"); TEST_RESULT_INT(
cipherBlockProcess(
blockDecrypt, (unsigned char *)(CIPHER_BLOCK_MAGIC "12345678"), 16, decryptBuffer), 0, "0 bytes processed");
TEST_ERROR(cipherBlockFlush(blockDecrypt, decryptBuffer), CipherError, "unable to flush"); TEST_ERROR(cipherBlockFlush(blockDecrypt, decryptBuffer), CipherError, "unable to flush");
} }
} }

View File

@ -14,7 +14,7 @@ void testRun()
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
// Test if the buffer was overrun // Test if the buffer was overrun
int bufferSize = 256; int bufferSize = 256;
char *buffer = memNew(bufferSize); unsigned char *buffer = memNew(bufferSize);
randomBytes(buffer, bufferSize); randomBytes(buffer, bufferSize);
TEST_RESULT_BOOL(buffer[bufferSize] == 0, true, "check that buffer did not overrun (though random byte could be 0)"); TEST_RESULT_BOOL(buffer[bufferSize] == 0, true, "check that buffer did not overrun (though random byte could be 0)");

View File

@ -10,82 +10,84 @@ void testRun()
// ----------------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("base64")) if (testBegin("base64"))
{ {
char *source = "string_to_encode\r\n"; unsigned char *encode = (unsigned char *)"string_to_encode\r\n";
unsigned char destination[256]; char destinationEncode[256];
encodeToStr(encodeBase64, source, 1, destination); encodeToStr(encodeBase64, encode, 1, destinationEncode);
TEST_RESULT_STR(destination, "c3==", "1 character encode"); TEST_RESULT_STR(destinationEncode, "c3==", "1 character encode");
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 1), strlen(destination), "check size"); TEST_RESULT_INT(encodeToStrSize(encodeBase64, 1), strlen(destinationEncode), "check size");
encodeToStr(encodeBase64, source, 2, destination); encodeToStr(encodeBase64, encode, 2, destinationEncode);
TEST_RESULT_STR(destination, "c3R=", "2 character encode"); TEST_RESULT_STR(destinationEncode, "c3R=", "2 character encode");
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 2), strlen(destination), "check size"); TEST_RESULT_INT(encodeToStrSize(encodeBase64, 2), strlen(destinationEncode), "check size");
encodeToStr(encodeBase64, source, 3, destination); encodeToStr(encodeBase64, encode, 3, destinationEncode);
TEST_RESULT_STR(destination, "c3Ry", "3 character encode"); TEST_RESULT_STR(destinationEncode, "c3Ry", "3 character encode");
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 3), strlen(destination), "check size"); TEST_RESULT_INT(encodeToStrSize(encodeBase64, 3), strlen(destinationEncode), "check size");
encodeToStr(encodeBase64, source, strlen(source) - 2, destination); encodeToStr(encodeBase64, encode, strlen((char *)encode) - 2, destinationEncode);
TEST_RESULT_STR(destination, "c3RyaW5nX3RvX2VuY29kZQ==", "encode full string"); TEST_RESULT_STR(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ==", "encode full string");
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen(source) - 2), strlen(destination), "check size"); TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen((char *)encode) - 2), strlen(destinationEncode), "check size");
encodeToStr(encodeBase64, source, strlen(source), destination); encodeToStr(encodeBase64, encode, strlen((char *)encode), destinationEncode);
TEST_RESULT_STR(destination, "c3RyaW5nX3RvX2VuY29kZQ0K", "encode full string with \\r\\n"); TEST_RESULT_STR(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0K", "encode full string with \\r\\n");
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen(source)), strlen(destination), "check size"); TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen((char *)encode)), strlen(destinationEncode), "check size");
encodeToStr(encodeBase64, source, strlen(source) + 1, destination); encodeToStr(encodeBase64, encode, strlen((char *)encode) + 1, destinationEncode);
TEST_RESULT_STR(destination, "c3RyaW5nX3RvX2VuY29kZQ0KAG==", "encode full string with \\r\\n and null"); TEST_RESULT_STR(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0KAG==", "encode full string with \\r\\n and null");
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen(source) + 1), strlen(destination), "check size"); TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen((char *)encode) + 1), strlen(destinationEncode), "check size");
TEST_ERROR(encodeToStr(999, source, strlen(source), destination), AssertError, "invalid encode type 999"); TEST_ERROR(encodeToStr(999, encode, strlen((char *)encode), destinationEncode), AssertError, "invalid encode type 999");
TEST_ERROR(encodeToStrSize(999, strlen(source)), AssertError, "invalid encode type 999"); TEST_ERROR(encodeToStrSize(999, strlen((char *)encode)), AssertError, "invalid encode type 999");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
memset(destination, 0xFF, sizeof(destination)); unsigned char destinationDecode[256];
char *decode = "c3RyaW5nX3RvX2VuY29kZQ0KAG==";
decodeToBin(encodeBase64, decode, destination);
TEST_RESULT_STR(destination, source, "full string with \\r\\n and null decode");
TEST_RESULT_INT(destination[strlen(source) + 1], 0xFF, "check for overrun");
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen(source) + 1, "check size");
memset(destination, 0xFF, sizeof(destination)); memset(destinationDecode, 0xFF, sizeof(destinationDecode));
const char *decode = "c3RyaW5nX3RvX2VuY29kZQ0KAG==";
decodeToBin(encodeBase64, decode, destinationDecode);
TEST_RESULT_STR(destinationDecode, encode, "full string with \\r\\n and null decode");
TEST_RESULT_INT(destinationDecode[strlen((char *)encode) + 1], 0xFF, "check for overrun");
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen((char *)encode) + 1, "check size");
memset(destinationDecode, 0xFF, sizeof(destinationDecode));
decode = "c3RyaW5nX3RvX2VuY29kZQ0K"; decode = "c3RyaW5nX3RvX2VuY29kZQ0K";
decodeToBin(encodeBase64, decode, destination); decodeToBin(encodeBase64, decode, destinationDecode);
TEST_RESULT_INT(memcmp(destination, source, strlen(source)), 0, "full string with \\r\\n decode"); TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((char *)encode)), 0, "full string with \\r\\n decode");
TEST_RESULT_INT(destination[strlen(source)], 0xFF, "check for overrun"); TEST_RESULT_INT(destinationDecode[strlen((char *)encode)], 0xFF, "check for overrun");
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen(source), "check size"); TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen((char *)encode), "check size");
memset(destination, 0xFF, sizeof(destination)); memset(destinationDecode, 0xFF, sizeof(destinationDecode));
decode = "c3RyaW5nX3RvX2VuY29kZQ=="; decode = "c3RyaW5nX3RvX2VuY29kZQ==";
decodeToBin(encodeBase64, decode, destination); decodeToBin(encodeBase64, decode, destinationDecode);
TEST_RESULT_INT(memcmp(destination, source, strlen(source) - 2), 0, "full string decode"); TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((char *)encode) - 2), 0, "full string decode");
TEST_RESULT_INT(destination[strlen(source) - 2], 0xFF, "check for overrun"); TEST_RESULT_INT(destinationDecode[strlen((char *)encode) - 2], 0xFF, "check for overrun");
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen(source) - 2, "check size"); TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen((char *)encode) - 2, "check size");
memset(destination, 0xFF, sizeof(destination)); memset(destinationDecode, 0xFF, sizeof(destinationDecode));
decode = "c3Ry"; decode = "c3Ry";
decodeToBin(encodeBase64, decode, destination); decodeToBin(encodeBase64, decode, destinationDecode);
TEST_RESULT_INT(memcmp(destination, source, 3), 0, "3 character decode"); TEST_RESULT_INT(memcmp(destinationDecode, encode, 3), 0, "3 character decode");
TEST_RESULT_INT(destination[3], 0xFF, "check for overrun"); TEST_RESULT_INT(destinationDecode[3], 0xFF, "check for overrun");
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 3, "check size"); TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 3, "check size");
memset(destination, 0xFF, sizeof(destination)); memset(destinationDecode, 0xFF, sizeof(destinationDecode));
decode = "c3R="; decode = "c3R=";
decodeToBin(encodeBase64, decode, destination); decodeToBin(encodeBase64, decode, destinationDecode);
TEST_RESULT_INT(memcmp(destination, source, 2), 0, "2 character decode"); TEST_RESULT_INT(memcmp(destinationDecode, encode, 2), 0, "2 character decode");
TEST_RESULT_INT(destination[2], 0xFF, "check for overrun"); TEST_RESULT_INT(destinationDecode[2], 0xFF, "check for overrun");
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 2, "check size"); TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 2, "check size");
memset(destination, 0xFF, sizeof(destination)); memset(destinationDecode, 0xFF, sizeof(destinationDecode));
decode = "c3=="; decode = "c3==";
decodeToBin(encodeBase64, decode, destination); decodeToBin(encodeBase64, decode, destinationDecode);
TEST_RESULT_INT(memcmp(destination, source, 1), 0, "1 character decode"); TEST_RESULT_INT(memcmp(destinationDecode, encode, 1), 0, "1 character decode");
TEST_RESULT_INT(destination[1], 0xFF, "check for overrun"); TEST_RESULT_INT(destinationDecode[1], 0xFF, "check for overrun");
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 1, "check size"); TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 1, "check size");
TEST_ERROR(decodeToBin(-1, decode, destination), AssertError, "invalid encode type -1"); TEST_ERROR(decodeToBin(-1, decode, destinationDecode), AssertError, "invalid encode type -1");
TEST_ERROR(decodeToBinSize(-1, decode), AssertError, "invalid encode type -1"); TEST_ERROR(decodeToBinSize(-1, decode), AssertError, "invalid encode type -1");
TEST_ERROR(decodeToBin(encodeBase64, "cc$=", destination), FormatError, "base64 invalid character found at position 2"); TEST_ERROR(decodeToBin(encodeBase64, "cc$=", destinationDecode), FormatError, "base64 invalid character found at position 2");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_ERROR(decodeToBinValidate(encodeBase64, "c3"), FormatError, "base64 size 2 is not evenly divisible by 4"); TEST_ERROR(decodeToBinValidate(encodeBase64, "c3"), FormatError, "base64 size 2 is not evenly divisible by 4");

View File

@ -53,7 +53,7 @@ void testRun()
unsigned char *buffer2 = memAllocInternal(sizeof(size_t), true); unsigned char *buffer2 = memAllocInternal(sizeof(size_t), true);
int expectedTotal = 0; int expectedTotal = 0;
for (int charIdx = 0; charIdx < sizeof(size_t); charIdx++) for (unsigned int charIdx = 0; charIdx < sizeof(size_t); charIdx++)
if (buffer2[charIdx] == 0) if (buffer2[charIdx] == 0)
expectedTotal++; expectedTotal++;
@ -66,7 +66,7 @@ void testRun()
expectedTotal = 0; expectedTotal = 0;
for (int charIdx = 0; charIdx < sizeof(size_t); charIdx++) for (unsigned int charIdx = 0; charIdx < sizeof(size_t); charIdx++)
if (buffer2[charIdx] == 0xC7) if (buffer2[charIdx] == 0xC7)
expectedTotal++; expectedTotal++;
@ -74,7 +74,7 @@ void testRun()
expectedTotal = 0; expectedTotal = 0;
for (int charIdx = 0; charIdx < sizeof(size_t); charIdx++) for (unsigned int charIdx = 0; charIdx < sizeof(size_t); charIdx++)
if ((buffer2 + sizeof(size_t))[charIdx] == 0) if ((buffer2 + sizeof(size_t))[charIdx] == 0)
expectedTotal++; expectedTotal++;
@ -172,7 +172,7 @@ void testRun()
// Check that the buffer is zeroed // Check that the buffer is zeroed
int expectedTotal = 0; int expectedTotal = 0;
for (int charIdx = 0; charIdx < sizeof(size_t); charIdx++) for (unsigned int charIdx = 0; charIdx < sizeof(size_t); charIdx++)
if (buffer[charIdx] == 0) if (buffer[charIdx] == 0)
expectedTotal++; expectedTotal++;
@ -243,7 +243,7 @@ void testRun()
{ {
// ------------------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------------------
// Successful context new block // Successful context new block
char *memContextTestName = "test-new-block"; const char *memContextTestName = "test-new-block";
MemContext *memContext; MemContext *memContext;
MEM_CONTEXT_NEW_BEGIN(memContextTestName) MEM_CONTEXT_NEW_BEGIN(memContextTestName)

View File

@ -464,19 +464,6 @@ eval
($bContainerExists ? "'" : ''), ($bContainerExists ? "'" : ''),
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail}); {bSuppressStdErr => true, bShowOutputAsync => $bLogDetail});
# CO7 LibC.xs needs to be patched to ignore maybe-uninitialized warnings due to issue in a Perl header:
# embed.h:609:37: warning: 'iv' may be used uninitialized in this function [-Wmaybe-uninitialized]
# #define sv_setiv(a,b) Perl_sv_setiv(aTHX_ a,b)
if ($strBuildVM eq VM_CO7)
{
my $strLibXsFile = "${strBuildPath}/LibC.xs";
$oStorageBackRest->put(
$strLibXsFile,
"#pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n" .
${$oStorageBackRest->get($strLibXsFile)});
}
executeTest( executeTest(
($bContainerExists ? 'docker exec -i test-build ' : '') . ($bContainerExists ? 'docker exec -i test-build ' : '') .
"make --silent --directory ${strBuildPath}", "make --silent --directory ${strBuildPath}",