diff options
| author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2021-08-29 20:47:46 +0200 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2021-09-08 10:41:28 -0400 |
| commit | ecaf92ac2e34923b4b98e06e9d86e42ee18ae21f (patch) | |
| tree | 040bb75ffb9bfa7b4ca31b05217d9f88ea6aa92f /csv.c | |
| parent | 72a95aef81e6fb82f6b467cf2890f8b38a75aea1 (diff) | |
| download | efi-boot-shim-ecaf92ac2e34923b4b98e06e9d86e42ee18ae21f.tar.gz efi-boot-shim-ecaf92ac2e34923b4b98e06e9d86e42ee18ae21f.zip | |
csv: detect end of csv file correctly
.sbat sections contain user supplied data. We should not assume that it is
well formed. The last line feed might be missing or it might not be at the
end of the file. Instead one or more \0 might follow.
In parse_csv_data() variable 'line' is a pointer with a value between
the values of 'data' and 'data_end'.
There is no reason to check that it is non-zero after assigning it
from 'data' as we already check 'data'.
Instead at the beginning of the file and after each line we must check that
we have not reached the end of the file marked by a '\0' character.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'csv.c')
| -rw-r--r-- | csv.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -15,6 +15,7 @@ parse_csv_line(char * line, size_t max, size_t *n_columns, const char *columns[] char *token = NULL; bool valid = true; + for (n = 0; n < *n_columns; n++) { if (valid) { @@ -62,16 +63,17 @@ parse_csv_data(char *data, char *data_end, size_t n_columns, list_t *list) } max = (uintptr_t)end - (uintptr_t)line + (end > line ? 1 : 0); + if (is_utf8_bom(line, max)) - if (line && is_utf8_bom(line, max)) line += UTF8_BOM_SIZE; - while (line && line <= data_end) { + while (line <= data_end && *line) { size_t entrysz = sizeof(char *) * n_columns + sizeof(struct csv_row); struct csv_row *entry; size_t m_columns = n_columns; char *delim; bool found = true; + bool eof = false; end = data_end; max = (uintptr_t)end - (uintptr_t)line + (end > line ? 1 : 0); @@ -91,6 +93,9 @@ parse_csv_data(char *data, char *data_end, size_t n_columns, list_t *list) end = tmp; } max = (uintptr_t)end - (uintptr_t)line + (end > line ? 1 : 0); + + if (!*end) + eof = true; *end = '\0'; if (line == data_end || max == 0) { @@ -115,6 +120,9 @@ parse_csv_data(char *data, char *data_end, size_t n_columns, list_t *list) parse_csv_line(line, max, &m_columns, (const char **)entry->columns); entry->n_columns = m_columns; + if (eof) + break; + line = end + 1; } |
