Skip to content
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

Replacing sprintf with snprintf to avoid overflow. #114

Closed
wants to merge 2 commits into from
Closed
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
67 changes: 67 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Format Style Options - Created with Clang Power Tools
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: ''
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros:
[]
IncludeBlocks: Preserve
IncludeCategories:
[]
IncludeIsMainRegex: $
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 8
UseTab: Never
...
11 changes: 6 additions & 5 deletions elf2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ union Elf_Ehdr ElfHeader;
union Elf_Shdr **SectionHeaderPtrs = NULL;
union Elf_Shdr SectionHeaderStringTable = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
int64 SectionHeaderStringTableDataOffset = 0;
char ** SectionNamePtrs = NULL;
char **SectionNamePtrs = NULL;

struct stat SrcFileStats;

uint64_t StringTableDataOffset = 0;
int32 SymbolTableDataOffset = 0;
uint64_t NumSymbols = 0;
uint64_t SymbolTableEntrySize = 0;
union Elf_Sym ** SymbolPtrs = NULL;
char ** SymbolNames;
union Elf_Sym **SymbolPtrs = NULL;
char **SymbolNames;
int32 TblDefSymbolIndex = -1;
CFE_TBL_FileDef_t TblFileDef;
int32 UserObjSymbolIndex = -1;
Expand Down Expand Up @@ -924,7 +924,7 @@ int32 ProcessCmdLineOptions(int ArgumentCount, char *Arguments[])
bool InputFileSpecified = false;
bool OutputFileSpecified = false;
int i = 1;
char * EndPtr;
char *EndPtr;
uint32 MaxDay;
struct tm FileEpochTm;
struct tm ScEpochTm;
Expand Down Expand Up @@ -2244,7 +2244,8 @@ int32 GetStringFromMap(char *Result, ElfStrMap *Map, int32 Key)

if (Status == FAILED)
{
sprintf(Result, Map->String, Key);
// Using snprintf to avoid overflow
snprintf(Result, sizeof(String), Map->String, Key);
}

return Status;
Expand Down