This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: elf_update bug


I can't figure out why my test program doesn't trigger the same bug.  
Take http://roland.fedorapeople.org/tmp/deadline-iosched.ko.bz2 and run:

/usr/lib/rpm/debugedit -b /home/roland/redhat/pkgs/kernel/devel/kernel-2.6.28 -d /usr/src/debug deadline-iosched.ko

This crashes with 0.138-1 (or point LD_LIBRARY_PATH=yourbuild/libelf,
using master).  It doesn't crash this test.

/* Copyright (C) 2009 Red Hat, Inc.
   This file is part of Red Hat elfutils.

   Red Hat elfutils is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by the
   Free Software Foundation; version 2 of the License.

   Red Hat elfutils is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with Red Hat elfutils; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.

   Red Hat elfutils is an included package of the Open Invention Network.
   An included package of the Open Invention Network is a package for which
   Open Invention Network licensees cross-license their patents.  No patent
   license is granted, either expressly or impliedly, by designation as an
   included package.  Should you wish to participate in the Open Invention
   Network licensing program, please visit www.openinventionnetwork.com
   <http://www.openinventionnetwork.com>.  */

#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <gelf.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

static void
handle_file (const char *file, Elf_Cmd cmd)
{
  int fd = open (file, O_RDWR);
  if (fd < 0)
    error (EXIT_FAILURE, errno, "cannot open input file '%s'", file);

  Elf *elf = elf_begin (fd, cmd, NULL);
  size_t shstrndx;
  if (elf_getshstrndx (elf, &shstrndx))
    error (EXIT_FAILURE, 0, "problems opening '%s' as ELF file: %s",
	   file, elf_errmsg (-1));

  elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT);

  Elf_Scn *scn = NULL;
  while ((scn = elf_nextscn (elf, scn)) != NULL)
    {
      GElf_Shdr shdr_mem;
      const char *name = elf_strptr (elf, shstrndx,
				     gelf_getshdr (scn, &shdr_mem)->sh_name);
      if (name != NULL && !strcmp (name, ".debug_str"))
	elf_flagdata (elf_rawdata (scn, NULL), ELF_C_SET, ELF_F_DIRTY);
    }

  if (elf_update (elf, ELF_C_NULL) == -1)
    error (EXIT_FAILURE, 0, "elf_update failed: %s", elf_errmsg (-1));

  if (elf_update (elf, ELF_C_WRITE) == -1)
    error (EXIT_FAILURE, 0, "elf_update failed: %s", elf_errmsg (-1));

  elf_end (elf);
  close (fd);
}

int
main (int argc, char *argv[])
{
  elf_version (EV_CURRENT);

  for (int i = 1; i < argc; ++i)
    {
      handle_file (argv[i], ELF_C_RDWR_MMAP);
      handle_file (argv[i], ELF_C_RDWR);
    }

  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]