summaryrefslogtreecommitdiffstats
path: root/fmap.c
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2022-02-14 17:07:39 -0800
committerEdward O'Callaghan <quasisec@chromium.org>2022-02-20 22:28:17 +0000
commit016b5abc837cc8ceaa939d1e881cb07a3185cbff (patch)
tree5142e26e453d29e6b91c270e9f1dfaa5961afee8 /fmap.c
parent9a52d20b34b39df6402d3f342ae4d19dbd358df7 (diff)
downloadflashrom-016b5abc837cc8ceaa939d1e881cb07a3185cbff.tar.gz
flashrom-016b5abc837cc8ceaa939d1e881cb07a3185cbff.tar.bz2
flashrom-016b5abc837cc8ceaa939d1e881cb07a3185cbff.zip
libflashrom/fmap: Don't use off_t for flash offsets
off_t is a special POSIX type that is used to represent file offsets in certain APIs (e.g. lseek(), mmap()), and should not be reused to represent anything else (such as flash offsets). In particular, the width of the type may change based on the definition of the _FILE_OFFSET_BITS macro. Using such a type at the libflashrom interface is particularly dangerous, because if a program is built with a different _FILE_OFFSET_BITS value than libflashrom, the resulting ABI corruption will cause very very nasty and confusing bugs. This patch replaces all instances of off_t that are not related to file offsets with (s)size_t. BUG=b:219811851 TEST=`elogtool list` on cherry. Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I68a386973f79ea634f63dfcd7d95a63400e1fdee Reviewed-on: https://review.coreboot.org/c/flashrom/+/61943 Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'fmap.c')
-rw-r--r--fmap.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/fmap.c b/fmap.c
index 0236b621a..bd847bd0b 100644
--- a/fmap.c
+++ b/fmap.c
@@ -91,15 +91,15 @@ static int is_valid_fmap(const struct fmap *fmap)
* -1 to indicate that fmap was not found
* -2 to indicate fmap is truncated or exceeds buffer + len
*/
-static off_t fmap_lsearch(const uint8_t *buf, size_t len)
+static ssize_t fmap_lsearch(const uint8_t *buf, size_t len)
{
- off_t offset;
+ ssize_t offset;
bool fmap_found = 0;
if (len < sizeof(struct fmap))
return -1;
- for (offset = 0; offset <= (off_t)(len - sizeof(struct fmap)); offset++) {
+ for (offset = 0; offset <= (ssize_t)(len - sizeof(struct fmap)); offset++) {
if (is_valid_fmap((struct fmap *)&buf[offset])) {
fmap_found = 1;
break;
@@ -131,7 +131,7 @@ static off_t fmap_lsearch(const uint8_t *buf, size_t len)
*/
int fmap_read_from_buffer(struct fmap **fmap_out, const uint8_t *const buf, size_t len)
{
- off_t offset = fmap_lsearch(buf, len);
+ ssize_t offset = fmap_lsearch(buf, len);
if (offset < 0) {
msg_gdbg("Unable to find fmap in provided buffer.\n");
return 2;