diff options
author | arekm <devnull@localhost> | 2004-06-17 20:53:28 +0000 |
---|---|---|
committer | arekm <devnull@localhost> | 2004-06-17 20:53:28 +0000 |
commit | a413bb610f3f6ffe616650206ce096f61260074c (patch) | |
tree | 5ac28764c7282b5b250d7fe1d38eec0a521977e2 /file/src | |
parent | 40100f75a42b1b07efeb2f9a357f1291a3873aa4 (diff) | |
download | librpm-tizen-a413bb610f3f6ffe616650206ce096f61260074c.tar.gz librpm-tizen-a413bb610f3f6ffe616650206ce096f61260074c.tar.bz2 librpm-tizen-a413bb610f3f6ffe616650206ce096f61260074c.zip |
- fix: readelf.c breakage on some non x86 arches (qboosh@PLD).
(on top of previous readelf.c commit)
CVS patchset: 7346
CVS date: 2004/06/17 20:53:28
Diffstat (limited to 'file/src')
-rw-r--r-- | file/src/readelf.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/file/src/readelf.c b/file/src/readelf.c index 5db9bf946..d482fc71c 100644 --- a/file/src/readelf.c +++ b/file/src/readelf.c @@ -136,6 +136,9 @@ getu64(const fmagic fm, uint64_t value) getu32(fm, ph32.p_align) : 4) \ : (off_t) (ph64.p_align ? \ getu64(fm, ph64.p_align) : 4))) +#define ph_filesz (fm->cls == ELFCLASS32 \ + ? getu32(fm, ph32.p_filesz) \ + : getu64(fm, ph64.p_filesz)) #define nh_size (fm->cls == ELFCLASS32 \ ? sizeof nh32 \ : sizeof nh64) @@ -244,7 +247,7 @@ dophn_core(fmagic fm, off_t off, int num, size_t size) error(EXIT_FAILURE, 0, "lseek failed (%s).\n", strerror(errno)); /*@notreached@*/ } - bufsize = read(fm->fd, nbuf, BUFSIZ); + bufsize = read(fm->fd, nbuf, ((ph_filesz < BUFSIZ) ? ph_filesz : BUFSIZ)); if (bufsize == -1) { error(EXIT_FAILURE, 0, ": " "read failed (%s).\n", strerror(errno)); /*@notreached@*/ @@ -290,7 +293,7 @@ donote(const fmagic fm, unsigned char *nbuf, size_t offset, size_t size, noff = offset; doff = ELF_ALIGN(offset + nh_namesz); - if (offset + nh_namesz >= size) { + if (offset + nh_namesz > size) { /* * We're past the end of the buffer. */ @@ -298,7 +301,7 @@ donote(const fmagic fm, unsigned char *nbuf, size_t offset, size_t size, } offset = ELF_ALIGN(doff + nh_descsz); - if (offset + nh_descsz >= size) + if (doff + nh_descsz > size) return offset; if (nh_namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 && @@ -601,7 +604,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size) error(EXIT_FAILURE, 0, "lseek failed (%s).\n", strerror(errno)); /*@notreached@*/ } - bufsize = read(fm->fd, nbuf, sizeof(nbuf)); + bufsize = read(fm->fd, nbuf, ((ph_filesz < sizeof(nbuf)) ? ph_filesz : sizeof(nbuf))); if (bufsize == -1) { error(EXIT_FAILURE, 0, ": " "read failed (%s).\n", strerror(errno)); @@ -614,7 +617,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size) offset = donote(fm, nbuf, offset, (size_t)bufsize, ph_align); } - if ((lseek(fm->fd, savedoffset + offset, SEEK_SET)) == (off_t)-1) { + if ((lseek(fm->fd, savedoffset, SEEK_SET)) == (off_t)-1) { error(EXIT_FAILURE, 0, "lseek failed (%s).\n", strerror(errno)); /*@notreached@*/ } |