parent
d897a96c05
commit
4935cf5fb3
|
@ -32,9 +32,6 @@
|
||||||
static int consoleActionCount = 0;
|
static int consoleActionCount = 0;
|
||||||
static TokenCallback consoleActions[CONSOLE_MAX_ACTIONS] CCM_OPTIONAL;
|
static TokenCallback consoleActions[CONSOLE_MAX_ACTIONS] CCM_OPTIONAL;
|
||||||
|
|
||||||
#define SECURE_LINE_PREFIX "sec!"
|
|
||||||
#define SECURE_LINE_PREFIX_LENGTH 4
|
|
||||||
|
|
||||||
void resetConsoleActions(void) {
|
void resetConsoleActions(void) {
|
||||||
consoleActionCount = 0;
|
consoleActionCount = 0;
|
||||||
}
|
}
|
||||||
|
@ -468,40 +465,6 @@ void initConsoleLogic() {
|
||||||
addConsoleActionI("echo", echo);
|
addConsoleActionI("echo", echo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return NULL if input line validation failed, reference to line payload if validation succeeded.
|
|
||||||
* @see sendOutConfirmation() for command confirmation processing.
|
|
||||||
*/
|
|
||||||
char *validateSecureLine(char *line) {
|
|
||||||
if (line == NULL)
|
|
||||||
return NULL;
|
|
||||||
if (strncmp(SECURE_LINE_PREFIX, line, SECURE_LINE_PREFIX_LENGTH) == 0) {
|
|
||||||
// COM protocol looses bytes, this is a super-naive error detection
|
|
||||||
|
|
||||||
// print("Got secure mode request header [%s]\r\n", line);
|
|
||||||
line += SECURE_LINE_PREFIX_LENGTH;
|
|
||||||
// print("Got secure mode request command [%s]\r\n", line);
|
|
||||||
|
|
||||||
char *divider = line;
|
|
||||||
while (*divider != '!') {
|
|
||||||
if (*divider == '\0') {
|
|
||||||
efiPrintf("Divider not found [%s]", line);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
divider++;
|
|
||||||
}
|
|
||||||
*divider++ = 0; // replacing divider symbol with zero
|
|
||||||
int expectedLength = atoi(line);
|
|
||||||
line = divider;
|
|
||||||
int actualLength = strlen(line);
|
|
||||||
if (expectedLength != actualLength) {
|
|
||||||
efiPrintf("Error detected: expected %d but got %d in [%s]", expectedLength, actualLength, line);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char handleBuffer[MAX_CMD_LINE_LENGTH + 1];
|
static char handleBuffer[MAX_CMD_LINE_LENGTH + 1];
|
||||||
|
|
||||||
static int handleConsoleLineInternal(const char *commandLine, int lineLength) {
|
static int handleConsoleLineInternal(const char *commandLine, int lineLength) {
|
||||||
|
@ -540,7 +503,6 @@ static int handleConsoleLineInternal(const char *commandLine, int lineLength) {
|
||||||
* @brief This function takes care of one command line once we have it
|
* @brief This function takes care of one command line once we have it
|
||||||
*/
|
*/
|
||||||
void handleConsoleLine(char *line) {
|
void handleConsoleLine(char *line) {
|
||||||
line = validateSecureLine(line);
|
|
||||||
if (line == NULL)
|
if (line == NULL)
|
||||||
return; // error detected
|
return; // error detected
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ extern "C"
|
||||||
{
|
{
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
char *validateSecureLine(char *line);
|
|
||||||
void resetConsoleActions(void);
|
void resetConsoleActions(void);
|
||||||
void helpCommand(void);
|
void helpCommand(void);
|
||||||
void initConsoleLogic();
|
void initConsoleLogic();
|
||||||
|
|
|
@ -324,8 +324,6 @@ TEST(misc, testConsoleLogic) {
|
||||||
strcpy(buffer, "\"echo\"");
|
strcpy(buffer, "\"echo\"");
|
||||||
ASSERT_TRUE(strEqual("echo", unquote(buffer))) << "unquote quoted";
|
ASSERT_TRUE(strEqual("echo", unquote(buffer))) << "unquote quoted";
|
||||||
|
|
||||||
char *ptr = validateSecureLine(UNKNOWN_COMMAND);
|
|
||||||
ASSERT_EQ(0, strcmp(UNKNOWN_COMMAND, ptr));
|
|
||||||
ASSERT_EQ(10, tokenLength(UNKNOWN_COMMAND));
|
ASSERT_EQ(10, tokenLength(UNKNOWN_COMMAND));
|
||||||
|
|
||||||
// handling invalid token should work
|
// handling invalid token should work
|
||||||
|
|
Loading…
Reference in New Issue