Skip to content

Commit

Permalink
Fix string literal UB in codeCoverage (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest authored Jan 22, 2024
1 parent 829917d commit a2a590f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions codeCoverage/Inst.C
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void initCoverage(int totalFuncs, int totalBBs) {
}

// Populates a record for a function
void registerFunc(int id, char *name, char *modName) {
void registerFunc(int id, char const* name, char const* modName) {
if (!enabled)
return;
funcs[id].funcName = name;
Expand All @@ -87,7 +87,7 @@ void registerFunc(int id, char *name, char *modName) {
}

// Populates a record for a basic block
void registerBB(int id, char *name, char *modName, unsigned long addr) {
void registerBB(int id, char const* name, char const* modName, unsigned long addr) {
if (!enabled)
return;
bbs[id].funcName = name;
Expand Down
4 changes: 2 additions & 2 deletions codeCoverage/Inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#endif

LIB_EXPORT void initCoverage(int, int);
LIB_EXPORT void registerFunc(int, char *, char *);
LIB_EXPORT void registerBB(int, char *, char *, unsigned long);
LIB_EXPORT void registerFunc(int, char const*, char const*);
LIB_EXPORT void registerBB(int, char const*, char const*, unsigned long);
LIB_EXPORT void incFuncCoverage(int);
LIB_EXPORT void incBBCoverage(int);
LIB_EXPORT void exitCoverage(int, int, int);
22 changes: 11 additions & 11 deletions codeCoverage/code_coverage.C
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static const char *USAGE = " [-bpsa] <binary> <output binary>\n \
static const char *OPT_STR = "bpsa";

// configuration options
char *inBinary = NULL;
char *outBinary = NULL;
char const*inBinary = NULL;
char const*outBinary = NULL;
bool includeSharedLib = false;
int printAll = 0;
bool bbCoverage = false;
Expand Down Expand Up @@ -118,7 +118,7 @@ bool parseArgs(int argc, char *argv[]) {
return true;
}

BPatch_function *findFuncByName(BPatch_image *appImage, char *funcName) {
BPatch_function *findFuncByName(BPatch_image *appImage, char const*funcName) {
/* fundFunctions returns a list of all functions with the name 'funcName' in
* the binary */
BPatch_Vector<BPatch_function *> funcs;
Expand All @@ -132,7 +132,7 @@ BPatch_function *findFuncByName(BPatch_image *appImage, char *funcName) {
}

bool insertFuncEntry(BPatch_binaryEdit *appBin, BPatch_function *curFunc,
char *funcName, BPatch_function *instIncFunc, int funcId) {
char const*funcName, BPatch_function *instIncFunc, int funcId) {
/* Find the instrumentation points */
vector<BPatch_point *> *funcEntry = curFunc->findPoint(BPatch_entry);
if (NULL == funcEntry) {
Expand Down Expand Up @@ -160,7 +160,7 @@ bool insertFuncEntry(BPatch_binaryEdit *appBin, BPatch_function *curFunc,
}

bool insertBBEntry(BPatch_binaryEdit *appBin, BPatch_function *curFunc,
char *funcName, const char *moduleName,
char const*funcName, char const*moduleName,
BPatch_function *instBBIncFunc, BPatch_function *registerBB,
int *bbIndex,
BPatch_Vector<BPatch_snippet *> *registerCalls) {
Expand Down Expand Up @@ -254,16 +254,16 @@ int main(int argc, char *argv[]) {
BPatch_image *appImage = appBin->getImage();
/* Find code coverage functions in the instrumentation library */
BPatch_function *instInitFunc =
findFuncByName(appImage, (char *)"initCoverage");
findFuncByName(appImage, "initCoverage");
BPatch_function *registerFunc =
findFuncByName(appImage, (char *)"registerFunc");
findFuncByName(appImage, "registerFunc");
BPatch_function *instIncFunc =
findFuncByName(appImage, (char *)"incFuncCoverage");
BPatch_function *registerBB = findFuncByName(appImage, (char *)"registerBB");
findFuncByName(appImage, "incFuncCoverage");
BPatch_function *registerBB = findFuncByName(appImage, "registerBB");
BPatch_function *instBBIncFunc =
findFuncByName(appImage, (char *)"incBBCoverage");
findFuncByName(appImage, "incBBCoverage");
BPatch_function *instExitFunc =
findFuncByName(appImage, (char *)"exitCoverage");
findFuncByName(appImage, "exitCoverage");

if (!instInitFunc || !instIncFunc || !instExitFunc || !instBBIncFunc ||
!registerFunc || !registerBB) {
Expand Down

0 comments on commit a2a590f

Please sign in to comment.