aboutsummaryrefslogtreecommitdiffstats
path: root/com32/hdt
diff options
context:
space:
mode:
authorErwan Velu <erwanaliasr1@gmail.com>2010-06-22 21:43:27 +0200
committerErwan Velu <erwanaliasr1@gmail.com>2010-06-22 21:43:27 +0200
commite7fa1978a0fa326d50bff091b454ecc06aec5330 (patch)
tree93b9335e71e8a68ac3b226c55c1d71148ba0d384 /com32/hdt
parent3e3afd955d5708c65c33545c7f3094999a7f1395 (diff)
downloadsyslinux-e7fa1978a0fa326d50bff091b454ecc06aec5330.tar.gz
syslinux-e7fa1978a0fa326d50bff091b454ecc06aec5330.tar.xz
syslinux-e7fa1978a0fa326d50bff091b454ecc06aec5330.zip
Replacing strncpy by strlcpy
As reported by hpa, strlcpy is safer and could prevent some bugs. So I replaced all strncpy by strlcpy calls.
Diffstat (limited to 'com32/hdt')
-rw-r--r--com32/hdt/hdt-cli.c24
-rw-r--r--com32/hdt/hdt-common.c26
2 files changed, 25 insertions, 25 deletions
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index dad2d408..639bcdb8 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -85,7 +85,7 @@ static void autocomplete_add_token_to_list(const char *token)
{
struct autocomplete_list *new = malloc(sizeof(struct autocomplete_list));
- strncpy(new->autocomplete_token, token, sizeof(new->autocomplete_token));
+ strlcpy(new->autocomplete_token, token, sizeof(new->autocomplete_token));
new->next = NULL;
autocomplete_backlog++;
@@ -277,13 +277,13 @@ static void expand_aliases(char *line __unused, char **command, char **module,
*argc = 1;
*argv = malloc(*argc * sizeof(char *));
argv[0] = malloc((sizeof(*command) + 1) * sizeof(char));
- strncpy(argv[0], *command, sizeof(*command) + 1);
+ strlcpy(argv[0], *command, sizeof(*command) + 1);
dprintf("CLI DEBUG: ALIAS %s ", *command);
- strncpy(*command, CLI_SET, sizeof(CLI_SET)); /* set */
+ strlcpy(*command, CLI_SET, sizeof(CLI_SET)); /* set */
*module = malloc(sizeof(CLI_MODE) * sizeof(char));
- strncpy(*module, CLI_MODE, sizeof(CLI_MODE)); /* mode */
+ strlcpy(*module, CLI_MODE, sizeof(CLI_MODE)); /* mode */
dprintf("--> %s %s %s\n", *command, *module, argv[0]);
goto out;
@@ -295,7 +295,7 @@ static void expand_aliases(char *line __unused, char **command, char **module,
if (!strncmp(*command, hdt_aliases[i].aliases[j],
sizeof(hdt_aliases[i].aliases[j]))) {
dprintf("CLI DEBUG: ALIAS %s ", *command);
- strncpy(*command, hdt_aliases[i].command,
+ strlcpy(*command, hdt_aliases[i].command,
sizeof(hdt_aliases[i].command) + 1);
dprintf("--> %s\n", *command);
goto out; /* Don't allow chaining aliases */
@@ -367,14 +367,14 @@ static void parse_command_line(char *line, char **command, char **module,
if (token_found == 0) {
/* Main command to execute */
*command = malloc((token_len + 1) * sizeof(char));
- strncpy(*command, pch, token_len);
+ strlcpy(*command, pch, token_len);
(*command)[token_len] = '\0';
dprintf("CLI DEBUG: command = %s\n", *command);
args_pos += args_len;
} else if (token_found == 1) {
/* Module */
*module = malloc((token_len + 1) * sizeof(char));
- strncpy(*module, pch, token_len);
+ strlcpy(*module, pch, token_len);
(*module)[token_len] = '\0';
dprintf("CLI DEBUG: module = %s\n", *module);
args_pos += args_len;
@@ -396,7 +396,7 @@ static void parse_command_line(char *line, char **command, char **module,
while (pch != NULL) {
dprintf("CLI DEBUG: argv[%d] = %s\n", argc_iter, pch);
argv[argc_iter] = malloc(sizeof(pch) * sizeof(char));
- strncpy(argv[argc_iter], pch, sizeof(pch));
+ strlcpy(argv[argc_iter], pch, sizeof(pch));
argc_iter++;
pch = strtok(NULL, CLI_SPACE);
/*
@@ -918,7 +918,7 @@ void start_cli_mode(struct s_hardware *hardware)
/* Let's make that future position the one we use */
memset(INPUT, 0, sizeof(INPUT));
- strncpy(INPUT, hdt_cli.history[future_history_pos], sizeof(INPUT));
+ strlcpy(INPUT, hdt_cli.history[future_history_pos], sizeof(INPUT));
/* Clear the line */
clear_line();
@@ -959,7 +959,7 @@ void start_cli_mode(struct s_hardware *hardware)
/* Let's make that future position the one we use */
memset(INPUT, 0, sizeof(INPUT));
- strncpy(INPUT, hdt_cli.history[future_history_pos], sizeof(INPUT));
+ strlcpy(INPUT, hdt_cli.history[future_history_pos], sizeof(INPUT));
/* Clear the line */
clear_line();
@@ -979,7 +979,7 @@ void start_cli_mode(struct s_hardware *hardware)
move_cursor_to_column(0);
reset_prompt();
printf("%s", autocomplete_last_seen->autocomplete_token);
- strncpy(INPUT,
+ strlcpy(INPUT,
autocomplete_last_seen->autocomplete_token,
sizeof(INPUT));
hdt_cli.cursor_pos = strlen(INPUT);
@@ -1093,7 +1093,7 @@ void start_cli_mode(struct s_hardware *hardware)
char key[2];
int trailing_chars = strlen(INPUT) - hdt_cli.cursor_pos;
memset(temp_command, 0, sizeof(temp_command));
- strncpy(temp_command, INPUT, hdt_cli.cursor_pos);
+ strlcpy(temp_command, INPUT, hdt_cli.cursor_pos);
sprintf(key, "%c", current_key);
strncat(temp_command, key, 1);
strncat(temp_command,
diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c
index 736d9b6e..114e6ee9 100644
--- a/com32/hdt/hdt-common.c
+++ b/com32/hdt/hdt-common.c
@@ -70,23 +70,23 @@ void detect_parameters(const int argc, const char *argv[],
if (!strncmp(argv[i], "quiet", 5)) {
quiet = true;
} else if (!strncmp(argv[i], "modules_pcimap=", 15)) {
- strncpy(hardware->modules_pcimap_path, argv[i] + 15,
+ strlcpy(hardware->modules_pcimap_path, argv[i] + 15,
sizeof(hardware->modules_pcimap_path));
convert_isolinux_filename(hardware->modules_pcimap_path, hardware);
} else if (!strncmp(argv[i], "pciids=", 7)) {
- strncpy(hardware->pciids_path, argv[i] + 7,
+ strlcpy(hardware->pciids_path, argv[i] + 7,
sizeof(hardware->pciids_path));
convert_isolinux_filename(hardware->pciids_path, hardware);
} else if (!strncmp(argv[i], "modules_alias=", 14)) {
- strncpy(hardware->modules_alias_path, argv[i] + 14,
+ strlcpy(hardware->modules_alias_path, argv[i] + 14,
sizeof(hardware->modules_alias_path));
convert_isolinux_filename(hardware->modules_alias_path, hardware);
} else if (!strncmp(argv[i], "memtest=", 8)) {
- strncpy(hardware->memtest_label, argv[i] + 8,
+ strlcpy(hardware->memtest_label, argv[i] + 8,
sizeof(hardware->memtest_label));
convert_isolinux_filename(hardware->memtest_label, hardware);
} else if (!strncmp(argv[i], "reboot=", 7)) {
- strncpy(hardware->reboot_label, argv[i] + 7,
+ strlcpy(hardware->reboot_label, argv[i] + 7,
sizeof(hardware->reboot_label));
convert_isolinux_filename(hardware->reboot_label, hardware);
} else if (!strncmp(argv[i], "vesa", 4)) {
@@ -94,7 +94,7 @@ void detect_parameters(const int argc, const char *argv[],
max_console_lines = MAX_CLI_LINES;
/* If the user defines a background image */
if (!strncmp(argv[i], "vesa=", 5)) {
- strncpy(hardware->vesa_background, argv[i] + 5,
+ strlcpy(hardware->vesa_background, argv[i] + 5,
sizeof(hardware->vesa_background));
}
} else if (!strncmp(argv[i], "novesa", 6)) {
@@ -199,7 +199,7 @@ void init_hardware(struct s_hardware *hardware)
strcat(hardware->modules_alias_path, "modules.alias");
strcat(hardware->memtest_label, "memtest");
strcat(hardware->reboot_label, "reboot.c32");
- strncpy(hardware->vesa_background, CLI_DEFAULT_BACKGROUND,
+ strlcpy(hardware->vesa_background, CLI_DEFAULT_BACKGROUND,
sizeof(hardware->vesa_background));
}
@@ -277,11 +277,11 @@ int detect_vesa(struct s_hardware *hardware)
mode_ptr = GET_PTR(gi->video_mode_ptr);
oem_ptr = GET_PTR(gi->oem_vendor_name_ptr);
- strncpy(hardware->vesa.vendor, oem_ptr, sizeof(hardware->vesa.vendor));
+ strlcpy(hardware->vesa.vendor, oem_ptr, sizeof(hardware->vesa.vendor));
oem_ptr = GET_PTR(gi->oem_product_name_ptr);
- strncpy(hardware->vesa.product, oem_ptr, sizeof(hardware->vesa.product));
+ strlcpy(hardware->vesa.product, oem_ptr, sizeof(hardware->vesa.product));
oem_ptr = GET_PTR(gi->oem_product_rev_ptr);
- strncpy(hardware->vesa.product_revision, oem_ptr,
+ strlcpy(hardware->vesa.product_revision, oem_ptr,
sizeof(hardware->vesa.product_revision));
hardware->vesa.major_version = (gi->version >> 8) & 0xff;
@@ -533,13 +533,13 @@ void cpu_detect(struct s_hardware *hardware)
/* Old processors doesn't manage the identify commands
* Let's use the dmi value in that case */
if (strlen(remove_spaces(hardware->cpu.model)) == 0)
- strncpy(hardware->cpu.model, hardware->dmi.processor.version,
+ strlcpy(hardware->cpu.model, hardware->dmi.processor.version,
sizeof(hardware->cpu.model));
/* Some CPUs like to put many spaces in the model name
* That makes some weird display in console/menu
* Let's remove that mulitple spaces */
- strncpy(hardware->cpu.model,del_multi_spaces(hardware->cpu.model),sizeof(hardware->cpu.model));
+ strlcpy(hardware->cpu.model,del_multi_spaces(hardware->cpu.model),sizeof(hardware->cpu.model));
hardware->cpu_detection = true;
}
@@ -631,7 +631,7 @@ char *del_multi_spaces(char *p)
/* Let's copy to the current position
* the content from the second space*/
- strncpy(p, p + 1, strlen(p + 1));
+ strlcpy(p, p + 1, strlen(p + 1));
/* The string is 1 char smaller */
*(p + strlen(p) - 1) = '\0';