The following reply was made to PR bin/175491; it has been noted by GNATS.

From: "Mikhail T." <mi+t...@aldan.algebra.com>
To: bug-follo...@freebsd.org, m...@aldan.algebra.com
Cc:  
Subject: Re: bin/175491: elf_getdata may return NULL without setting 
error-message
Date: Mon, 21 Jan 2013 17:23:27 -0500

 This is a multi-part message in MIME format.
 --------------090000090100000008010002
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 The test-program...
 
 --------------090000090100000008010002
 Content-Type: text/plain; charset=KOI8-U;
  name="libelftest.c"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="libelftest.c"
 
 #include <err.h>
 #include <fcntl.h>
 #include <libelf.h>
 #include <stdio.h>
 #include <sysexits.h>
 #include <unistd.h>
 
 int
 main(int argc, char *argv[])
 {
        int              fd;
        Elf             *elf;
        Elf_Scn         *scn;
        Elf_Data        *data;
        unsigned int     elfversion;
 
        elfversion = elf_version(EV_CURRENT);
        printf("elfversion returned %u\n", elfversion);
 
        fd = open(argv[argc-1], O_RDONLY);
        if (fd == -1)
                err(EX_NOINPUT, "%s", argv[argc-1]);
 
        elf = elf_begin(fd, ELF_C_READ, NULL);
        if (elf == NULL)
                errx(EX_DATAERR, "%s: %s: %s", argv[argc-1], "elf_begin",
                    elf_errmsg(elf_errno()));
 
        /*
         * Section 0:
         */
        scn = elf_getscn(elf, 0);
        if (scn == NULL)
                errx(EX_DATAERR, "%s: %s: %s", argv[argc-1], "elf_getscn",
                    elf_errmsg(elf_errno()));
        data = elf_getdata(scn, NULL);
        if (data == NULL)
                warnx("%s: %s: %s", argv[argc-1], "elf_getscn",
                    elf_errmsg(elf_errno()));
 
        /*
         * Enumerate through valid sections
         */
        for (scn = elf_nextscn(elf, NULL); scn; scn = elf_nextscn(elf, scn)) {
                data = elf_getdata(scn, NULL);
                if (data == NULL) {
                        int              errnum;
                        const char      *msg;
 
                        errnum = elf_errno();
                        msg = errnum ? elf_errmsg(errnum) : "errnum was zero";
                        if (errnum && msg)
                                printf("Section %zd has no data: %s\n",
                                    elf_ndxscn(scn), msg);
                        else
                                warnx("Section %zd: elf_getdata() return NULL "
                                    "without explanation", elf_ndxscn(scn));
                } else {
                        printf("Section %zd has data %p\n",
                            elf_ndxscn(scn), data);
                }
        }
        return EX_OK;
 }
 
 --------------090000090100000008010002--
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to