Deleted Added
full compact
elf_scn.c (210330) elf_scn.c (210338)
1/*-
2 * Copyright (c) 2006 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/lib/libelf/elf_scn.c 210330 2010-07-21 09:47:14Z kaiw $");
28__FBSDID("$FreeBSD: head/lib/libelf/elf_scn.c 210338 2010-07-21 10:25:02Z kaiw $");
29
30#include <assert.h>
31#include <errno.h>
32#include <gelf.h>
33#include <libelf.h>
34#include <stdlib.h>
35
36#include "_libelf.h"

--- 6 unchanged lines hidden (view full) ---

43{
44 int ec, swapbytes;
45 size_t fsz, i, shnum;
46 uint64_t shoff;
47 char *src;
48 Elf32_Ehdr *eh32;
49 Elf64_Ehdr *eh64;
50 Elf_Scn *scn;
29
30#include <assert.h>
31#include <errno.h>
32#include <gelf.h>
33#include <libelf.h>
34#include <stdlib.h>
35
36#include "_libelf.h"

--- 6 unchanged lines hidden (view full) ---

43{
44 int ec, swapbytes;
45 size_t fsz, i, shnum;
46 uint64_t shoff;
47 char *src;
48 Elf32_Ehdr *eh32;
49 Elf64_Ehdr *eh64;
50 Elf_Scn *scn;
51 void (*xlator)(char *_d, char *_s, size_t _c, int _swap);
51 int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
52
53 assert(e != NULL);
54 assert(ehdr != NULL);
55 assert((e->e_flags & LIBELF_F_SHDRS_LOADED) == 0);
56
57#define CHECK_EHDR(E,EH) do { \
58 if (fsz != (EH)->e_shentsize || \
59 shoff + fsz * shnum > e->e_rawsize) { \

--- 36 unchanged lines hidden (view full) ---

96 i = 1;
97 src += fsz;
98 }
99
100 for (; i < shnum; i++, src += fsz) {
101 if ((scn = _libelf_allocate_scn(e, i)) == NULL)
102 return (0);
103
52
53 assert(e != NULL);
54 assert(ehdr != NULL);
55 assert((e->e_flags & LIBELF_F_SHDRS_LOADED) == 0);
56
57#define CHECK_EHDR(E,EH) do { \
58 if (fsz != (EH)->e_shentsize || \
59 shoff + fsz * shnum > e->e_rawsize) { \

--- 36 unchanged lines hidden (view full) ---

96 i = 1;
97 src += fsz;
98 }
99
100 for (; i < shnum; i++, src += fsz) {
101 if ((scn = _libelf_allocate_scn(e, i)) == NULL)
102 return (0);
103
104 (*xlator)((char *) &scn->s_shdr, src, (size_t) 1, swapbytes);
104 (*xlator)((char *) &scn->s_shdr, sizeof(scn->s_shdr), src,
105 (size_t) 1, swapbytes);
105
106 if (ec == ELFCLASS32) {
107 scn->s_offset = scn->s_rawoff =
108 scn->s_shdr.s_shdr32.sh_offset;
109 scn->s_size = scn->s_shdr.s_shdr32.sh_size;
110 } else {
111 scn->s_offset = scn->s_rawoff =
112 scn->s_shdr.s_shdr64.sh_offset;

--- 116 unchanged lines hidden ---
106
107 if (ec == ELFCLASS32) {
108 scn->s_offset = scn->s_rawoff =
109 scn->s_shdr.s_shdr32.sh_offset;
110 scn->s_size = scn->s_shdr.s_shdr32.sh_size;
111 } else {
112 scn->s_offset = scn->s_rawoff =
113 scn->s_shdr.s_shdr64.sh_offset;

--- 116 unchanged lines hidden ---