]>
Commit | Line | Data |
---|---|---|
0749e45a AM |
1 | --- rpm.org/file/src/readelf.c.orig 2004-03-22 21:28:40.000000000 +0100 |
2 | +++ rpm/file/src/readelf.c 2004-03-28 23:25:50.806604968 +0200 | |
3 | @@ -147,6 +147,9 @@ | |
4 | getu32(swap, ph32.p_align) : 4) \ | |
30427c58 | 5 | : (off_t) (ph64.p_align ? \ |
0749e45a AM |
6 | getu64(swap, ph64.p_align) : 4))) |
7 | +#define ph_filesz (class == ELFCLASS32 \ | |
8 | + ? getu32(swap, ph32.p_filesz) \ | |
9 | + : getu64(swap, ph64.p_filesz)) | |
10 | #define nh_size (class == ELFCLASS32 \ | |
30427c58 JB |
11 | ? sizeof nh32 \ |
12 | : sizeof nh64) | |
0749e45a AM |
13 | @@ -250,7 +253,7 @@ |
14 | file_badseek(ms); | |
15 | return -1; | |
30427c58 | 16 | } |
0749e45a AM |
17 | - bufsize = read(fd, nbuf, BUFSIZ); |
18 | + bufsize = read(fd, nbuf, ((ph_filesz < BUFSIZ) ? ph_filesz : BUFSIZ)); | |
30427c58 | 19 | if (bufsize == -1) { |
0749e45a AM |
20 | file_badread(ms); |
21 | return -1; | |
22 | @@ -313,7 +316,7 @@ | |
7e18e7ef | 23 | noff = offset; |
0749e45a | 24 | doff = ELF_ALIGN(offset + namesz); |
7e18e7ef | 25 | |
0749e45a AM |
26 | - if (offset + namesz >= size) { |
27 | + if (offset + namesz > size) { | |
7e18e7ef JB |
28 | /* |
29 | * We're past the end of the buffer. | |
30 | */ | |
0749e45a | 31 | @@ -321,7 +324,7 @@ |
7e18e7ef JB |
32 | } |
33 | ||
0749e45a AM |
34 | offset = ELF_ALIGN(doff + descsz); |
35 | - if (offset + descsz >= size) { | |
36 | + if (doff + descsz > size) { | |
7e18e7ef | 37 | return offset; |
0749e45a | 38 | } |
7e18e7ef | 39 | |
0749e45a AM |
40 | @@ -670,7 +673,8 @@ |
41 | file_badseek(ms); | |
42 | return -1; | |
30427c58 | 43 | } |
0749e45a AM |
44 | - bufsize = read(fd, nbuf, sizeof(nbuf)); |
45 | + bufsize = read(fd, nbuf, | |
30427c58 JB |
46 | + ((ph_filesz < sizeof(nbuf)) ? ph_filesz : sizeof(nbuf))); |
47 | if (bufsize == -1) { | |
0749e45a AM |
48 | file_badread(ms); |
49 | return -1; | |
50 | @@ -684,7 +688,7 @@ | |
51 | if (offset == 0) | |
52 | break; | |
30427c58 | 53 | } |
0749e45a AM |
54 | - if (lseek(fd, savedoffset + offset, SEEK_SET) |
55 | + if (lseek(fd, savedoffset, SEEK_SET) | |
56 | == (off_t)-1) { | |
57 | file_badseek(ms); | |
58 | return -1; |