diff options
author | Timm Bäder <tbaeder@redhat.com> | 2021-02-17 09:42:19 +0100 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2021-03-01 17:27:08 +0100 |
commit | e95d1fbb7745b6bb945b25b6429455ace43c9ed8 (patch) | |
tree | 0c0e16aa1b189a179839e670919ce17283550eaf | |
parent | fd1b3802a7b15b33e78aa4c8ef0e3d184c280253 (diff) | |
download | elfutils-e95d1fbb7745b6bb945b25b6429455ace43c9ed8.tar.gz |
elflint: Pull left() in file scope
And rename it to buffer_left() to be a bit more descriptive
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
-rw-r--r-- | src/ChangeLog | 6 | ||||
-rw-r--r-- | src/elflint.c | 17 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 62c58908..065fdd58 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2021-02-17 Timm Bäder <tbaeder@redhat.com> + * elflint.c (check_attributes): Rename and move left function... + (buffer_left): ...as static toplevel function taking both an + Elf_Data pointer argument and the unsigned char pointer p. + +2021-02-17 Timm Bäder <tbaeder@redhat.com> + * elflint.c (check_attributes): Rename and move pos function... (buffer_pos): ...as static toplevel function taking an extra Elf_Data pointer argument. diff --git a/src/elflint.c b/src/elflint.c index 4df6f6e5..85cc7833 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -3434,6 +3434,12 @@ buffer_pos (Elf_Data *data, const unsigned char *p) return p - (const unsigned char *) data->d_buf; } +inline size_t +buffer_left (Elf_Data *data, const unsigned char *p) +{ + return (const unsigned char *) data->d_buf + data->d_size - p; +} + static void check_attributes (Ebl *ebl, GElf_Ehdr *ehdr, GElf_Shdr *shdr, int idx) { @@ -3460,12 +3466,7 @@ check_attributes (Ebl *ebl, GElf_Ehdr *ehdr, GElf_Shdr *shdr, int idx) return; } - inline size_t left (void) - { - return (const unsigned char *) data->d_buf + data->d_size - p; - } - - while (left () >= 4) + while (buffer_left (data, p) >= 4) { uint32_t len; memcpy (&len, p, sizeof len); @@ -3478,7 +3479,7 @@ section [%2d] '%s': offset %zu: zero length field in attribute section\n"), if (MY_ELFDATA != ehdr->e_ident[EI_DATA]) CONVERT (len); - if (len > left ()) + if (len > buffer_left (data, p)) { ERROR (_("\ section [%2d] '%s': offset %zu: invalid length in attribute section\n"), @@ -3614,7 +3615,7 @@ section [%2d] '%s': offset %zu: vendor '%s' unknown\n"), idx, section_name (ebl, idx), buffer_pos (data, p), name); } - if (left () != 0) + if (buffer_left (data, p) != 0) ERROR (_("\ section [%2d] '%s': offset %zu: extra bytes after last attribute section\n"), idx, section_name (ebl, idx), buffer_pos (data, p)); |