summaryrefslogtreecommitdiffstats
path: root/libelf
diff options
context:
space:
mode:
Diffstat (limited to 'libelf')
-rw-r--r--libelf/ChangeLog31
-rw-r--r--libelf/elf32_updatefile.c9
-rw-r--r--libelf/elf_begin.c2
-rw-r--r--libelf/elf_compress.c9
-rw-r--r--libelf/elf_getarsym.c2
-rw-r--r--libelf/elf_update.c2
-rw-r--r--libelf/libelf.h38
-rw-r--r--libelf/libelfP.h4
8 files changed, 79 insertions, 18 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 8539cb56..594bec99 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,34 @@
+2017-04-20 Ulf Hermann <[email protected]>
+
+ * libelfP.h: Don't include config.h.
+
+2017-04-20 Ulf Hermann <[email protected]>
+
+ * elf_begin.c: Use F_GETFD rather than F_GETFL.
+
+2017-04-20 Ulf Hermann <[email protected]>
+
+ * libelf.h: Define macros for various function attributes and use
+ them.
+
+2017-04-20 Ulf Hermann <[email protected]>
+
+ * elf_update.c: Set ELF_F_MMAPPED flag if we mmap from elf_update.
+
+2017-04-19 Mark Wielaard <[email protected]>
+
+ * elf_getarsym.c (elf_getarsym): Initialize n to zero.
+
+2017-03-27 Mark Wielaard <[email protected]>
+
+ * elf32_updatefile.c (updatemmap): Always update last_positition.
+ (updatefile): Likewise.
+
+2017-03-24 Mark Wielaard <[email protected]>
+
+ * elf_compress.c (__libelf_decompress): Check insane compression
+ ratios before trying to allocate output buffer.
+
2016-10-11 Akihiko Odaki <[email protected]>
Mark Wielaard <[email protected]>
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 8dd85d1a..7ac99510 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -343,9 +343,10 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
{
fill_mmap (dl->data.d.d_off, last_position, scn_start,
shdr_start, shdr_end);
- last_position = scn_start + dl->data.d.d_off;
}
+ last_position = scn_start + dl->data.d.d_off;
+
if ((scn->flags | dl->flags | elf->flags) & ELF_F_DIRTY)
{
/* Let it go backward if the sections use a bogus
@@ -353,8 +354,6 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
user's section data with the latest one, rather than
crashing. */
- last_position = scn_start + dl->data.d.d_off;
-
if (unlikely (change_bo))
{
#if EV_NUM != 2
@@ -728,6 +727,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum)
}
}
+ last_offset = scn_start + dl->data.d.d_off;
+
if ((scn->flags | dl->flags | elf->flags) & ELF_F_DIRTY)
{
char tmpbuf[MAX_TMPBUF];
@@ -738,8 +739,6 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum)
user's section data with the latest one, rather than
crashing. */
- last_offset = scn_start + dl->data.d.d_off;
-
if (unlikely (change_bo))
{
#if EV_NUM != 2
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 5e9099c2..6f850382 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -1075,7 +1075,7 @@ elf_begin (int fildes, Elf_Cmd cmd, Elf *ref)
if (ref != NULL)
/* Make sure the descriptor is not suddenly going away. */
rwlock_rdlock (ref->lock);
- else if (unlikely (fcntl (fildes, F_GETFL) == -1 && errno == EBADF))
+ else if (unlikely (fcntl (fildes, F_GETFD) == -1 && errno == EBADF))
{
/* We cannot do anything productive without a file descriptor. */
__libelf_seterrno (ELF_E_INVALID_FILE);
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index dac0ac6d..711be591 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -211,6 +211,15 @@ void *
internal_function
__libelf_decompress (void *buf_in, size_t size_in, size_t size_out)
{
+ /* Catch highly unlikely compression ratios so we don't allocate
+ some giant amount of memory for nothing. The max compression
+ factor 1032:1 comes from http://www.zlib.net/zlib_tech.html */
+ if (unlikely (size_out / 1032 > size_in))
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ return NULL;
+ }
+
void *buf_out = malloc (size_out);
if (unlikely (buf_out == NULL))
{
diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c
index d5f0ba43..1f031fca 100644
--- a/libelf/elf_getarsym.c
+++ b/libelf/elf_getarsym.c
@@ -167,7 +167,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
/* We have an archive. The first word in there is the number of
entries in the table. */
- uint64_t n;
+ uint64_t n = 0;
size_t off = elf->start_offset + SARMAG + sizeof (struct ar_hdr);
if (read_number_entries (&n, elf, &off, index64_p) < 0)
{
diff --git a/libelf/elf_update.c b/libelf/elf_update.c
index c635eb32..8ce07829 100644
--- a/libelf/elf_update.c
+++ b/libelf/elf_update.c
@@ -74,6 +74,8 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
MAP_SHARED, elf->fildes, 0);
if (unlikely (elf->map_address == MAP_FAILED))
elf->map_address = NULL;
+ else
+ elf->flags |= ELF_F_MMAPPED;
}
if (elf->map_address != NULL)
diff --git a/libelf/libelf.h b/libelf/libelf.h
index c0d6389f..547c0f50 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -64,6 +64,30 @@
#define ELFCOMPRESS_HIPROC 0x7fffffff /* End of processor-specific. */
#endif
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+# define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__)))
+# define __deprecated_attribute__ __attribute__ ((__deprecated__))
+# define __pure_attribute__ __attribute__ ((__pure__))
+# define __const_attribute__ __attribute__ ((__const__))
+#else
+# define __nonnull_attribute__(...)
+# define __deprecated_attribute__
+# define __pure_attribute__
+# define __const_attribute__
+#endif
+
+#if __GNUC__ < 4
+#define __noreturn_attribute__
+#else
+#define __noreturn_attribute__ __attribute__ ((noreturn))
+#endif
+
+#ifdef __GNUC_STDC_INLINE__
+# define __libdw_extern_inline extern __inline __attribute__ ((__gnu_inline__))
+#else
+# define __libdw_extern_inline extern __inline
+#endif
+
/* Known translation types. */
typedef enum
{
@@ -216,7 +240,7 @@ extern int elf_end (Elf *__elf);
extern int64_t elf_update (Elf *__elf, Elf_Cmd __cmd);
/* Determine what kind of file is associated with ELF. */
-extern Elf_Kind elf_kind (Elf *__elf) __attribute__ ((__pure__));
+extern Elf_Kind elf_kind (Elf *__elf) __pure_attribute__;
/* Get the base offset for an object file. */
extern int64_t elf_getbase (Elf *__elf);
@@ -282,7 +306,7 @@ extern int elf_getshdrnum (Elf *__elf, size_t *__dst);
It was agreed to make the same functionality available under a different
name and obsolete the old name. */
extern int elf_getshnum (Elf *__elf, size_t *__dst)
- __attribute__ ((__deprecated__));
+ __deprecated_attribute__;
/* Get the section index of the section header string table in the ELF
@@ -294,7 +318,7 @@ extern int elf_getshdrstrndx (Elf *__elf, size_t *__dst);
It was agreed to make the same functionality available under a different
name and obsolete the old name. */
extern int elf_getshstrndx (Elf *__elf, size_t *__dst)
- __attribute__ ((__deprecated__));
+ __deprecated_attribute__;
/* Retrieve section header of ELFCLASS32 binary. */
@@ -429,11 +453,11 @@ extern char *elf_rawfile (Elf *__elf, size_t *__nbytes);
The result is based on version VERSION of the ELF standard. */
extern size_t elf32_fsize (Elf_Type __type, size_t __count,
unsigned int __version)
- __attribute__ ((__const__));
+ __const_attribute__;
/* Similar but this time the binary calls is ELFCLASS64. */
extern size_t elf64_fsize (Elf_Type __type, size_t __count,
unsigned int __version)
- __attribute__ ((__const__));
+ __const_attribute__;
/* Convert data structure from the representation in the file represented
@@ -472,11 +496,11 @@ extern void elf_fill (int __fill);
/* Compute hash value. */
extern unsigned long int elf_hash (const char *__string)
- __attribute__ ((__pure__));
+ __pure_attribute__;
/* Compute hash value using the GNU-specific hash function. */
extern unsigned long int elf_gnu_hash (const char *__string)
- __attribute__ ((__pure__));
+ __pure_attribute__;
/* Compute simple checksum from permanent parts of the ELF file. */
diff --git a/libelf/libelfP.h b/libelf/libelfP.h
index 44599827..7ee6625a 100644
--- a/libelf/libelfP.h
+++ b/libelf/libelfP.h
@@ -30,10 +30,6 @@
#ifndef _LIBELFP_H
#define _LIBELFP_H 1
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include <ar.h>
#include <gelf.h>