Julius Werner has uploaded this change for review.

View Change

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. Since the
things we use this type for never get anywhere near the 32-bit limit
anyway, let's just replace it with fixed-width 32-bit integers.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I68a386973f79ea634f63dfcd7d95a63400e1fdee
---
M fmap.c
M libflashrom.c
M libflashrom.h
3 files changed, 6 insertions(+), 6 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/43/61943/1
diff --git a/fmap.c b/fmap.c
index 0236b62..23fa1eb 100644
--- a/fmap.c
+++ b/fmap.c
@@ -91,15 +91,15 @@
* -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 int32_t fmap_lsearch(const uint8_t *buf, size_t len)
{
- off_t offset;
+ int32_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 <= (int32_t)(len - sizeof(struct fmap)); offset++) {
if (is_valid_fmap((struct fmap *)&buf[offset])) {
fmap_found = 1;
break;
@@ -131,7 +131,7 @@
*/
int fmap_read_from_buffer(struct fmap **fmap_out, const uint8_t *const buf, size_t len)
{
- off_t offset = fmap_lsearch(buf, len);
+ int32_t offset = fmap_lsearch(buf, len);
if (offset < 0) {
msg_gdbg("Unable to find fmap in provided buffer.\n");
return 2;
diff --git a/libflashrom.c b/libflashrom.c
index fb70934..0ec44ee 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -534,7 +534,7 @@
* 1 on any other error.
*/
int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **const layout,
- struct flashctx *const flashctx, off_t offset, size_t len)
+ struct flashctx *const flashctx, uint32_t offset, size_t len)
{
#ifndef __FLASHROM_LITTLE_ENDIAN__
return 3;
diff --git a/libflashrom.h b/libflashrom.h
index 557978d..f264fda 100644
--- a/libflashrom.h
+++ b/libflashrom.h
@@ -109,7 +109,7 @@
int flashrom_layout_new(struct flashrom_layout **);
int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len);
int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **,
- struct flashrom_flashctx *, off_t offset, size_t length);
+ struct flashrom_flashctx *, uint32_t offset, size_t length);
int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout,
struct flashrom_flashctx *, const uint8_t *buf, size_t len);
int flashrom_layout_add_region(struct flashrom_layout *, size_t start, size_t end, const char *name);

To view, visit change 61943. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I68a386973f79ea634f63dfcd7d95a63400e1fdee
Gerrit-Change-Number: 61943
Gerrit-PatchSet: 1
Gerrit-Owner: Julius Werner <jwerner@chromium.org>
Gerrit-MessageType: newchange