diff options
author | Hung-Te Lin <hungte@chromium.org> | 2022-04-28 17:26:32 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-05-03 08:57:18 +0000 |
commit | 53491084865df3620193304d896d048c1acf5882 (patch) | |
tree | bad918b7741329f89b60c80d75047fa7d8521e0f | |
parent | 567d37e7a4d3fc88587b873cc0ef40d8812366d6 (diff) | |
download | vboot-53491084865df3620193304d896d048c1acf5882.tar.gz |
futility: updater: always add a \0 when reading files from archivesstabilize-14771.Bfactory-firmware-ti50-guc-14778.Bfactory-14778.B
To simplify parsing text files in future we want the archive_read_file
to always return a NULL terminated string on success.
BUG=None
TEST=make; run test
BRANCH=None
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Change-Id: I0dd0105971a80d857a1b05d9680b34b42dbff7e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3612645
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Julius Werner <jwerner@chromium.org>
-rw-r--r-- | futility/updater_archive.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/futility/updater_archive.c b/futility/updater_archive.c index 65b448d9..11b4be1e 100644 --- a/futility/updater_archive.c +++ b/futility/updater_archive.c @@ -191,6 +191,7 @@ static int archive_fallback_read_file(void *handle, const char *fname, VB2_DEBUG("Reading %s\n", path); *data = NULL; *size = 0; + /* vb2_read_file already has an extra '\0' in the end. */ r = vb2_read_file(path, data, size) != VB2_SUCCESS; if (mtime) { if (stat(path, &st) == 0) @@ -305,12 +306,13 @@ static int archive_zip_read_file(void *handle, const char *fname, ERROR("Failed to open entry in ZIP: %s\n", fname); return 1; } - *data = (uint8_t *)malloc(stat.size); + *data = (uint8_t *)malloc(stat.size + 1); if (*data) { if (zip_fread(fp, *data, stat.size) == stat.size) { if (mtime) *mtime = stat.mtime; *size = stat.size; + (*data)[stat.size] = '\0'; } else { ERROR("Failed to read entry in zip: %s\n", fname); free(*data); @@ -448,6 +450,8 @@ static int archive_walk(struct archive *ar, void *arg, * Reads a file from archive. * If entry name (fname) is an absolute path (/file), always read * from real file system. + * The returned data must always have one extra (not included by size) '\0' in + * the end of the allocated buffer for C string processing. * Returns 0 on success (data and size reflects the file content), * otherwise non-zero as failure. */ |