Skip to content

Commit

Permalink
NetUtilsWrapper: don't execute non-whitelisted commands.
Browse files Browse the repository at this point in the history
Bug: 36463595
Test: marlin builds, boots
Test: wifi calling works
Change-Id: Ic26adf95544ec4465d1182bb72c87fe4c9b05378
  • Loading branch information
lcolitti committed May 23, 2017
1 parent 3c57e25 commit 3394786
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions netutils_wrappers/NetUtilsWrapper-1.0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const char *EXPECTED_REGEXPS[] = {
};

bool checkExpectedCommand(int argc, char **argv) {
static bool loggedError = false;
std::vector<const char*> allArgs(argc);
for (int i = 0; i < argc; i++) {
allArgs[i] = argv[i];
Expand All @@ -92,7 +93,11 @@ bool checkExpectedCommand(int argc, char **argv) {
return true;
}
}
ALOGI("Unexpected command: %s", fullCmd.c_str());
if (!loggedError) {
ALOGI("Unexpected command: %s", fullCmd.c_str());
fprintf(stderr, LOG_TAG ": Unexpected command: %s", fullCmd.c_str());
loggedError = true;
}
return false;
}

Expand All @@ -118,12 +123,12 @@ int doMain(int argc, char **argv) {
exit(EXIT_FAILURE);
}
argv[0] = cmd;
checkExpectedCommand(argc, argv);
execv(cmd, argv);
if (checkExpectedCommand(argc, argv)) {
execv(cmd, argv);
}
}
}

// must never reach here
fprintf(stderr, "(%s:%d) is not a supported net util\n", progname, errno);
// Invalid command. Reject and fail.
exit(EXIT_FAILURE);
}

0 comments on commit 3394786

Please sign in to comment.