aboutsummaryrefslogtreecommitdiff
path: root/lib/libelf/elf_begin.c
diff options
context:
space:
mode:
authorKai Wang <kaiw@FreeBSD.org>2010-07-21 13:18:57 +0000
committerKai Wang <kaiw@FreeBSD.org>2010-07-21 13:18:57 +0000
commit52d63629e67d6565c025f094517c00b2f6a0be05 (patch)
tree080829446f2819a0e730581f99aafca6d525bd05 /lib/libelf/elf_begin.c
parent101235dcb35258a8a305310463ac2974798d625e (diff)
downloadsrc-52d63629e67d6565c025f094517c00b2f6a0be05.tar.gz
src-52d63629e67d6565c025f094517c00b2f6a0be05.zip
* Note that ar(1) archives may also be opened using `elf_memory(3)`.
* Ignore the passed in value of the `fd` argument for ar(1) archives opened with elf_memory(3). Obtained from: elftoolchain MFC after: 1 month
Notes
Notes: svn path=/head/; revision=210351
Diffstat (limited to 'lib/libelf/elf_begin.c')
-rw-r--r--lib/libelf/elf_begin.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/libelf/elf_begin.c b/lib/libelf/elf_begin.c
index 7879dbefd31c..6e81e32ced6c 100644
--- a/lib/libelf/elf_begin.c
+++ b/lib/libelf/elf_begin.c
@@ -131,13 +131,15 @@ elf_begin(int fd, Elf_Cmd c, Elf *a)
case ELF_C_READ:
/*
* Descriptor `a' could be for a regular ELF file, or
- * for an ar(1) archive.
+ * for an ar(1) archive. If descriptor `a' was opened
+ * using a valid file descriptor, we need to check if
+ * the passed in `fd' value matches the original one.
*/
- if (a && (a->e_fd != fd || c != a->e_cmd)) {
+ if (a &&
+ ((a->e_fd != -1 && a->e_fd != fd) || c != a->e_cmd)) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return (NULL);
}
-
break;
default:
@@ -149,7 +151,7 @@ elf_begin(int fd, Elf_Cmd c, Elf *a)
if (a == NULL)
e = _libelf_open_object(fd, c);
else if (a->e_kind == ELF_K_AR)
- e = _libelf_ar_open_member(fd, c, a);
+ e = _libelf_ar_open_member(a->e_fd, c, a);
else
(e = a)->e_activations++;