Fri Jul 23 04:20:05 2021 UTC ()
gcc hates strncpy()


(martin)
diff -r1.24 -r1.25 src/usr.bin/ldd/ldd.c

cvs diff -r1.24 -r1.25 src/usr.bin/ldd/ldd.c (expand / switch to unified diff)

--- src/usr.bin/ldd/ldd.c 2021/07/22 17:39:52 1.24
+++ src/usr.bin/ldd/ldd.c 2021/07/23 04:20:05 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ldd.c,v 1.24 2021/07/22 17:39:52 christos Exp $ */ 1/* $NetBSD: ldd.c,v 1.25 2021/07/23 04:20:05 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg. 8 * by Paul Kranenburg.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64#ifndef lint 64#ifndef lint
65__RCSID("$NetBSD: ldd.c,v 1.24 2021/07/22 17:39:52 christos Exp $"); 65__RCSID("$NetBSD: ldd.c,v 1.25 2021/07/23 04:20:05 martin Exp $");
66#endif /* not lint */ 66#endif /* not lint */
67 67
68#include <sys/types.h> 68#include <sys/types.h>
69#include <sys/mman.h> 69#include <sys/mman.h>
70#include <sys/wait.h> 70#include <sys/wait.h>
71 71
72#include <dirent.h> 72#include <dirent.h>
73#include <err.h> 73#include <err.h>
74#include <errno.h> 74#include <errno.h>
75#include <fcntl.h> 75#include <fcntl.h>
76#include <stdarg.h> 76#include <stdarg.h>
77#include <stdio.h> 77#include <stdio.h>
78#include <stdlib.h> 78#include <stdlib.h>
@@ -151,30 +151,33 @@ main(int argc, char **argv) @@ -151,30 +151,33 @@ main(int argc, char **argv)
151 argc -= optind; 151 argc -= optind;
152 argv += optind; 152 argv += optind;
153 153
154 if (argc <= 0) { 154 if (argc <= 0) {
155 usage(); 155 usage();
156 /*NOTREACHED*/ 156 /*NOTREACHED*/
157 } 157 }
158 if (getcwd(cwd, sizeof(cwd)) == NULL) 158 if (getcwd(cwd, sizeof(cwd)) == NULL)
159 err(EXIT_FAILURE, "Can't get working directory"); 159 err(EXIT_FAILURE, "Can't get working directory");
160 160
161 for (; argc != 0; argc--, argv++) { 161 for (; argc != 0; argc--, argv++) {
162 int fd; 162 int fd;
163 163
164 if (**argv != '/') 164 if (**argv != '/') {
165 snprintf(path, sizeof(path), "%s/%s", cwd, *argv); 165 strcpy(path, cwd);
166 else 166 strlcat(path, "/", sizeof(path));
 167 strlcat(path, *argv, sizeof(path));
 168 } else {
167 strlcpy(path, *argv, sizeof(path)); 169 strlcpy(path, *argv, sizeof(path));
 170 }
168 fd = open(*argv, O_RDONLY); 171 fd = open(*argv, O_RDONLY);
169 if (fd == -1) { 172 if (fd == -1) {
170 exit_status = EXIT_FAILURE; 173 exit_status = EXIT_FAILURE;
171 warn("%s", *argv); 174 warn("%s", *argv);
172 continue; 175 continue;
173 } 176 }
174 if (elf_ldd(fd, *argv, path, fmt1, fmt2) == -1 177 if (elf_ldd(fd, *argv, path, fmt1, fmt2) == -1
175 /* Alpha never had 32 bit support. */ 178 /* Alpha never had 32 bit support. */
176#if (defined(_LP64) && !defined(ELF64_ONLY)) || defined(MIPS_N32) 179#if (defined(_LP64) && !defined(ELF64_ONLY)) || defined(MIPS_N32)
177 && elf32_ldd(fd, *argv, path, fmt1, fmt2) == -1 180 && elf32_ldd(fd, *argv, path, fmt1, fmt2) == -1
178#if defined(__mips__) && 0 /* XXX this is still hosed for some reason */ 181#if defined(__mips__) && 0 /* XXX this is still hosed for some reason */
179 && elf32_ldd_compat(fd, *argv, path, fmt1, fmt2) == -1 182 && elf32_ldd_compat(fd, *argv, path, fmt1, fmt2) == -1
180#endif 183#endif