Skip to content

Commit

Permalink
logger: convert: read_entry_from_ldc_file: Make sure string null term…
Browse files Browse the repository at this point in the history
…inated

Added a null string terminator to be sure that strings read from a file are
terminated correctly.

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki committed Sep 18, 2023
1 parent 1e951e4 commit 2d65226
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tools/logger/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ static int read_entry_from_ldc_file(struct ldc_entry *entry, uint32_t log_entry_
ret = -EINVAL;
goto out;
}
entry->file_name = (char *)malloc(entry->header.file_name_len);
entry->file_name = (char *)malloc(entry->header.file_name_len + 1);

if (!entry->file_name) {
log_err("can't allocate %d byte for entry.file_name\n",
Expand All @@ -648,6 +648,8 @@ static int read_entry_from_ldc_file(struct ldc_entry *entry, uint32_t log_entry_

ret = fread(entry->file_name, sizeof(char), entry->header.file_name_len,
global_config->ldc_fd);
entry->file_name[entry->header.file_name_len] = '\0';

if (ret != entry->header.file_name_len) {
log_err("Failed to read source filename for offset 0x%x in dictionary.\n",
entry_offset);
Expand All @@ -661,7 +663,7 @@ static int read_entry_from_ldc_file(struct ldc_entry *entry, uint32_t log_entry_
ret = -EINVAL;
goto out;
}
entry->text = (char *)malloc(entry->header.text_len);
entry->text = (char *)malloc(entry->header.text_len + 1);
if (!entry->text) {
log_err("can't allocate %d byte for entry.text\n", entry->header.text_len);
ret = -ENOMEM;
Expand All @@ -674,6 +676,7 @@ static int read_entry_from_ldc_file(struct ldc_entry *entry, uint32_t log_entry_
ret = -1;
goto out;
}
entry->text[entry->header.text_len] = '\0';

return 0;

Expand Down

0 comments on commit 2d65226

Please sign in to comment.