- file: read elf64 notes correctly.
authorjbj <devnull@localhost>
Tue, 7 Jan 2003 23:13:52 +0000 (23:13 +0000)
committerjbj <devnull@localhost>
Tue, 7 Jan 2003 23:13:52 +0000 (23:13 +0000)
CVS patchset: 6000
CVS date: 2003/01/07 23:13:52

CHANGES
file/readelf.c
rpm.spec.in

diff --git a/CHANGES b/CHANGES
index b96897f..1089da8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
        - portabilitly: solaris fixes.
        - for DSO's, provide the file basename if DT_SONAME not found.
        - add perldeps.pl, start to replace perl.{prov,req}.
+       - file: read elf64 notes correctly.
 
 4.0.4 -> 4.1:
        - loosely wire beecrypt library into rpm.
index 9c728ca..9dd688d 100644 (file)
@@ -92,6 +92,9 @@ getu64(const fmagic fm, uint64_t value)
 #define ph_offset      (fm->cls == ELFCLASS32          \
                         ? getu32(fm, ph32.p_offset)    \
                         : getu64(fm, ph64.p_offset))
+#define ph_align       (fm->cls == ELFCLASS32          \
+                        ? getu32(fm, ph32.p_align)     \
+                        : getu64(fm, ph64.p_align))
 #define nh_size                (fm->cls == ELFCLASS32          \
                         ? sizeof *nh32                 \
                         : sizeof *nh64)
@@ -153,6 +156,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
        char nbuf[BUFSIZ];
        int bufsize;
        size_t offset, nameoffset;
+       off_t savedoffset;
 
        if (lseek(fm->fd, off, SEEK_SET) == -1) {
                error(EXIT_FAILURE, 0, "lseek failed (%s).\n", strerror(errno));
@@ -164,6 +168,10 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                        error(EXIT_FAILURE, 0, "read failed (%s).\n", strerror(errno));
                        /*@notreached@*/
                }
+               if ((savedoffset = lseek(fm->fd, 0, SEEK_CUR)) == -1) {
+                       error(EXIT_FAILURE, 0, "lseek failed (%s).\n", strerror(errno));
+                       /*@notreached@*/
+               }
 
                switch (ph_type) {
                case PT_DYNAMIC:
@@ -181,7 +189,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, BUFSIZ);
+                       bufsize = read(fm->fd, nbuf, sizeof(nbuf));
                        if (bufsize == -1) {
                                error(EXIT_FAILURE, 0, ": " "read failed (%s).\n",
                                    strerror(errno));
@@ -206,7 +214,14 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
 
                                nameoffset = offset;
                                offset += nh_namesz;
-                               offset = ((offset + 3)/4)*4;
+                               offset = ((offset+ph_align-1)/ph_align)*ph_align;
+
+                               if ((nh_namesz == 0) && (nh_descsz == 0)) {
+                                       /*
+                                        * We're out of note headers.
+                                        */
+                                       break;
+                               }
 
                                if (offset + nh_descsz >= bufsize)
                                        /*@innerbreak@*/ break;
@@ -282,6 +297,10 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                                        /* Content of note is always 0 */
                                }
                        }
+                       if ((lseek(fm->fd, savedoffset + offset, SEEK_SET)) == -1) {
+                           error(EXIT_FAILURE, 0, "lseek failed (%s).\n", strerror(errno));
+                           /*@notreached@*/
+                       }
                        /*@switchbreak@*/ break;
                }
        }
index fdd82f1..23620c6 100644 (file)
@@ -15,7 +15,7 @@ Name: rpm
 %define version @VERSION@
 Version: %{version}
 %{expand: %%define rpm_version %{version}}
-Release: 0.52
+Release: 0.53
 Group: System Environment/Base
 Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/rpm-%{rpm_version}.tar.gz
 Copyright: GPL
@@ -460,6 +460,9 @@ exit 0
 %{__prefix}/include/popt.h
 
 %changelog
+* Tue Jan  7 2003 Jeff Johnson <jbj@redhat.com> 4.2-0.53
+- file: read elf64 notes correctly.
+
 * Mon Jan  6 2003 Jeff Johnson <jbj@redhat.com> 4.2-0.52
 - portabilitly: solaris fixes.
 - for DSO's, provide the file basename if DT_SONAME not found.