Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/ldd rtld expects an absolute path in execname provid...
details: https://anonhg.NetBSD.org/src/rev/4d1fb071556d
branches: trunk
changeset: 1022500:4d1fb071556d
user: christos <christos%NetBSD.org@localhost>
date: Thu Jul 22 17:39:52 2021 +0000
description:
rtld expects an absolute path in execname provided via AUXV in order to
handle $ORIGIN properly and checks for that. Since we are calling its guts
directly, provide one.
diffstat:
usr.bin/ldd/ldd.c | 17 ++++++++++++-----
usr.bin/ldd/ldd.h | 6 +++---
usr.bin/ldd/ldd_elfxx.c | 8 ++++----
3 files changed, 19 insertions(+), 12 deletions(-)
diffs (120 lines):
diff -r 39589a87edcd -r 4d1fb071556d usr.bin/ldd/ldd.c
--- a/usr.bin/ldd/ldd.c Thu Jul 22 17:08:15 2021 +0000
+++ b/usr.bin/ldd/ldd.c Thu Jul 22 17:39:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldd.c,v 1.23 2017/12/25 05:08:49 maya Exp $ */
+/* $NetBSD: ldd.c,v 1.24 2021/07/22 17:39:52 christos Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ldd.c,v 1.23 2017/12/25 05:08:49 maya Exp $");
+__RCSID("$NetBSD: ldd.c,v 1.24 2021/07/22 17:39:52 christos Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -123,6 +123,7 @@
{
const char *fmt1 = NULL, *fmt2 = NULL;
int c, exit_status = EXIT_SUCCESS;
+ char cwd[MAXPATHLEN], path[MAXPATHLEN];
#ifdef DEBUG
debug = 1;
@@ -154,22 +155,28 @@
usage();
/*NOTREACHED*/
}
+ if (getcwd(cwd, sizeof(cwd)) == NULL)
+ err(EXIT_FAILURE, "Can't get working directory");
for (; argc != 0; argc--, argv++) {
int fd;
+ if (**argv != '/')
+ snprintf(path, sizeof(path), "%s/%s", cwd, *argv);
+ else
+ strlcpy(path, *argv, sizeof(path));
fd = open(*argv, O_RDONLY);
if (fd == -1) {
exit_status = EXIT_FAILURE;
warn("%s", *argv);
continue;
}
- if (elf_ldd(fd, *argv, fmt1, fmt2) == -1
+ if (elf_ldd(fd, *argv, path, fmt1, fmt2) == -1
/* Alpha never had 32 bit support. */
#if (defined(_LP64) && !defined(ELF64_ONLY)) || defined(MIPS_N32)
- && elf32_ldd(fd, *argv, fmt1, fmt2) == -1
+ && elf32_ldd(fd, *argv, path, fmt1, fmt2) == -1
#if defined(__mips__) && 0 /* XXX this is still hosed for some reason */
- && elf32_ldd_compat(fd, *argv, fmt1, fmt2) == -1
+ && elf32_ldd_compat(fd, *argv, path, fmt1, fmt2) == -1
#endif
#endif
) {
diff -r 39589a87edcd -r 4d1fb071556d usr.bin/ldd/ldd.h
--- a/usr.bin/ldd/ldd.h Thu Jul 22 17:08:15 2021 +0000
+++ b/usr.bin/ldd/ldd.h Thu Jul 22 17:39:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldd.h,v 1.7 2012/07/08 00:53:44 matt Exp $ */
+/* $NetBSD: ldd.h,v 1.8 2021/07/22 17:39:53 christos Exp $ */
/*
* Copyright (c) 2008 Matthew R. Green
@@ -28,14 +28,14 @@
* SUCH DAMAGE.
*/
-int elf32_ldd(int, char *, const char *, const char *);
+int elf32_ldd(int, char *, char *, const char *, const char *);
#ifdef _LP64
#define LDD_ELF64
#endif
#ifdef LDD_ELF64
-int elf64_ldd(int, char *, const char *, const char *);
+int elf64_ldd(int, char *, char *, const char *, const char *);
#define elf_ldd elf64_ldd
#elif defined(ELF32_COMPAT)
#define elf_ldd elf32_compat_ldd
diff -r 39589a87edcd -r 4d1fb071556d usr.bin/ldd/ldd_elfxx.c
--- a/usr.bin/ldd/ldd_elfxx.c Thu Jul 22 17:08:15 2021 +0000
+++ b/usr.bin/ldd/ldd_elfxx.c Thu Jul 22 17:39:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldd_elfxx.c,v 1.7 2017/01/10 21:11:25 christos Exp $ */
+/* $NetBSD: ldd_elfxx.c,v 1.8 2021/07/22 17:39:53 christos Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ldd_elfxx.c,v 1.7 2017/01/10 21:11:25 christos Exp $");
+__RCSID("$NetBSD: ldd_elfxx.c,v 1.8 2021/07/22 17:39:53 christos Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -93,7 +93,7 @@
* returns 0 on success and -1 on failure.
*/
int
-ELFNAME(ldd)(int fd, char *path, const char *fmt1, const char *fmt2)
+ELFNAME(ldd)(int fd, char *prog, char *path, const char *fmt1, const char *fmt2)
{
struct stat st;
@@ -132,7 +132,7 @@
(void) _rtld_load_needed_objects(_rtld_objmain, 0);
if (fmt1 == NULL)
- printf("%s:\n", _rtld_objmain->path);
+ printf("%s:\n", prog);
main_local = path;
main_progname = _rtld_objmain->path;
print_needed(_rtld_objmain, fmt1, fmt2);
Home |
Main Index |
Thread Index |
Old Index