Skip to content

Commit

Permalink
libbpf: Fix theoretical u32 underflow in find_cd() function
Browse files Browse the repository at this point in the history
Coverity reported a potential underflow of the offset variable used in
the find_cd() function. Switch to using a signed 64 bit integer for the
representation of offset to make sure we can never underflow.

Fixes: 1eebcb6 ("libbpf: Implement basic zip archive parsing support")
Signed-off-by: Daniel Müller <deso@posteo.net>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230307215504.837321-1-deso@posteo.net
  • Loading branch information
Daniel Müller authored and Andrii Nakryiko committed Mar 7, 2023
1 parent a73dc91 commit 3ecde21
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions tools/lib/bpf/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ static int try_parse_end_of_cd(struct zip_archive *archive, __u32 offset)

static int find_cd(struct zip_archive *archive)
{
int64_t limit, offset;
int rc = -EINVAL;
int64_t limit;
__u32 offset;

if (archive->size <= sizeof(struct end_of_cd_record))
return -EINVAL;
Expand Down

0 comments on commit 3ecde21

Please sign in to comment.