aboutsummaryrefslogtreecommitdiffstats
path: root/com32/hdt
diff options
context:
space:
mode:
authorErwan Velu <erwan.velu@free.fr>2009-03-19 10:57:46 +0100
committerErwan Velu <erwan.velu@free.fr>2009-03-19 10:57:46 +0100
commit8100f9bb22027fb9fc553c91631f4fb5770b0e30 (patch)
treeaeb9cc11b015d4115722ee87fe0d5a5d3e4ea5a0 /com32/hdt
parentfeac6f3f601db87d78ba2be1f5645df60a7ed798 (diff)
downloadsyslinux.git-8100f9bb22027fb9fc553c91631f4fb5770b0e30.tar.gz
syslinux.git-8100f9bb22027fb9fc553c91631f4fb5770b0e30.tar.xz
syslinux.git-8100f9bb22027fb9fc553c91631f4fb5770b0e30.zip
hdt: Renaming display_prompt to reset_prompt
Impact: Fix buffer corruption in cli. The rename occurs to match the reality. We actually do more than displaying the prompt as we reset some vars. One of this parameters where wrong too and could occurs corruption. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/hdt')
-rw-r--r--com32/hdt/hdt-cli.c15
-rw-r--r--com32/hdt/hdt-cli.h4
2 files changed, 12 insertions, 7 deletions
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index 160089d3..20cc03ff 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -233,13 +233,14 @@ static void exec_command(char *command, struct s_cli_mode *cli_mode,
}
}
-static void display_prompt(char command[256], struct s_cli_mode *cli_mode,
+static void reset_prompt(char *command, struct s_cli_mode *cli_mode,
int *cur_pos)
{
/* No need to display the prompt if we exit */
if (cli_mode->mode != EXIT_MODE) {
- memset(command, 0, sizeof command);
printf("%s", cli_mode->prompt);
+ /* Reset the line */
+ memset(command, '\0', MAX_LINE_SIZE);
*cur_pos = 0;
}
}
@@ -247,7 +248,7 @@ static void display_prompt(char command[256], struct s_cli_mode *cli_mode,
/* Code that manages the cli mode */
void start_cli_mode(struct s_hardware *hardware)
{
- char cli_line[256];
+ char cli_line[MAX_LINE_SIZE];
struct s_cli_mode cli_mode;
int current_key = 0;
int cur_pos = 0;
@@ -255,7 +256,7 @@ void start_cli_mode(struct s_hardware *hardware)
printf("Entering CLI mode\n");
- display_prompt(cli_line, &cli_mode, &cur_pos);
+ reset_prompt(cli_line, &cli_mode, &cur_pos);
while (cli_mode.mode != EXIT_MODE) {
//fgets(cli_line, sizeof cli_line, stdin);
@@ -270,7 +271,7 @@ void start_cli_mode(struct s_hardware *hardware)
case KEY_ENTER:
more_printf("\n");
exec_command(cli_line, &cli_mode, hardware);
- display_prompt(cli_line, &cli_mode, &cur_pos);
+ reset_prompt(cli_line, &cli_mode, &cur_pos);
break;
case KEY_BACKSPACE:
/* Don't delete prompt */
@@ -291,11 +292,11 @@ void start_cli_mode(struct s_hardware *hardware)
case KEY_F1:
more_printf("\n");
exec_command(CLI_HELP, &cli_mode, hardware);
- display_prompt(cli_line, &cli_mode, &cur_pos);
+ reset_prompt(cli_line, &cli_mode, &cur_pos);
break;
default:
/* Prevent overflow */
- if (cur_pos > 254)
+ if (cur_pos > MAX_LINE_SIZE - 2)
break;
putchar(current_key);
cli_line[cur_pos] = current_key;
diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h
index 72e46a36..8951bfed 100644
--- a/com32/hdt/hdt-cli.h
+++ b/com32/hdt/hdt-cli.h
@@ -32,6 +32,10 @@
#include "hdt-common.h"
+#define MAX_LINE_SIZE 256
+
+#define CLI_SPACE " "
+#define CLI_LF "\n"
#define CLI_CLEAR "clear"
#define CLI_EXIT "exit"
#define CLI_HELP "help"