diff options
author | Damien Miller <djm@mindrot.org> | 2002-09-11 10:29:11 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2002-09-11 10:29:11 +1000 |
commit | 71eb0c1550ec6ad10d29779df7a7f97c44000e3a (patch) | |
tree | 1cbfd081547bcf3bfcc26e17f2f4537a03ced5ff | |
parent | c34e03e4711cabffae3504bcfdac26b67250c45d (diff) |
- (djm) Sync openbsd-compat with OpenBSD -current
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | openbsd-compat/base64.c | 3 | ||||
-rw-r--r-- | openbsd-compat/dirname.c | 8 | ||||
-rw-r--r-- | openbsd-compat/glob.c | 44 | ||||
-rw-r--r-- | openbsd-compat/glob.h | 18 | ||||
-rw-r--r-- | openbsd-compat/inet_ntoa.c | 4 | ||||
-rw-r--r-- | openbsd-compat/inet_ntop.c | 49 | ||||
-rw-r--r-- | openbsd-compat/mktemp.c | 6 | ||||
-rw-r--r-- | openbsd-compat/readpassphrase.c | 35 | ||||
-rw-r--r-- | openbsd-compat/readpassphrase.h | 5 |
10 files changed, 103 insertions, 74 deletions
@@ -1,3 +1,6 @@ | |||
1 | 20020911 | ||
2 | - (djm) Sync openbsd-compat with OpenBSD -current | ||
3 | |||
1 | 20020910 | 4 | 20020910 |
2 | - (djm) Bug #365: Read /.ssh/environment properly under CygWin. | 5 | - (djm) Bug #365: Read /.ssh/environment properly under CygWin. |
3 | Patch from Mark Bradshaw <bradshaw@staff.crosswalk.com> | 6 | Patch from Mark Bradshaw <bradshaw@staff.crosswalk.com> |
@@ -1614,4 +1617,4 @@ | |||
1614 | - (stevesk) entropy.c: typo in debug message | 1617 | - (stevesk) entropy.c: typo in debug message |
1615 | - (djm) ssh-keygen -i needs seeded RNG; report from markus@ | 1618 | - (djm) ssh-keygen -i needs seeded RNG; report from markus@ |
1616 | 1619 | ||
1617 | $Id: ChangeLog,v 1.2450 2002/09/10 12:26:17 djm Exp $ | 1620 | $Id: ChangeLog,v 1.2451 2002/09/11 00:29:11 djm Exp $ |
diff --git a/openbsd-compat/base64.c b/openbsd-compat/base64.c index 48ba54256..005170b80 100644 --- a/openbsd-compat/base64.c +++ b/openbsd-compat/base64.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: base64.c,v 1.3 1997/11/08 20:46:55 deraadt Exp $ */ | 1 | /* $OpenBSD: base64.c,v 1.4 2002/01/02 23:00:10 deraadt Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1996 by Internet Software Consortium. | 4 | * Copyright (c) 1996 by Internet Software Consortium. |
@@ -60,6 +60,7 @@ | |||
60 | 60 | ||
61 | #include "base64.h" | 61 | #include "base64.h" |
62 | 62 | ||
63 | /* XXX abort illegal in library */ | ||
63 | #define Assert(Cond) if (!(Cond)) abort() | 64 | #define Assert(Cond) if (!(Cond)) abort() |
64 | 65 | ||
65 | static const char Base64[] = | 66 | static const char Base64[] = |
diff --git a/openbsd-compat/dirname.c b/openbsd-compat/dirname.c index 391b2dd81..35c7d8ec7 100644 --- a/openbsd-compat/dirname.c +++ b/openbsd-compat/dirname.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dirname.c,v 1.6 2001/06/28 04:27:19 pjanzen Exp $ */ | 1 | /* $OpenBSD: dirname.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> |
@@ -31,7 +31,7 @@ | |||
31 | #ifndef HAVE_DIRNAME | 31 | #ifndef HAVE_DIRNAME |
32 | 32 | ||
33 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
34 | static char rcsid[] = "$OpenBSD: dirname.c,v 1.6 2001/06/28 04:27:19 pjanzen Exp $"; | 34 | static char rcsid[] = "$OpenBSD: dirname.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $"; |
35 | #endif /* LIBC_SCCS and not lint */ | 35 | #endif /* LIBC_SCCS and not lint */ |
36 | 36 | ||
37 | #include <errno.h> | 37 | #include <errno.h> |
@@ -47,7 +47,7 @@ dirname(path) | |||
47 | 47 | ||
48 | /* Empty or NULL string gets treated as "." */ | 48 | /* Empty or NULL string gets treated as "." */ |
49 | if (path == NULL || *path == '\0') { | 49 | if (path == NULL || *path == '\0') { |
50 | (void)strcpy(bname, "."); | 50 | (void)strlcpy(bname, ".", sizeof bname); |
51 | return(bname); | 51 | return(bname); |
52 | } | 52 | } |
53 | 53 | ||
@@ -62,7 +62,7 @@ dirname(path) | |||
62 | 62 | ||
63 | /* Either the dir is "/" or there are no slashes */ | 63 | /* Either the dir is "/" or there are no slashes */ |
64 | if (endp == path) { | 64 | if (endp == path) { |
65 | (void)strcpy(bname, *endp == '/' ? "/" : "."); | 65 | (void)strlcpy(bname, *endp == '/' ? "/" : ".", sizeof bname); |
66 | return(bname); | 66 | return(bname); |
67 | } else { | 67 | } else { |
68 | do { | 68 | do { |
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index 14c91420d..e928a2272 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c | |||
@@ -56,7 +56,7 @@ get_arg_max(void) | |||
56 | #if 0 | 56 | #if 0 |
57 | static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; | 57 | static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; |
58 | #else | 58 | #else |
59 | static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $"; | 59 | static char rcsid[] = "$OpenBSD: glob.c,v 1.20 2002/06/14 21:34:58 todd Exp $"; |
60 | #endif | 60 | #endif |
61 | #endif /* LIBC_SCCS and not lint */ | 61 | #endif /* LIBC_SCCS and not lint */ |
62 | 62 | ||
@@ -137,32 +137,32 @@ typedef char Char; | |||
137 | #define ismeta(c) (((c)&M_QUOTE) != 0) | 137 | #define ismeta(c) (((c)&M_QUOTE) != 0) |
138 | 138 | ||
139 | 139 | ||
140 | static int compare __P((const void *, const void *)); | 140 | static int compare(const void *, const void *); |
141 | static int g_Ctoc __P((const Char *, char *, u_int)); | 141 | static int g_Ctoc(const Char *, char *, u_int); |
142 | static int g_lstat __P((Char *, struct stat *, glob_t *)); | 142 | static int g_lstat(Char *, struct stat *, glob_t *); |
143 | static DIR *g_opendir __P((Char *, glob_t *)); | 143 | static DIR *g_opendir(Char *, glob_t *); |
144 | static Char *g_strchr __P((Char *, int)); | 144 | static Char *g_strchr(Char *, int); |
145 | static int g_stat __P((Char *, struct stat *, glob_t *)); | 145 | static int g_stat(Char *, struct stat *, glob_t *); |
146 | static int glob0 __P((const Char *, glob_t *)); | 146 | static int glob0(const Char *, glob_t *); |
147 | static int glob1 __P((Char *, Char *, glob_t *, size_t *)); | 147 | static int glob1(Char *, Char *, glob_t *, size_t *); |
148 | static int glob2 __P((Char *, Char *, Char *, Char *, Char *, Char *, | 148 | static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, |
149 | glob_t *, size_t *)); | 149 | glob_t *, size_t *); |
150 | static int glob3 __P((Char *, Char *, Char *, Char *, Char *, Char *, | 150 | static int glob3(Char *, Char *, Char *, Char *, Char *, Char *, |
151 | Char *, Char *, glob_t *, size_t *)); | 151 | Char *, Char *, glob_t *, size_t *); |
152 | static int globextend __P((const Char *, glob_t *, size_t *)); | 152 | static int globextend(const Char *, glob_t *, size_t *); |
153 | static const Char * | 153 | static const Char * |
154 | globtilde __P((const Char *, Char *, size_t, glob_t *)); | 154 | globtilde(const Char *, Char *, size_t, glob_t *); |
155 | static int globexp1 __P((const Char *, glob_t *)); | 155 | static int globexp1(const Char *, glob_t *); |
156 | static int globexp2 __P((const Char *, const Char *, glob_t *, int *)); | 156 | static int globexp2(const Char *, const Char *, glob_t *, int *); |
157 | static int match __P((Char *, Char *, Char *)); | 157 | static int match(Char *, Char *, Char *); |
158 | #ifdef DEBUG | 158 | #ifdef DEBUG |
159 | static void qprintf __P((const char *, Char *)); | 159 | static void qprintf(const char *, Char *); |
160 | #endif | 160 | #endif |
161 | 161 | ||
162 | int | 162 | int |
163 | glob(pattern, flags, errfunc, pglob) | 163 | glob(pattern, flags, errfunc, pglob) |
164 | const char *pattern; | 164 | const char *pattern; |
165 | int flags, (*errfunc) __P((const char *, int)); | 165 | int flags, (*errfunc)(const char *, int); |
166 | glob_t *pglob; | 166 | glob_t *pglob; |
167 | { | 167 | { |
168 | const u_char *patnext; | 168 | const u_char *patnext; |
@@ -677,7 +677,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, | |||
677 | 677 | ||
678 | 678 | ||
679 | /* | 679 | /* |
680 | * Extend the gl_pathv member of a glob_t structure to accomodate a new item, | 680 | * Extend the gl_pathv member of a glob_t structure to accommodate a new item, |
681 | * add the new item, and update gl_pathc. | 681 | * add the new item, and update gl_pathc. |
682 | * | 682 | * |
683 | * This assumes the BSD realloc, which only copies the block when its size | 683 | * This assumes the BSD realloc, which only copies the block when its size |
@@ -822,7 +822,7 @@ g_opendir(str, pglob) | |||
822 | char buf[MAXPATHLEN]; | 822 | char buf[MAXPATHLEN]; |
823 | 823 | ||
824 | if (!*str) | 824 | if (!*str) |
825 | strcpy(buf, "."); | 825 | strlcpy(buf, ".", sizeof buf); |
826 | else { | 826 | else { |
827 | if (g_Ctoc(str, buf, sizeof(buf))) | 827 | if (g_Ctoc(str, buf, sizeof(buf))) |
828 | return(NULL); | 828 | return(NULL); |
diff --git a/openbsd-compat/glob.h b/openbsd-compat/glob.h index b4c8f7aaa..6421f7049 100644 --- a/openbsd-compat/glob.h +++ b/openbsd-compat/glob.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: glob.h,v 1.5 2001/03/18 17:18:58 deraadt Exp $ */ | 1 | /* $OpenBSD: glob.h,v 1.7 2002/02/17 19:42:21 millert Exp $ */ |
2 | /* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ | 2 | /* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -53,18 +53,18 @@ typedef struct { | |||
53 | int gl_flags; /* Copy of flags parameter to glob. */ | 53 | int gl_flags; /* Copy of flags parameter to glob. */ |
54 | char **gl_pathv; /* List of paths matching pattern. */ | 54 | char **gl_pathv; /* List of paths matching pattern. */ |
55 | /* Copy of errfunc parameter to glob. */ | 55 | /* Copy of errfunc parameter to glob. */ |
56 | int (*gl_errfunc) __P((const char *, int)); | 56 | int (*gl_errfunc)(const char *, int); |
57 | 57 | ||
58 | /* | 58 | /* |
59 | * Alternate filesystem access methods for glob; replacement | 59 | * Alternate filesystem access methods for glob; replacement |
60 | * versions of closedir(3), readdir(3), opendir(3), stat(2) | 60 | * versions of closedir(3), readdir(3), opendir(3), stat(2) |
61 | * and lstat(2). | 61 | * and lstat(2). |
62 | */ | 62 | */ |
63 | void (*gl_closedir) __P((void *)); | 63 | void (*gl_closedir)(void *); |
64 | struct dirent *(*gl_readdir) __P((void *)); | 64 | struct dirent *(*gl_readdir)(void *); |
65 | void *(*gl_opendir) __P((const char *)); | 65 | void *(*gl_opendir)(const char *); |
66 | int (*gl_lstat) __P((const char *, struct stat *)); | 66 | int (*gl_lstat)(const char *, struct stat *); |
67 | int (*gl_stat) __P((const char *, struct stat *)); | 67 | int (*gl_stat)(const char *, struct stat *); |
68 | } glob_t; | 68 | } glob_t; |
69 | 69 | ||
70 | /* Flags */ | 70 | /* Flags */ |
@@ -91,8 +91,8 @@ typedef struct { | |||
91 | #define GLOB_NOSYS (-4) /* Function not supported. */ | 91 | #define GLOB_NOSYS (-4) /* Function not supported. */ |
92 | #define GLOB_ABEND GLOB_ABORTED | 92 | #define GLOB_ABEND GLOB_ABORTED |
93 | 93 | ||
94 | int glob __P((const char *, int, int (*)(const char *, int), glob_t *)); | 94 | int glob(const char *, int, int (*)(const char *, int), glob_t *); |
95 | void globfree __P((glob_t *)); | 95 | void globfree(glob_t *); |
96 | 96 | ||
97 | #endif /* !_GLOB_H_ */ | 97 | #endif /* !_GLOB_H_ */ |
98 | 98 | ||
diff --git a/openbsd-compat/inet_ntoa.c b/openbsd-compat/inet_ntoa.c index ad228229c..ac5f56708 100644 --- a/openbsd-compat/inet_ntoa.c +++ b/openbsd-compat/inet_ntoa.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) | 36 | #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) |
37 | 37 | ||
38 | #if defined(LIBC_SCCS) && !defined(lint) | 38 | #if defined(LIBC_SCCS) && !defined(lint) |
39 | static char rcsid[] = "$OpenBSD: inet_ntoa.c,v 1.2 1996/08/19 08:29:16 tholo Exp $"; | 39 | static char rcsid[] = "$OpenBSD: inet_ntoa.c,v 1.3 2002/06/27 10:14:01 itojun Exp $"; |
40 | #endif /* LIBC_SCCS and not lint */ | 40 | #endif /* LIBC_SCCS and not lint */ |
41 | 41 | ||
42 | /* | 42 | /* |
@@ -57,7 +57,7 @@ char *inet_ntoa(struct in_addr in) | |||
57 | p = (char *)∈ | 57 | p = (char *)∈ |
58 | #define UC(b) (((int)b)&0xff) | 58 | #define UC(b) (((int)b)&0xff) |
59 | (void)snprintf(b, sizeof(b), | 59 | (void)snprintf(b, sizeof(b), |
60 | "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); | 60 | "%u.%u.%u.%u", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); |
61 | return (b); | 61 | return (b); |
62 | } | 62 | } |
63 | 63 | ||
diff --git a/openbsd-compat/inet_ntop.c b/openbsd-compat/inet_ntop.c index 3a91aecd4..3bea519af 100644 --- a/openbsd-compat/inet_ntop.c +++ b/openbsd-compat/inet_ntop.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $ */ | 1 | /* $OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $ */ |
2 | 2 | ||
3 | /* Copyright (c) 1996 by Internet Software Consortium. | 3 | /* Copyright (c) 1996 by Internet Software Consortium. |
4 | * | 4 | * |
@@ -24,7 +24,7 @@ | |||
24 | #if 0 | 24 | #if 0 |
25 | static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $"; | 25 | static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $"; |
26 | #else | 26 | #else |
27 | static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $"; | 27 | static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $"; |
28 | #endif | 28 | #endif |
29 | #endif /* LIBC_SCCS and not lint */ | 29 | #endif /* LIBC_SCCS and not lint */ |
30 | 30 | ||
@@ -54,8 +54,8 @@ static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Ex | |||
54 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | 54 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. |
55 | */ | 55 | */ |
56 | 56 | ||
57 | static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); | 57 | static const char *inet_ntop4(const u_char *src, char *dst, size_t size); |
58 | static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); | 58 | static const char *inet_ntop6(const u_char *src, char *dst, size_t size); |
59 | 59 | ||
60 | /* char * | 60 | /* char * |
61 | * inet_ntop(af, src, dst, size) | 61 | * inet_ntop(af, src, dst, size) |
@@ -103,13 +103,14 @@ inet_ntop4(src, dst, size) | |||
103 | { | 103 | { |
104 | static const char fmt[] = "%u.%u.%u.%u"; | 104 | static const char fmt[] = "%u.%u.%u.%u"; |
105 | char tmp[sizeof "255.255.255.255"]; | 105 | char tmp[sizeof "255.255.255.255"]; |
106 | int l; | ||
106 | 107 | ||
107 | if (snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], | 108 | l = snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]); |
108 | src[3]) > size) { | 109 | if (l <= 0 || l >= size) { |
109 | errno = ENOSPC; | 110 | errno = ENOSPC; |
110 | return (NULL); | 111 | return (NULL); |
111 | } | 112 | } |
112 | strcpy(dst, tmp); | 113 | strlcpy(dst, tmp, size); |
113 | return (dst); | 114 | return (dst); |
114 | } | 115 | } |
115 | 116 | ||
@@ -132,10 +133,12 @@ inet_ntop6(src, dst, size) | |||
132 | * Keep this in mind if you think this function should have been coded | 133 | * Keep this in mind if you think this function should have been coded |
133 | * to use pointer overlays. All the world's not a VAX. | 134 | * to use pointer overlays. All the world's not a VAX. |
134 | */ | 135 | */ |
135 | char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; | 136 | char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; |
137 | char *tp, *ep; | ||
136 | struct { int base, len; } best, cur; | 138 | struct { int base, len; } best, cur; |
137 | u_int words[IN6ADDRSZ / INT16SZ]; | 139 | u_int words[IN6ADDRSZ / INT16SZ]; |
138 | int i; | 140 | int i; |
141 | int advance; | ||
139 | 142 | ||
140 | /* | 143 | /* |
141 | * Preprocess: | 144 | * Preprocess: |
@@ -172,31 +175,45 @@ inet_ntop6(src, dst, size) | |||
172 | * Format the result. | 175 | * Format the result. |
173 | */ | 176 | */ |
174 | tp = tmp; | 177 | tp = tmp; |
175 | for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { | 178 | ep = tmp + sizeof(tmp); |
179 | for (i = 0; i < (IN6ADDRSZ / INT16SZ) && tp < ep; i++) { | ||
176 | /* Are we inside the best run of 0x00's? */ | 180 | /* Are we inside the best run of 0x00's? */ |
177 | if (best.base != -1 && i >= best.base && | 181 | if (best.base != -1 && i >= best.base && |
178 | i < (best.base + best.len)) { | 182 | i < (best.base + best.len)) { |
179 | if (i == best.base) | 183 | if (i == best.base) { |
184 | if (tp + 1 >= ep) | ||
185 | return (NULL); | ||
180 | *tp++ = ':'; | 186 | *tp++ = ':'; |
187 | } | ||
181 | continue; | 188 | continue; |
182 | } | 189 | } |
183 | /* Are we following an initial run of 0x00s or any real hex? */ | 190 | /* Are we following an initial run of 0x00s or any real hex? */ |
184 | if (i != 0) | 191 | if (i != 0) { |
192 | if (tp + 1 >= ep) | ||
193 | return (NULL); | ||
185 | *tp++ = ':'; | 194 | *tp++ = ':'; |
195 | } | ||
186 | /* Is this address an encapsulated IPv4? */ | 196 | /* Is this address an encapsulated IPv4? */ |
187 | if (i == 6 && best.base == 0 && | 197 | if (i == 6 && best.base == 0 && |
188 | (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { | 198 | (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { |
189 | if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) | 199 | if (!inet_ntop4(src+12, tp, (size_t)(ep - tp))) |
190 | return (NULL); | 200 | return (NULL); |
191 | tp += strlen(tp); | 201 | tp += strlen(tp); |
192 | break; | 202 | break; |
193 | } | 203 | } |
194 | snprintf(tp, sizeof(tmp - (tp - tmp)), "%x", words[i]); | 204 | advance = snprintf(tp, ep - tp, "%x", words[i]); |
195 | tp += strlen(tp); | 205 | if (advance <= 0 || advance >= ep - tp) |
206 | return (NULL); | ||
207 | tp += advance; | ||
196 | } | 208 | } |
197 | /* Was it a trailing run of 0x00's? */ | 209 | /* Was it a trailing run of 0x00's? */ |
198 | if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) | 210 | if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) { |
211 | if (tp + 1 >= ep) | ||
212 | return (NULL); | ||
199 | *tp++ = ':'; | 213 | *tp++ = ':'; |
214 | } | ||
215 | if (tp + 1 >= ep) | ||
216 | return (NULL); | ||
200 | *tp++ = '\0'; | 217 | *tp++ = '\0'; |
201 | 218 | ||
202 | /* | 219 | /* |
@@ -206,7 +223,7 @@ inet_ntop6(src, dst, size) | |||
206 | errno = ENOSPC; | 223 | errno = ENOSPC; |
207 | return (NULL); | 224 | return (NULL); |
208 | } | 225 | } |
209 | strcpy(dst, tmp); | 226 | strlcpy(dst, tmp, size); |
210 | return (dst); | 227 | return (dst); |
211 | } | 228 | } |
212 | 229 | ||
diff --git a/openbsd-compat/mktemp.c b/openbsd-compat/mktemp.c index d69dc5c24..d256ee448 100644 --- a/openbsd-compat/mktemp.c +++ b/openbsd-compat/mktemp.c | |||
@@ -39,7 +39,7 @@ | |||
39 | #ifndef HAVE_MKDTEMP | 39 | #ifndef HAVE_MKDTEMP |
40 | 40 | ||
41 | #if defined(LIBC_SCCS) && !defined(lint) | 41 | #if defined(LIBC_SCCS) && !defined(lint) |
42 | static char rcsid[] = "$OpenBSD: mktemp.c,v 1.14 2002/01/02 20:18:32 deraadt Exp $"; | 42 | static char rcsid[] = "$OpenBSD: mktemp.c,v 1.16 2002/05/27 18:20:45 millert Exp $"; |
43 | #endif /* LIBC_SCCS and not lint */ | 43 | #endif /* LIBC_SCCS and not lint */ |
44 | 44 | ||
45 | #ifdef HAVE_CYGWIN | 45 | #ifdef HAVE_CYGWIN |
@@ -102,11 +102,11 @@ _gettemp(path, doopen, domkdir, slen) | |||
102 | return (0); | 102 | return (0); |
103 | } | 103 | } |
104 | pid = getpid(); | 104 | pid = getpid(); |
105 | while (*trv == 'X' && pid != 0) { | 105 | while (trv >= path && *trv == 'X' && pid != 0) { |
106 | *trv-- = (pid % 10) + '0'; | 106 | *trv-- = (pid % 10) + '0'; |
107 | pid /= 10; | 107 | pid /= 10; |
108 | } | 108 | } |
109 | while (*trv == 'X') { | 109 | while (trv >= path && *trv == 'X') { |
110 | char c; | 110 | char c; |
111 | 111 | ||
112 | pid = (arc4random() & 0xffff) % (26+26); | 112 | pid = (arc4random() & 0xffff) % (26+26); |
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c index 8c2f5f841..4e549b62b 100644 --- a/openbsd-compat/readpassphrase.c +++ b/openbsd-compat/readpassphrase.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* $OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $ */ | 1 | /* $OpenBSD: readpassphrase.c,v 1.14 2002/06/28 01:43:58 millert Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 2000-2002 Todd C. Miller <Todd.Miller@courtesan.com> |
5 | * All rights reserved. | 5 | * 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 |
@@ -28,7 +28,7 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $"; | 31 | static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.14 2002/06/28 01:43:58 millert Exp $"; |
32 | #endif /* LIBC_SCCS and not lint */ | 32 | #endif /* LIBC_SCCS and not lint */ |
33 | 33 | ||
34 | #include "includes.h" | 34 | #include "includes.h" |
@@ -60,8 +60,8 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) | |||
60 | int input, output, save_errno; | 60 | int input, output, save_errno; |
61 | char ch, *p, *end; | 61 | char ch, *p, *end; |
62 | struct termios term, oterm; | 62 | struct termios term, oterm; |
63 | struct sigaction sa, saveint, savehup, savequit, saveterm; | 63 | struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm; |
64 | struct sigaction savetstp, savettin, savettou; | 64 | struct sigaction savetstp, savettin, savettou, savepipe; |
65 | 65 | ||
66 | /* I suppose we could alloc on demand in this case (XXX). */ | 66 | /* I suppose we could alloc on demand in this case (XXX). */ |
67 | if (bufsiz == 0) { | 67 | if (bufsiz == 0) { |
@@ -70,11 +70,13 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) | |||
70 | } | 70 | } |
71 | 71 | ||
72 | restart: | 72 | restart: |
73 | signo = 0; | ||
73 | /* | 74 | /* |
74 | * Read and write to /dev/tty if available. If not, read from | 75 | * Read and write to /dev/tty if available. If not, read from |
75 | * stdin and write to stderr unless a tty is required. | 76 | * stdin and write to stderr unless a tty is required. |
76 | */ | 77 | */ |
77 | if ((input = output = open(_PATH_TTY, O_RDWR)) == -1) { | 78 | if ((flags & RPP_STDIN) || |
79 | (input = output = open(_PATH_TTY, O_RDWR)) == -1) { | ||
78 | if (flags & RPP_REQUIRE_TTY) { | 80 | if (flags & RPP_REQUIRE_TTY) { |
79 | errno = ENOTTY; | 81 | errno = ENOTTY; |
80 | return(NULL); | 82 | return(NULL); |
@@ -86,13 +88,15 @@ restart: | |||
86 | /* | 88 | /* |
87 | * Catch signals that would otherwise cause the user to end | 89 | * Catch signals that would otherwise cause the user to end |
88 | * up with echo turned off in the shell. Don't worry about | 90 | * up with echo turned off in the shell. Don't worry about |
89 | * things like SIGALRM and SIGPIPE for now. | 91 | * things like SIGXCPU and SIGVTALRM for now. |
90 | */ | 92 | */ |
91 | sigemptyset(&sa.sa_mask); | 93 | sigemptyset(&sa.sa_mask); |
92 | sa.sa_flags = 0; /* don't restart system calls */ | 94 | sa.sa_flags = 0; /* don't restart system calls */ |
93 | sa.sa_handler = handler; | 95 | sa.sa_handler = handler; |
94 | (void)sigaction(SIGINT, &sa, &saveint); | 96 | (void)sigaction(SIGALRM, &sa, &savealrm); |
95 | (void)sigaction(SIGHUP, &sa, &savehup); | 97 | (void)sigaction(SIGHUP, &sa, &savehup); |
98 | (void)sigaction(SIGINT, &sa, &saveint); | ||
99 | (void)sigaction(SIGPIPE, &sa, &savepipe); | ||
96 | (void)sigaction(SIGQUIT, &sa, &savequit); | 100 | (void)sigaction(SIGQUIT, &sa, &savequit); |
97 | (void)sigaction(SIGTERM, &sa, &saveterm); | 101 | (void)sigaction(SIGTERM, &sa, &saveterm); |
98 | (void)sigaction(SIGTSTP, &sa, &savetstp); | 102 | (void)sigaction(SIGTSTP, &sa, &savetstp); |
@@ -100,7 +104,7 @@ restart: | |||
100 | (void)sigaction(SIGTTOU, &sa, &savettou); | 104 | (void)sigaction(SIGTTOU, &sa, &savettou); |
101 | 105 | ||
102 | /* Turn off echo if possible. */ | 106 | /* Turn off echo if possible. */ |
103 | if (tcgetattr(input, &oterm) == 0) { | 107 | if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) { |
104 | memcpy(&term, &oterm, sizeof(term)); | 108 | memcpy(&term, &oterm, sizeof(term)); |
105 | if (!(flags & RPP_ECHO_ON)) | 109 | if (!(flags & RPP_ECHO_ON)) |
106 | term.c_lflag &= ~(ECHO | ECHONL); | 110 | term.c_lflag &= ~(ECHO | ECHONL); |
@@ -111,10 +115,13 @@ restart: | |||
111 | (void)tcsetattr(input, _T_FLUSH, &term); | 115 | (void)tcsetattr(input, _T_FLUSH, &term); |
112 | } else { | 116 | } else { |
113 | memset(&term, 0, sizeof(term)); | 117 | memset(&term, 0, sizeof(term)); |
118 | term.c_lflag |= ECHO; | ||
114 | memset(&oterm, 0, sizeof(oterm)); | 119 | memset(&oterm, 0, sizeof(oterm)); |
120 | oterm.c_lflag |= ECHO; | ||
115 | } | 121 | } |
116 | 122 | ||
117 | (void)write(output, prompt, strlen(prompt)); | 123 | if (!(flags & RPP_STDIN)) |
124 | (void)write(output, prompt, strlen(prompt)); | ||
118 | end = buf + bufsiz - 1; | 125 | end = buf + bufsiz - 1; |
119 | for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { | 126 | for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { |
120 | if (p < end) { | 127 | if (p < end) { |
@@ -137,13 +144,14 @@ restart: | |||
137 | /* Restore old terminal settings and signals. */ | 144 | /* Restore old terminal settings and signals. */ |
138 | if (memcmp(&term, &oterm, sizeof(term)) != 0) | 145 | if (memcmp(&term, &oterm, sizeof(term)) != 0) |
139 | (void)tcsetattr(input, _T_FLUSH, &oterm); | 146 | (void)tcsetattr(input, _T_FLUSH, &oterm); |
140 | (void)sigaction(SIGINT, &saveint, NULL); | 147 | (void)sigaction(SIGALRM, &savealrm, NULL); |
141 | (void)sigaction(SIGHUP, &savehup, NULL); | 148 | (void)sigaction(SIGHUP, &savehup, NULL); |
149 | (void)sigaction(SIGINT, &saveint, NULL); | ||
142 | (void)sigaction(SIGQUIT, &savequit, NULL); | 150 | (void)sigaction(SIGQUIT, &savequit, NULL); |
151 | (void)sigaction(SIGPIPE, &savepipe, NULL); | ||
143 | (void)sigaction(SIGTERM, &saveterm, NULL); | 152 | (void)sigaction(SIGTERM, &saveterm, NULL); |
144 | (void)sigaction(SIGTSTP, &savetstp, NULL); | 153 | (void)sigaction(SIGTSTP, &savetstp, NULL); |
145 | (void)sigaction(SIGTTIN, &savettin, NULL); | 154 | (void)sigaction(SIGTTIN, &savettin, NULL); |
146 | (void)sigaction(SIGTTOU, &savettou, NULL); | ||
147 | if (input != STDIN_FILENO) | 155 | if (input != STDIN_FILENO) |
148 | (void)close(input); | 156 | (void)close(input); |
149 | 157 | ||
@@ -152,12 +160,11 @@ restart: | |||
152 | * now that we have restored the signal handlers. | 160 | * now that we have restored the signal handlers. |
153 | */ | 161 | */ |
154 | if (signo) { | 162 | if (signo) { |
155 | kill(getpid(), signo); | 163 | kill(getpid(), signo); |
156 | switch (signo) { | 164 | switch (signo) { |
157 | case SIGTSTP: | 165 | case SIGTSTP: |
158 | case SIGTTIN: | 166 | case SIGTTIN: |
159 | case SIGTTOU: | 167 | case SIGTTOU: |
160 | signo = 0; | ||
161 | goto restart; | 168 | goto restart; |
162 | } | 169 | } |
163 | } | 170 | } |
diff --git a/openbsd-compat/readpassphrase.h b/openbsd-compat/readpassphrase.h index 9077b6e08..92908a489 100644 --- a/openbsd-compat/readpassphrase.h +++ b/openbsd-compat/readpassphrase.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: readpassphrase.h,v 1.1 2000/11/21 00:48:38 millert Exp $ */ | 1 | /* $OpenBSD: readpassphrase.h,v 1.3 2002/06/28 12:32:22 millert Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> |
@@ -40,8 +40,9 @@ | |||
40 | #define RPP_FORCELOWER 0x04 /* Force input to lower case. */ | 40 | #define RPP_FORCELOWER 0x04 /* Force input to lower case. */ |
41 | #define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ | 41 | #define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ |
42 | #define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ | 42 | #define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ |
43 | #define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ | ||
43 | 44 | ||
44 | char *readpassphrase(const char *, char *, size_t, int); | 45 | char * readpassphrase(const char *, char *, size_t, int); |
45 | 46 | ||
46 | #endif /* HAVE_READPASSPHRASE */ | 47 | #endif /* HAVE_READPASSPHRASE */ |
47 | 48 | ||