convert explicit length check before unchecked snprintf() with just a overflow checked snprintf(). for res_debug.c and res_query.c, convert from sprintf() to snprintf(). tested scp and rcp fail properly with too-long paths. tested getaddrinfo fails as expected for too-long domains. tested dig and ping for similar (res_debug.c/res_query.c). created a temporary fs with quotas to test edquota with a long EDITOR. did not test ypserv directly, but it's the same pattern. avoids GCC 12 snprintf() warnings, and reduces total code size.diff -r1.52 -r1.53 src/bin/rcp/rcp.c
(mrg)
--- src/bin/rcp/rcp.c 2022/07/18 13:01:59 1.52
+++ src/bin/rcp/rcp.c 2023/08/01 08:47:24 1.53
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rcp.c,v 1.52 2022/07/18 13:01:59 rin Exp $ */ | 1 | /* $NetBSD: rcp.c,v 1.53 2023/08/01 08:47:24 mrg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1983, 1990, 1992, 1993 | 4 | * Copyright (c) 1983, 1990, 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -29,27 +29,27 @@ | @@ -29,27 +29,27 @@ | |||
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | __COPYRIGHT("@(#) Copyright (c) 1983, 1990, 1992, 1993\ | 34 | __COPYRIGHT("@(#) Copyright (c) 1983, 1990, 1992, 1993\ | |
35 | The Regents of the University of California. All rights reserved."); | 35 | The Regents of the University of California. All rights reserved."); | |
36 | #endif /* not lint */ | 36 | #endif /* not lint */ | |
37 | 37 | |||
38 | #ifndef lint | 38 | #ifndef lint | |
39 | #if 0 | 39 | #if 0 | |
40 | static char sccsid[] = "@(#)rcp.c 8.2 (Berkeley) 4/2/94"; | 40 | static char sccsid[] = "@(#)rcp.c 8.2 (Berkeley) 4/2/94"; | |
41 | #else | 41 | #else | |
42 | __RCSID("$NetBSD: rcp.c,v 1.52 2022/07/18 13:01:59 rin Exp $"); | 42 | __RCSID("$NetBSD: rcp.c,v 1.53 2023/08/01 08:47:24 mrg Exp $"); | |
43 | #endif | 43 | #endif | |
44 | #endif /* not lint */ | 44 | #endif /* not lint */ | |
45 | 45 | |||
46 | #include <sys/param.h> | 46 | #include <sys/param.h> | |
47 | #include <sys/stat.h> | 47 | #include <sys/stat.h> | |
48 | #include <sys/time.h> | 48 | #include <sys/time.h> | |
49 | #include <sys/socket.h> | 49 | #include <sys/socket.h> | |
50 | #include <netinet/in.h> | 50 | #include <netinet/in.h> | |
51 | #include <netinet/in_systm.h> | 51 | #include <netinet/in_systm.h> | |
52 | #include <netinet/ip.h> | 52 | #include <netinet/ip.h> | |
53 | 53 | |||
54 | #include <ctype.h> | 54 | #include <ctype.h> | |
55 | #include <dirent.h> | 55 | #include <dirent.h> | |
@@ -456,31 +456,31 @@ rsource(char *name, struct stat *statp) | @@ -456,31 +456,31 @@ rsource(char *name, struct stat *statp) | |||
456 | } | 456 | } | |
457 | (void)snprintf(path, sizeof(path), | 457 | (void)snprintf(path, sizeof(path), | |
458 | "D%04o %d %s\n", statp->st_mode & RCPMODEMASK, 0, last); | 458 | "D%04o %d %s\n", statp->st_mode & RCPMODEMASK, 0, last); | |
459 | (void)write(rem, path, strlen(path)); | 459 | (void)write(rem, path, strlen(path)); | |
460 | if (response() < 0) { | 460 | if (response() < 0) { | |
461 | (void)closedir(dirp); | 461 | (void)closedir(dirp); | |
462 | return; | 462 | return; | |
463 | } | 463 | } | |
464 | while ((dp = readdir(dirp)) != NULL) { | 464 | while ((dp = readdir(dirp)) != NULL) { | |
465 | if (dp->d_ino == 0) | 465 | if (dp->d_ino == 0) | |
466 | continue; | 466 | continue; | |
467 | if (!strcmp(dp->d_name, dot) || !strcmp(dp->d_name, "..")) | 467 | if (!strcmp(dp->d_name, dot) || !strcmp(dp->d_name, "..")) | |
468 | continue; | 468 | continue; | |
469 | if (strlen(name) + 1 + strlen(dp->d_name) >= MAXPATHLEN - 1) { | 469 | if (snprintf(path, sizeof(path), "%s/%s", name, dp->d_name) >= | |
470 | sizeof(path)) { | |||
470 | run_err("%s/%s: name too long", name, dp->d_name); | 471 | run_err("%s/%s: name too long", name, dp->d_name); | |
471 | continue; | 472 | continue; | |
472 | } | 473 | } | |
473 | (void)snprintf(path, sizeof(path), "%s/%s", name, dp->d_name); | |||
474 | vect[0] = path; | 474 | vect[0] = path; | |
475 | source(1, vect); | 475 | source(1, vect); | |
476 | } | 476 | } | |
477 | (void)closedir(dirp); | 477 | (void)closedir(dirp); | |
478 | (void)write(rem, "E\n", 2); | 478 | (void)write(rem, "E\n", 2); | |
479 | (void)response(); | 479 | (void)response(); | |
480 | } | 480 | } | |
481 | 481 | |||
482 | void | 482 | void | |
483 | sink(int argc, char *argv[]) | 483 | sink(int argc, char *argv[]) | |
484 | { | 484 | { | |
485 | static BUF buffer; | 485 | static BUF buffer; | |
486 | struct stat stb; | 486 | struct stat stb; |
--- src/crypto/external/bsd/openssh/dist/scp.c 2023/07/28 04:40:54 1.38
+++ src/crypto/external/bsd/openssh/dist/scp.c 2023/08/01 08:47:25 1.39
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: scp.c,v 1.38 2023/07/28 04:40:54 rin Exp $ */ | 1 | /* $NetBSD: scp.c,v 1.39 2023/08/01 08:47:25 mrg Exp $ */ | |
2 | /* $OpenBSD: scp.c,v 1.253 2023/03/03 03:12:24 dtucker Exp $ */ | 2 | /* $OpenBSD: scp.c,v 1.253 2023/03/03 03:12:24 dtucker Exp $ */ | |
3 | /* | 3 | /* | |
4 | * scp - secure remote copy. This is basically patched BSD rcp which | 4 | * scp - secure remote copy. This is basically patched BSD rcp which | |
5 | * uses ssh to do the data transfer (instead of using rcmd). | 5 | * uses ssh to do the data transfer (instead of using rcmd). | |
6 | * | 6 | * | |
7 | * NOTE: This version should NOT be suid root. (This uses ssh to | 7 | * NOTE: This version should NOT be suid root. (This uses ssh to | |
8 | * do the transfer and ssh has the necessary privileges.) | 8 | * do the transfer and ssh has the necessary privileges.) | |
9 | * | 9 | * | |
10 | * 1995 Timo Rinne <tri@iki.fi>, Tatu Ylonen <ylo@cs.hut.fi> | 10 | * 1995 Timo Rinne <tri@iki.fi>, Tatu Ylonen <ylo@cs.hut.fi> | |
11 | * | 11 | * | |
12 | * As far as I am concerned, the code I have written for this software | 12 | * As far as I am concerned, the code I have written for this software | |
13 | * can be used freely for any purpose. Any derived versions of this | 13 | * can be used freely for any purpose. Any derived versions of this | |
14 | * software must be clearly marked as such, and if the derived work is | 14 | * software must be clearly marked as such, and if the derived work is | |
@@ -63,27 +63,27 @@ | @@ -63,27 +63,27 @@ | |||
63 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 63 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
64 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 64 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
65 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 65 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
66 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 66 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
67 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 67 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
68 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 68 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
69 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 69 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
70 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 70 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
71 | * SUCH DAMAGE. | 71 | * SUCH DAMAGE. | |
72 | * | 72 | * | |
73 | */ | 73 | */ | |
74 | 74 | |||
75 | #include "includes.h" | 75 | #include "includes.h" | |
76 | __RCSID("$NetBSD: scp.c,v 1.38 2023/07/28 04:40:54 rin Exp $"); | 76 | __RCSID("$NetBSD: scp.c,v 1.39 2023/08/01 08:47:25 mrg Exp $"); | |
77 | 77 | |||
78 | #include <sys/param.h> /* roundup MAX */ | 78 | #include <sys/param.h> /* roundup MAX */ | |
79 | #include <sys/types.h> | 79 | #include <sys/types.h> | |
80 | #include <sys/poll.h> | 80 | #include <sys/poll.h> | |
81 | #include <sys/wait.h> | 81 | #include <sys/wait.h> | |
82 | #include <sys/stat.h> | 82 | #include <sys/stat.h> | |
83 | #include <sys/time.h> | 83 | #include <sys/time.h> | |
84 | #include <sys/uio.h> | 84 | #include <sys/uio.h> | |
85 | 85 | |||
86 | #include <ctype.h> | 86 | #include <ctype.h> | |
87 | #include <dirent.h> | 87 | #include <dirent.h> | |
88 | #include <errno.h> | 88 | #include <errno.h> | |
89 | #include <fcntl.h> | 89 | #include <fcntl.h> | |
@@ -1466,31 +1466,31 @@ rsource(char *name, struct stat *statp) | @@ -1466,31 +1466,31 @@ rsource(char *name, struct stat *statp) | |||
1466 | (u_int) (statp->st_mode & FILEMODEMASK), 0, last); | 1466 | (u_int) (statp->st_mode & FILEMODEMASK), 0, last); | |
1467 | if (verbose_mode) | 1467 | if (verbose_mode) | |
1468 | fmprintf(stderr, "Entering directory: %s", path); | 1468 | fmprintf(stderr, "Entering directory: %s", path); | |
1469 | (void) atomicio(vwrite, remout, path, strlen(path)); | 1469 | (void) atomicio(vwrite, remout, path, strlen(path)); | |
1470 | if (response() < 0) { | 1470 | if (response() < 0) { | |
1471 | closedir(dirp); | 1471 | closedir(dirp); | |
1472 | return; | 1472 | return; | |
1473 | } | 1473 | } | |
1474 | while ((dp = readdir(dirp)) != NULL) { | 1474 | while ((dp = readdir(dirp)) != NULL) { | |
1475 | if (dp->d_ino == 0) | 1475 | if (dp->d_ino == 0) | |
1476 | continue; | 1476 | continue; | |
1477 | if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) | 1477 | if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) | |
1478 | continue; | 1478 | continue; | |
1479 | if (strlen(name) + 1 + strlen(dp->d_name) >= sizeof(path) - 1) { | 1479 | if ((size_t)snprintf(path, sizeof path, "%s/%s", | |
1480 | name, dp->d_name) >= sizeof path) { | |||
1480 | run_err("%s/%s: name too long", name, dp->d_name); | 1481 | run_err("%s/%s: name too long", name, dp->d_name); | |
1481 | continue; | 1482 | continue; | |
1482 | } | 1483 | } | |
1483 | (void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name); | |||
1484 | vect[0] = path; | 1484 | vect[0] = path; | |
1485 | source(1, vect); | 1485 | source(1, vect); | |
1486 | } | 1486 | } | |
1487 | (void) closedir(dirp); | 1487 | (void) closedir(dirp); | |
1488 | (void) atomicio(vwrite, remout, __UNCONST("E\n"), 2); | 1488 | (void) atomicio(vwrite, remout, __UNCONST("E\n"), 2); | |
1489 | (void) response(); | 1489 | (void) response(); | |
1490 | } | 1490 | } | |
1491 | 1491 | |||
1492 | void | 1492 | void | |
1493 | sink_sftp(int argc, char *dst, const char *src, struct sftp_conn *conn) | 1493 | sink_sftp(int argc, char *dst, const char *src, struct sftp_conn *conn) | |
1494 | { | 1494 | { | |
1495 | char *abs_src = NULL; | 1495 | char *abs_src = NULL; | |
1496 | char *abs_dst = NULL; | 1496 | char *abs_dst = NULL; |
--- src/lib/libc/net/getaddrinfo.c 2022/04/19 20:32:15 1.123
+++ src/lib/libc/net/getaddrinfo.c 2023/08/01 08:47:25 1.124
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: getaddrinfo.c,v 1.123 2022/04/19 20:32:15 rillig Exp $ */ | 1 | /* $NetBSD: getaddrinfo.c,v 1.124 2023/08/01 08:47:25 mrg Exp $ */ | |
2 | /* $KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -45,27 +45,27 @@ | @@ -45,27 +45,27 @@ | |||
45 | * Note: | 45 | * Note: | |
46 | * - The code filters out AFs that are not supported by the kernel, | 46 | * - The code filters out AFs that are not supported by the kernel, | |
47 | * when globbing NULL hostname (to loopback, or wildcard). Is it the right | 47 | * when globbing NULL hostname (to loopback, or wildcard). Is it the right | |
48 | * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG | 48 | * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG | |
49 | * in ai_flags? | 49 | * in ai_flags? | |
50 | * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. | 50 | * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. | |
51 | * (1) what should we do against numeric hostname (2) what should we do | 51 | * (1) what should we do against numeric hostname (2) what should we do | |
52 | * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? | 52 | * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? | |
53 | * non-loopback address configured? global address configured? | 53 | * non-loopback address configured? global address configured? | |
54 | */ | 54 | */ | |
55 | 55 | |||
56 | #include <sys/cdefs.h> | 56 | #include <sys/cdefs.h> | |
57 | #if defined(LIBC_SCCS) && !defined(lint) | 57 | #if defined(LIBC_SCCS) && !defined(lint) | |
58 | __RCSID("$NetBSD: getaddrinfo.c,v 1.123 2022/04/19 20:32:15 rillig Exp $"); | 58 | __RCSID("$NetBSD: getaddrinfo.c,v 1.124 2023/08/01 08:47:25 mrg Exp $"); | |
59 | #endif /* LIBC_SCCS and not lint */ | 59 | #endif /* LIBC_SCCS and not lint */ | |
60 | 60 | |||
61 | #ifndef RUMP_ACTION | 61 | #ifndef RUMP_ACTION | |
62 | #include "namespace.h" | 62 | #include "namespace.h" | |
63 | #endif | 63 | #endif | |
64 | #include <sys/types.h> | 64 | #include <sys/types.h> | |
65 | #include <sys/param.h> | 65 | #include <sys/param.h> | |
66 | #include <sys/socket.h> | 66 | #include <sys/socket.h> | |
67 | #include <sys/ioctl.h> | 67 | #include <sys/ioctl.h> | |
68 | #include <sys/sysctl.h> | 68 | #include <sys/sysctl.h> | |
69 | #include <net/if.h> | 69 | #include <net/if.h> | |
70 | #include <netinet/in.h> | 70 | #include <netinet/in.h> | |
71 | #include <netinet6/in6_var.h> | 71 | #include <netinet6/in6_var.h> | |
@@ -2810,59 +2810,56 @@ res_searchN(const char *name, struct res | @@ -2810,59 +2810,56 @@ res_searchN(const char *name, struct res | |||
2810 | return -1; | 2810 | return -1; | |
2811 | } | 2811 | } | |
2812 | 2812 | |||
2813 | /* | 2813 | /* | |
2814 | * Perform a call on res_query on the concatenation of name and domain, | 2814 | * Perform a call on res_query on the concatenation of name and domain, | |
2815 | * removing a trailing dot from name if domain is NULL. | 2815 | * removing a trailing dot from name if domain is NULL. | |
2816 | */ | 2816 | */ | |
2817 | static int | 2817 | static int | |
2818 | res_querydomainN(const char *name, const char *domain, | 2818 | res_querydomainN(const char *name, const char *domain, | |
2819 | struct res_target *target, res_state res) | 2819 | struct res_target *target, res_state res) | |
2820 | { | 2820 | { | |
2821 | char nbuf[MAXDNAME]; | 2821 | char nbuf[MAXDNAME]; | |
2822 | const char *longname = nbuf; | 2822 | const char *longname = nbuf; | |
2823 | size_t n, d; | 2823 | size_t n; | |
2824 | 2824 | |||
2825 | _DIAGASSERT(name != NULL); | 2825 | _DIAGASSERT(name != NULL); | |
2826 | /* XXX: target may be NULL??? */ | 2826 | /* XXX: target may be NULL??? */ | |
2827 | 2827 | |||
2828 | #ifdef DEBUG | 2828 | #ifdef DEBUG | |
2829 | if (res->options & RES_DEBUG) | 2829 | if (res->options & RES_DEBUG) | |
2830 | printf(";; res_querydomain(%s, %s)\n", | 2830 | printf(";; res_querydomain(%s, %s)\n", | |
2831 | name, domain?domain:"<Nil>"); | 2831 | name, domain?domain:"<Nil>"); | |
2832 | #endif | 2832 | #endif | |
2833 | if (domain == NULL) { | 2833 | if (domain == NULL) { | |
2834 | /* | 2834 | /* | |
2835 | * Check for trailing '.'; | 2835 | * Check for trailing '.'; | |
2836 | * copy without '.' if present. | 2836 | * copy without '.' if present. | |
2837 | */ | 2837 | */ | |
2838 | n = strlen(name); | 2838 | n = strlen(name); | |
2839 | if (n + 1 > sizeof(nbuf)) { | 2839 | if (n + 1 > sizeof(nbuf)) { | |
2840 | h_errno = NO_RECOVERY; | 2840 | h_errno = NO_RECOVERY; | |
2841 | return -1; | 2841 | return -1; | |
2842 | } | 2842 | } | |
2843 | if (n > 0 && name[--n] == '.') { | 2843 | if (n > 0 && name[--n] == '.') { | |
2844 | strncpy(nbuf, name, n); | 2844 | snprintf(nbuf, sizeof(nbuf), "%*s", (int)n, name); | |
2845 | nbuf[n] = '\0'; | |||
2846 | } else | 2845 | } else | |
2847 | longname = name; | 2846 | longname = name; | |
2848 | } else { | 2847 | } else { | |
2849 | n = strlen(name); | 2848 | if ((size_t)snprintf(nbuf, sizeof(nbuf), "%s.%s", | |
2850 | d = strlen(domain); | 2849 | name, domain) >= sizeof(nbuf)) { | |
2851 | if (n + 1 + d + 1 > sizeof(nbuf)) { | |||
2852 | h_errno = NO_RECOVERY; | 2850 | h_errno = NO_RECOVERY; | |
2853 | return -1; | 2851 | return -1; | |
2854 | } | 2852 | } | |
2855 | snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain); | |||
2856 | } | 2853 | } | |
2857 | return res_queryN(longname, target, res); | 2854 | return res_queryN(longname, target, res); | |
2858 | } | 2855 | } | |
2859 | 2856 | |||
2860 | #ifdef TEST | 2857 | #ifdef TEST | |
2861 | int | 2858 | int | |
2862 | main(int argc, char *argv[]) { | 2859 | main(int argc, char *argv[]) { | |
2863 | struct addrinfo *ai, *sai; | 2860 | struct addrinfo *ai, *sai; | |
2864 | int i, e; | 2861 | int i, e; | |
2865 | char buf[1024]; | 2862 | char buf[1024]; | |
2866 | 2863 | |||
2867 | for (i = 1; i < argc; i++) { | 2864 | for (i = 1; i < argc; i++) { | |
2868 | if ((e = getaddrinfo(argv[i], NULL, NULL, &sai)) != 0) | 2865 | if ((e = getaddrinfo(argv[i], NULL, NULL, &sai)) != 0) |
--- src/lib/libc/resolv/res_debug.c 2021/09/16 20:17:46 1.16
+++ src/lib/libc/resolv/res_debug.c 2023/08/01 08:47:25 1.17
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: res_debug.c,v 1.16 2021/09/16 20:17:46 andvar Exp $ */ | 1 | /* $NetBSD: res_debug.c,v 1.17 2023/08/01 08:47:25 mrg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") | 4 | * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") | |
5 | * Portions Copyright (C) 1996-2003 Internet Software Consortium. | 5 | * Portions Copyright (C) 1996-2003 Internet Software Consortium. | |
6 | * | 6 | * | |
7 | * Permission to use, copy, modify, and/or distribute this software for any | 7 | * Permission to use, copy, modify, and/or distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | 8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice appear in all copies. | 9 | * copyright notice and this permission notice appear in all copies. | |
10 | * | 10 | * | |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH | |
12 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | 12 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
13 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, | 13 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, | |
14 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | 14 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
@@ -87,27 +87,27 @@ | @@ -87,27 +87,27 @@ | |||
87 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | 87 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
88 | * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | 88 | * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | |
89 | * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | 89 | * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | |
90 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | 90 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | |
91 | * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | 91 | * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
92 | */ | 92 | */ | |
93 | 93 | |||
94 | #include <sys/cdefs.h> | 94 | #include <sys/cdefs.h> | |
95 | #if defined(LIBC_SCCS) && !defined(lint) | 95 | #if defined(LIBC_SCCS) && !defined(lint) | |
96 | #ifdef notdef | 96 | #ifdef notdef | |
97 | static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; | 97 | static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; | |
98 | static const char rcsid[] = "Id: res_debug.c,v 1.19 2009/02/26 11:20:20 tbox Exp"; | 98 | static const char rcsid[] = "Id: res_debug.c,v 1.19 2009/02/26 11:20:20 tbox Exp"; | |
99 | #else | 99 | #else | |
100 | __RCSID("$NetBSD: res_debug.c,v 1.16 2021/09/16 20:17:46 andvar Exp $"); | 100 | __RCSID("$NetBSD: res_debug.c,v 1.17 2023/08/01 08:47:25 mrg Exp $"); | |
101 | #endif | 101 | #endif | |
102 | #endif /* LIBC_SCCS and not lint */ | 102 | #endif /* LIBC_SCCS and not lint */ | |
103 | 103 | |||
104 | #include "port_before.h" | 104 | #include "port_before.h" | |
105 | 105 | |||
106 | #include "namespace.h" | 106 | #include "namespace.h" | |
107 | #include <sys/types.h> | 107 | #include <sys/types.h> | |
108 | #include <sys/param.h> | 108 | #include <sys/param.h> | |
109 | #include <sys/socket.h> | 109 | #include <sys/socket.h> | |
110 | 110 | |||
111 | #include <netinet/in.h> | 111 | #include <netinet/in.h> | |
112 | #include <arpa/inet.h> | 112 | #include <arpa/inet.h> | |
113 | #include <arpa/nameser.h> | 113 | #include <arpa/nameser.h> | |
@@ -1173,29 +1173,33 @@ p_secstodate (u_long secs) { | @@ -1173,29 +1173,33 @@ p_secstodate (u_long secs) { | |||
1173 | /* XXX nonreentrant */ | 1173 | /* XXX nonreentrant */ | |
1174 | char *output = p_secstodate_output; | 1174 | char *output = p_secstodate_output; | |
1175 | time_t myclock = secs; | 1175 | time_t myclock = secs; | |
1176 | struct tm *mytime; | 1176 | struct tm *mytime; | |
1177 | #ifdef HAVE_TIME_R | 1177 | #ifdef HAVE_TIME_R | |
1178 | struct tm res; | 1178 | struct tm res; | |
1179 | 1179 | |||
1180 | mytime = gmtime_r(&myclock, &res); | 1180 | mytime = gmtime_r(&myclock, &res); | |
1181 | #else | 1181 | #else | |
1182 | mytime = gmtime(&myclock); | 1182 | mytime = gmtime(&myclock); | |
1183 | #endif | 1183 | #endif | |
1184 | mytime->tm_year += 1900; | 1184 | mytime->tm_year += 1900; | |
1185 | mytime->tm_mon += 1; | 1185 | mytime->tm_mon += 1; | |
1186 | sprintf(output, "%04d%02d%02d%02d%02d%02d", | 1186 | if ((size_t)snprintf(output, sizeof p_secstodate_output, | |
1187 | mytime->tm_year, mytime->tm_mon, mytime->tm_mday, | 1187 | "%04d%02d%02d%02d%02d%02d", | |
1188 | mytime->tm_hour, mytime->tm_min, mytime->tm_sec); | 1188 | mytime->tm_year, mytime->tm_mon, mytime->tm_mday, | |
1189 | mytime->tm_hour, mytime->tm_min, mytime->tm_sec) > | |||
1190 | sizeof p_secstodate_output) { | |||
1191 | output[sizeof(p_secstodate_output) - 1] = 0; | |||
1192 | } | |||
1189 | return (output); | 1193 | return (output); | |
1190 | } | 1194 | } | |
1191 | 1195 | |||
1192 | u_int16_t | 1196 | u_int16_t | |
1193 | res_nametoclass(const char *buf, int *successp) { | 1197 | res_nametoclass(const char *buf, int *successp) { | |
1194 | unsigned long result; | 1198 | unsigned long result; | |
1195 | char *endptr; | 1199 | char *endptr; | |
1196 | int success; | 1200 | int success; | |
1197 | 1201 | |||
1198 | result = sym_ston(__p_class_syms, buf, &success); | 1202 | result = sym_ston(__p_class_syms, buf, &success); | |
1199 | if (success) | 1203 | if (success) | |
1200 | goto done; | 1204 | goto done; | |
1201 | 1205 |
--- src/lib/libc/resolv/res_query.c 2015/02/24 17:56:20 1.16
+++ src/lib/libc/resolv/res_query.c 2023/08/01 08:47:25 1.17
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: res_query.c,v 1.16 2015/02/24 17:56:20 christos Exp $ */ | 1 | /* $NetBSD: res_query.c,v 1.17 2023/08/01 08:47:25 mrg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") | 4 | * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") | |
5 | * Portions Copyright (C) 1996-2001, 2003 Internet Software Consortium. | 5 | * Portions Copyright (C) 1996-2001, 2003 Internet Software Consortium. | |
6 | * | 6 | * | |
7 | * Permission to use, copy, modify, and/or distribute this software for any | 7 | * Permission to use, copy, modify, and/or distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | 8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice appear in all copies. | 9 | * copyright notice and this permission notice appear in all copies. | |
10 | * | 10 | * | |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH | |
12 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | 12 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
13 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, | 13 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, | |
14 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | 14 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
@@ -79,27 +79,27 @@ | @@ -79,27 +79,27 @@ | |||
79 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR | 79 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR | |
80 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 80 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
81 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 81 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
82 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | 82 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
83 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 83 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
84 | */ | 84 | */ | |
85 | 85 | |||
86 | #include <sys/cdefs.h> | 86 | #include <sys/cdefs.h> | |
87 | #if defined(LIBC_SCCS) && !defined(lint) | 87 | #if defined(LIBC_SCCS) && !defined(lint) | |
88 | #ifdef notdef | 88 | #ifdef notdef | |
89 | static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; | 89 | static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; | |
90 | static const char rcsid[] = "Id: res_query.c,v 1.11 2008/11/14 02:36:51 marka Exp"; | 90 | static const char rcsid[] = "Id: res_query.c,v 1.11 2008/11/14 02:36:51 marka Exp"; | |
91 | #else | 91 | #else | |
92 | __RCSID("$NetBSD: res_query.c,v 1.16 2015/02/24 17:56:20 christos Exp $"); | 92 | __RCSID("$NetBSD: res_query.c,v 1.17 2023/08/01 08:47:25 mrg Exp $"); | |
93 | #endif | 93 | #endif | |
94 | #endif /* LIBC_SCCS and not lint */ | 94 | #endif /* LIBC_SCCS and not lint */ | |
95 | 95 | |||
96 | #include "port_before.h" | 96 | #include "port_before.h" | |
97 | 97 | |||
98 | #include "namespace.h" | 98 | #include "namespace.h" | |
99 | #include <sys/types.h> | 99 | #include <sys/types.h> | |
100 | #include <sys/param.h> | 100 | #include <sys/param.h> | |
101 | #include <netinet/in.h> | 101 | #include <netinet/in.h> | |
102 | #include <arpa/inet.h> | 102 | #include <arpa/inet.h> | |
103 | #include <arpa/nameser.h> | 103 | #include <arpa/nameser.h> | |
104 | #include <ctype.h> | 104 | #include <ctype.h> | |
105 | #include <errno.h> | 105 | #include <errno.h> | |
@@ -388,56 +388,53 @@ res_nsearch(res_state statp, | @@ -388,56 +388,53 @@ res_nsearch(res_state statp, | |||
388 | * Perform a call on res_query on the concatenation of name and domain, | 388 | * Perform a call on res_query on the concatenation of name and domain, | |
389 | * removing a trailing dot from name if domain is NULL. | 389 | * removing a trailing dot from name if domain is NULL. | |
390 | */ | 390 | */ | |
391 | int | 391 | int | |
392 | res_nquerydomain(res_state statp, | 392 | res_nquerydomain(res_state statp, | |
393 | const char *name, | 393 | const char *name, | |
394 | const char *domain, | 394 | const char *domain, | |
395 | int class, int type, /*%< class and type of query */ | 395 | int class, int type, /*%< class and type of query */ | |
396 | u_char *answer, /*%< buffer to put answer */ | 396 | u_char *answer, /*%< buffer to put answer */ | |
397 | int anslen) /*%< size of answer */ | 397 | int anslen) /*%< size of answer */ | |
398 | { | 398 | { | |
399 | char nbuf[MAXDNAME]; | 399 | char nbuf[MAXDNAME]; | |
400 | const char *longname = nbuf; | 400 | const char *longname = nbuf; | |
401 | size_t n, d; | 401 | size_t n; | |
402 | 402 | |||
403 | #ifdef DEBUG | 403 | #ifdef DEBUG | |
404 | if (statp->options & RES_DEBUG) | 404 | if (statp->options & RES_DEBUG) | |
405 | printf(";; res_nquerydomain(%s, %s, %d, %d)\n", | 405 | printf(";; res_nquerydomain(%s, %s, %d, %d)\n", | |
406 | name, domain?domain:"<Nil>", class, type); | 406 | name, domain?domain:"<Nil>", class, type); | |
407 | #endif | 407 | #endif | |
408 | if (domain == NULL) { | 408 | if (domain == NULL) { | |
409 | /* | 409 | /* | |
410 | * Check for trailing '.'; | 410 | * Check for trailing '.'; | |
411 | * copy without '.' if present. | 411 | * copy without '.' if present. | |
412 | */ | 412 | */ | |
413 | n = strlen(name); | 413 | n = strlen(name); | |
414 | if (n >= MAXDNAME) { | 414 | if (n >= MAXDNAME) { | |
415 | RES_SET_H_ERRNO(statp, NO_RECOVERY); | 415 | RES_SET_H_ERRNO(statp, NO_RECOVERY); | |
416 | return (-1); | 416 | return (-1); | |
417 | } | 417 | } | |
418 | if (n && name[--n] == '.') { | 418 | if (n && name[--n] == '.') { | |
419 | strncpy(nbuf, name, n); | 419 | snprintf(nbuf, sizeof(nbuf), "%*s", (int)n, name); | |
420 | nbuf[n] = '\0'; | |||
421 | } else | 420 | } else | |
422 | longname = name; | 421 | longname = name; | |
423 | } else { | 422 | } else { | |
424 | n = strlen(name); | 423 | if ((size_t)snprintf(nbuf, sizeof(nbuf), "%s.%s", | |
425 | d = strlen(domain); | 424 | name, domain) >= sizeof(nbuf)) { | |
426 | if (n + d + 1 >= MAXDNAME) { | |||
427 | RES_SET_H_ERRNO(statp, NO_RECOVERY); | 425 | RES_SET_H_ERRNO(statp, NO_RECOVERY); | |
428 | return (-1); | 426 | return (-1); | |
429 | } | 427 | } | |
430 | sprintf(nbuf, "%s.%s", name, domain); | |||
431 | } | 428 | } | |
432 | return (res_nquery(statp, longname, class, type, answer, anslen)); | 429 | return (res_nquery(statp, longname, class, type, answer, anslen)); | |
433 | } | 430 | } | |
434 | 431 | |||
435 | const char * | 432 | const char * | |
436 | res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { | 433 | res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { | |
437 | char *file, *cp1, *cp2; | 434 | char *file, *cp1, *cp2; | |
438 | char buf[BUFSIZ]; | 435 | char buf[BUFSIZ]; | |
439 | FILE *fp; | 436 | FILE *fp; | |
440 | 437 | |||
441 | if (statp->options & RES_NOALIASES) | 438 | if (statp->options & RES_NOALIASES) | |
442 | return (NULL); | 439 | return (NULL); | |
443 | /* | 440 | /* |
--- src/usr.sbin/edquota/edquota.c 2021/11/09 09:21:31 1.53
+++ src/usr.sbin/edquota/edquota.c 2023/08/01 08:47:25 1.54
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: edquota.c,v 1.53 2021/11/09 09:21:31 nia Exp $ */ | 1 | /* $NetBSD: edquota.c,v 1.54 2023/08/01 08:47:25 mrg Exp $ */ | |
2 | /* | 2 | /* | |
3 | * Copyright (c) 1980, 1990, 1993 | 3 | * Copyright (c) 1980, 1990, 1993 | |
4 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. | |
5 | * | 5 | * | |
6 | * This code is derived from software contributed to Berkeley by | 6 | * This code is derived from software contributed to Berkeley by | |
7 | * Robert Elz at The University of Melbourne. | 7 | * Robert Elz at The University of Melbourne. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -31,27 +31,27 @@ | @@ -31,27 +31,27 @@ | |||
31 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <sys/cdefs.h> | 34 | #include <sys/cdefs.h> | |
35 | #ifndef lint | 35 | #ifndef lint | |
36 | __COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\ | 36 | __COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\ | |
37 | The Regents of the University of California. All rights reserved."); | 37 | The Regents of the University of California. All rights reserved."); | |
38 | #endif /* not lint */ | 38 | #endif /* not lint */ | |
39 | 39 | |||
40 | #ifndef lint | 40 | #ifndef lint | |
41 | #if 0 | 41 | #if 0 | |
42 | static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95"; | 42 | static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95"; | |
43 | #else | 43 | #else | |
44 | __RCSID("$NetBSD: edquota.c,v 1.53 2021/11/09 09:21:31 nia Exp $"); | 44 | __RCSID("$NetBSD: edquota.c,v 1.54 2023/08/01 08:47:25 mrg Exp $"); | |
45 | #endif | 45 | #endif | |
46 | #endif /* not lint */ | 46 | #endif /* not lint */ | |
47 | 47 | |||
48 | /* | 48 | /* | |
49 | * Disk quota editor. | 49 | * Disk quota editor. | |
50 | */ | 50 | */ | |
51 | #include <sys/param.h> | 51 | #include <sys/param.h> | |
52 | #include <sys/stat.h> | 52 | #include <sys/stat.h> | |
53 | #include <sys/file.h> | 53 | #include <sys/file.h> | |
54 | #include <sys/wait.h> | 54 | #include <sys/wait.h> | |
55 | #include <sys/queue.h> | 55 | #include <sys/queue.h> | |
56 | #include <sys/types.h> | 56 | #include <sys/types.h> | |
57 | #include <sys/statvfs.h> | 57 | #include <sys/statvfs.h> | |
@@ -742,30 +742,30 @@ top: | @@ -742,30 +742,30 @@ top: | |||
742 | if (errno == EAGAIN) { | 742 | if (errno == EAGAIN) { | |
743 | sleep(1); | 743 | sleep(1); | |
744 | goto top; | 744 | goto top; | |
745 | } | 745 | } | |
746 | warn("fork"); | 746 | warn("fork"); | |
747 | return 0; | 747 | return 0; | |
748 | case 0: | 748 | case 0: | |
749 | if (sigprocmask(SIG_SETMASK, &os, NULL) == -1) | 749 | if (sigprocmask(SIG_SETMASK, &os, NULL) == -1) | |
750 | err(1, "sigprocmask"); | 750 | err(1, "sigprocmask"); | |
751 | setgid(getgid()); | 751 | setgid(getgid()); | |
752 | setuid(getuid()); | 752 | setuid(getuid()); | |
753 | if ((ed = getenv("EDITOR")) == (char *)0) | 753 | if ((ed = getenv("EDITOR")) == (char *)0) | |
754 | ed = _PATH_VI; | 754 | ed = _PATH_VI; | |
755 | if (strlen(ed) + strlen(ltmpfile) + 2 >= MAX_TMPSTR) { | 755 | if ((size_t)snprintf(p, sizeof(p), "%s %s", ed, ltmpfile) >= | |
756 | sizeof(p)) { | |||
756 | errx(1, "%s", "editor or filename too long"); | 757 | errx(1, "%s", "editor or filename too long"); | |
757 | } | 758 | } | |
758 | snprintf(p, sizeof(p), "%s %s", ed, ltmpfile); | |||
759 | execlp(_PATH_BSHELL, _PATH_BSHELL, "-c", p, NULL); | 759 | execlp(_PATH_BSHELL, _PATH_BSHELL, "-c", p, NULL); | |
760 | err(1, "%s", ed); | 760 | err(1, "%s", ed); | |
761 | default: | 761 | default: | |
762 | if (waitpid(pid, &lst, 0) == -1) | 762 | if (waitpid(pid, &lst, 0) == -1) | |
763 | err(1, "waitpid"); | 763 | err(1, "waitpid"); | |
764 | if (sigprocmask(SIG_SETMASK, &os, NULL) == -1) | 764 | if (sigprocmask(SIG_SETMASK, &os, NULL) == -1) | |
765 | err(1, "sigprocmask"); | 765 | err(1, "sigprocmask"); | |
766 | if (!WIFEXITED(lst) || WEXITSTATUS(lst) != 0) | 766 | if (!WIFEXITED(lst) || WEXITSTATUS(lst) != 0) | |
767 | return 0; | 767 | return 0; | |
768 | return 1; | 768 | return 1; | |
769 | } | 769 | } | |
770 | } | 770 | } | |
771 | 771 |
--- src/usr.sbin/ypserv/common/ypdb.c 2017/01/10 21:06:17 1.12
+++ src/usr.sbin/ypserv/common/ypdb.c 2023/08/01 08:47:25 1.13
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ypdb.c,v 1.12 2017/01/10 21:06:17 christos Exp $ */ | 1 | /* $NetBSD: ypdb.c,v 1.13 2023/08/01 08:47:25 mrg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1990, 1993 | 4 | * Copyright (c) 1990, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * This code is derived from software contributed to Berkeley by | 8 | * This code is derived from software contributed to Berkeley by | |
9 | * Margo Seltzer. | 9 | * Margo Seltzer. | |
10 | * | 10 | * | |
11 | * This code is derived from ndbm module of BSD4.4 db (hash) by | 11 | * This code is derived from ndbm module of BSD4.4 db (hash) by | |
12 | * Mats O Jansson | 12 | * Mats O Jansson | |
13 | * | 13 | * | |
14 | * Redistribution and use in source and binary forms, with or without | 14 | * Redistribution and use in source and binary forms, with or without | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
36 | * SUCH DAMAGE. | 36 | * SUCH DAMAGE. | |
37 | */ | 37 | */ | |
38 | 38 | |||
39 | #include <sys/cdefs.h> | 39 | #include <sys/cdefs.h> | |
40 | #ifndef lint | 40 | #ifndef lint | |
41 | __RCSID("$NetBSD: ypdb.c,v 1.12 2017/01/10 21:06:17 christos Exp $"); | 41 | __RCSID("$NetBSD: ypdb.c,v 1.13 2023/08/01 08:47:25 mrg Exp $"); | |
42 | #endif | 42 | #endif | |
43 | 43 | |||
44 | #include <sys/param.h> | 44 | #include <sys/param.h> | |
45 | #include <sys/types.h> | 45 | #include <sys/types.h> | |
46 | #include <sys/stat.h> | 46 | #include <sys/stat.h> | |
47 | 47 | |||
48 | #include <db.h> | 48 | #include <db.h> | |
49 | #include <err.h> | 49 | #include <err.h> | |
50 | #include <errno.h> | 50 | #include <errno.h> | |
51 | #include <fcntl.h> | 51 | #include <fcntl.h> | |
52 | #include <stdio.h> | 52 | #include <stdio.h> | |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> | |
54 | #include <string.h> | 54 | #include <string.h> | |
@@ -72,31 +72,31 @@ static DBM *_ypdb_dbopen(const char *, i | @@ -72,31 +72,31 @@ static DBM *_ypdb_dbopen(const char *, i | |||
72 | */ | 72 | */ | |
73 | 73 | |||
74 | DBM * | 74 | DBM * | |
75 | ypdb_open(const char *file) | 75 | ypdb_open(const char *file) | |
76 | { | 76 | { | |
77 | char path[MAXPATHLEN]; | 77 | char path[MAXPATHLEN]; | |
78 | const char *cp, *suffix; | 78 | const char *cp, *suffix; | |
79 | 79 | |||
80 | cp = strrchr(file, '.'); | 80 | cp = strrchr(file, '.'); | |
81 | if (cp != NULL && strcmp(cp, YPDB_SUFFIX) == 0) | 81 | if (cp != NULL && strcmp(cp, YPDB_SUFFIX) == 0) | |
82 | suffix = ""; | 82 | suffix = ""; | |
83 | else | 83 | else | |
84 | suffix = YPDB_SUFFIX; | 84 | suffix = YPDB_SUFFIX; | |
85 | if (strlen(file) + strlen(suffix) > (sizeof(path) - 1)) { | 85 | if ((size_t)snprintf(path, sizeof(path), "%s%s", file, suffix) > | |
86 | sizeof(path)) { | |||
86 | warnx("File name `%s' is too long", file); | 87 | warnx("File name `%s' is too long", file); | |
87 | return (NULL); | 88 | return NULL; | |
88 | } | 89 | } | |
89 | snprintf(path, sizeof(path), "%s%s", file, suffix); | |||
90 | return _ypdb_dbopen(path, O_RDONLY, 0444); | 90 | return _ypdb_dbopen(path, O_RDONLY, 0444); | |
91 | } | 91 | } | |
92 | 92 | |||
93 | /* | 93 | /* | |
94 | * ypdb_mktemp -- | 94 | * ypdb_mktemp -- | |
95 | * Create a temporary file using mkstemp(3) based on the | 95 | * Create a temporary file using mkstemp(3) based on the | |
96 | * template provided in file. | 96 | * template provided in file. | |
97 | * dbopen(3) file, read-write, 0644 (modified by umask(2)). | 97 | * dbopen(3) file, read-write, 0644 (modified by umask(2)). | |
98 | * Try opening as a DB_BTREE first, then DB_HASH. | 98 | * Try opening as a DB_BTREE first, then DB_HASH. | |
99 | * file won't have YPDB_SUFFIX. | 99 | * file won't have YPDB_SUFFIX. | |
100 | * | 100 | * | |
101 | * Returns: | 101 | * Returns: | |
102 | * *DBM on success; file now exists. | 102 | * *DBM on success; file now exists. |