aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-11-18 20:15:55 -0800
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-11-18 20:15:55 -0800
commit1682c7e3b73c00727ddf4a5792633bded9d37e0e (patch)
tree6807d25e21d4c13dc02010fe618dae9f29cb1ea6
parent937dfc4e294cffff792d6f126efd6ff8b8480742 (diff)
downloadsyslinux-1682c7e3b73c00727ddf4a5792633bded9d37e0e.tar.gz
syslinux-1682c7e3b73c00727ddf4a5792633bded9d37e0e.tar.xz
syslinux-1682c7e3b73c00727ddf4a5792633bded9d37e0e.zip
hdt: more memory corruption fixes
A cli_module_descr can be defined with no modules (only a default callback). Cf. the syslinux module for instance. This patch adds a check for NULL structures before trying to dereference them. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
-rw-r--r--com32/hdt/hdt-cli-disk.c1
-rw-r--r--com32/hdt/hdt-cli.c40
2 files changed, 26 insertions, 15 deletions
diff --git a/com32/hdt/hdt-cli-disk.c b/com32/hdt/hdt-cli-disk.c
index 7f6b00db..c83c220e 100644
--- a/com32/hdt/hdt-cli-disk.c
+++ b/com32/hdt/hdt-cli-disk.c
@@ -224,7 +224,6 @@ struct cli_callback_descr list_disk_show_modules[] = {
},
};
-
struct cli_module_descr disk_show_modules = {
.modules = list_disk_show_modules,
.default_callback = disks_summary,
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index da8066c3..65750609 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -497,17 +497,19 @@ static void autocomplete_command(char *command)
* (single token commands for the current_mode)
*/
j = 0;
- while (current_mode->default_modules &&
- current_mode->default_modules->modules[j].name) {
- if (strncmp(current_mode->default_modules->modules[j].name,
- command,
- strlen(command)) == 0) {
- printf("%s\n",
- current_mode->default_modules->modules[j].name);
- autocomplete_add_token_to_list(current_mode->default_modules->modules[j].name);
+ if (current_mode->default_modules &&
+ current_mode->default_modules->modules) {
+ while (current_mode->default_modules->modules[j].name) {
+ if (strncmp(current_mode->default_modules->modules[j].name,
+ command,
+ strlen(command)) == 0) {
+ printf("%s\n",
+ current_mode->default_modules->modules[j].name);
+ autocomplete_add_token_to_list(current_mode->default_modules->modules[j].name);
+ }
+ j++;
}
- j++;
- }
+ }
/*
* Finally, if the current_mode is not hdt, list the available
@@ -516,6 +518,10 @@ static void autocomplete_command(char *command)
if (current_mode->mode == HDT_MODE)
return;
+ if (!hdt_mode.default_modules ||
+ !hdt_mode.default_modules->modules)
+ return;
+
j = 0;
while (hdt_mode.default_modules &&
hdt_mode.default_modules->modules[j].name) {
@@ -557,8 +563,11 @@ static void autocomplete_module(char *command, char* module)
char autocomplete_full_line[MAX_LINE_SIZE];
if (strncmp(CLI_SHOW, command, strlen(command)) == 0) {
- while (current_mode->show_modules &&
- current_mode->show_modules->modules[j].name) {
+ if (!current_mode->show_modules ||
+ !current_mode->show_modules->modules)
+ return;
+
+ while (current_mode->show_modules->modules[j].name) {
if (strncmp(current_mode->show_modules->modules[j].name,
module,
strlen(module)) == 0) {
@@ -572,8 +581,11 @@ static void autocomplete_module(char *command, char* module)
}
} else if (strncmp(CLI_SET, command, strlen(command)) == 0) {
j = 0;
- while (current_mode->set_modules &&
- current_mode->set_modules->modules[j].name) {
+ if (!current_mode->set_modules ||
+ !current_mode->set_modules->modules)
+ return;
+
+ while (current_mode->set_modules->modules[j].name) {
if (strncmp(current_mode->set_modules->modules[j].name,
module,
strlen(module)) == 0) {