summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2021-12-06 11:06:58 +0000
committertb <>2021-12-06 11:06:58 +0000
commit60a6a10467f5b7d56c92fe8e4133a6af9e9bd48f (patch)
tree55bcc3ded6ebb2898bb541a7b58b36f5c9bc096d /src
parentf99574add34cb55c0297c6dcad8ed12e9eb18893 (diff)
downloadopenbsd-60a6a10467f5b7d56c92fe8e4133a6af9e9bd48f.tar.gz
openbsd-60a6a10467f5b7d56c92fe8e4133a6af9e9bd48f.tar.bz2
openbsd-60a6a10467f5b7d56c92fe8e4133a6af9e9bd48f.zip
Clean up a bunch of dead code in s_server.c and s_socket.c
jsg's analysis tool flagged a potential double free in do_server(). While this looks like a false positive, we can clean this code up a little: the host name passed to the callbacks isn't used by either sv_body() and www_body(), so it can be made local to do_accept() (an extra variable would not even be needed). Simplify the callbacks' signatures accordingly. Remove some commented out linger code that would never be used again anyway. ok inoguchi jsg
Diffstat (limited to '')
-rw-r--r--src/usr.bin/openssl/s_apps.h4
-rw-r--r--src/usr.bin/openssl/s_server.c10
-rw-r--r--src/usr.bin/openssl/s_socket.c43
3 files changed, 21 insertions, 36 deletions
diff --git a/src/usr.bin/openssl/s_apps.h b/src/usr.bin/openssl/s_apps.h
index f535a35c39..a73c2eb1b4 100644
--- a/src/usr.bin/openssl/s_apps.h
+++ b/src/usr.bin/openssl/s_apps.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: s_apps.h,v 1.6 2021/08/29 12:33:15 tb Exp $ */ 1/* $OpenBSD: s_apps.h,v 1.7 2021/12/06 11:06:58 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -119,7 +119,7 @@ extern int verify_depth;
119extern int verify_return_error; 119extern int verify_return_error;
120 120
121int do_server(int port, int type, int *ret, 121int do_server(int port, int type, int *ret,
122 int (*cb)(char *hostname, int s, unsigned char *context), 122 int (*cb)(int s, unsigned char *context),
123 unsigned char *context, int naccept); 123 unsigned char *context, int naccept);
124#ifdef HEADER_X509_H 124#ifdef HEADER_X509_H
125int verify_callback(int ok, X509_STORE_CTX *ctx); 125int verify_callback(int ok, X509_STORE_CTX *ctx);
diff --git a/src/usr.bin/openssl/s_server.c b/src/usr.bin/openssl/s_server.c
index 233b8fdced..9b06856ac9 100644
--- a/src/usr.bin/openssl/s_server.c
+++ b/src/usr.bin/openssl/s_server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s_server.c,v 1.53 2021/10/31 16:47:27 tb Exp $ */ 1/* $OpenBSD: s_server.c,v 1.54 2021/12/06 11:06:58 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -180,13 +180,13 @@
180static void s_server_init(void); 180static void s_server_init(void);
181static void sv_usage(void); 181static void sv_usage(void);
182static void print_stats(BIO *bp, SSL_CTX *ctx); 182static void print_stats(BIO *bp, SSL_CTX *ctx);
183static int sv_body(char *hostname, int s, unsigned char *context); 183static int sv_body(int s, unsigned char *context);
184static void close_accept_socket(void); 184static void close_accept_socket(void);
185static int init_ssl_connection(SSL *s); 185static int init_ssl_connection(SSL *s);
186#ifndef OPENSSL_NO_DH 186#ifndef OPENSSL_NO_DH
187static DH *load_dh_param(const char *dhfile); 187static DH *load_dh_param(const char *dhfile);
188#endif 188#endif
189static int www_body(char *hostname, int s, unsigned char *context); 189static int www_body(int s, unsigned char *context);
190static int generate_session_id(const SSL *ssl, unsigned char *id, 190static int generate_session_id(const SSL *ssl, unsigned char *id,
191 unsigned int *id_len); 191 unsigned int *id_len);
192static int ssl_servername_cb(SSL *s, int *ad, void *arg); 192static int ssl_servername_cb(SSL *s, int *ad, void *arg);
@@ -1531,7 +1531,7 @@ print_stats(BIO *bio, SSL_CTX *ssl_ctx)
1531} 1531}
1532 1532
1533static int 1533static int
1534sv_body(char *hostname, int s, unsigned char *context) 1534sv_body(int s, unsigned char *context)
1535{ 1535{
1536 char *buf = NULL; 1536 char *buf = NULL;
1537 int ret = 1; 1537 int ret = 1;
@@ -1956,7 +1956,7 @@ load_dh_param(const char *dhfile)
1956#endif 1956#endif
1957 1957
1958static int 1958static int
1959www_body(char *hostname, int s, unsigned char *context) 1959www_body(int s, unsigned char *context)
1960{ 1960{
1961 char *buf = NULL; 1961 char *buf = NULL;
1962 int ret = 1; 1962 int ret = 1;
diff --git a/src/usr.bin/openssl/s_socket.c b/src/usr.bin/openssl/s_socket.c
index f22c88d228..db125c1ed3 100644
--- a/src/usr.bin/openssl/s_socket.c
+++ b/src/usr.bin/openssl/s_socket.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s_socket.c,v 1.12 2021/08/29 12:33:15 tb Exp $ */ 1/* $OpenBSD: s_socket.c,v 1.13 2021/12/06 11:06:58 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -75,7 +75,7 @@
75 75
76static int init_server(int *sock, int port, int type); 76static int init_server(int *sock, int port, int type);
77static int init_server_long(int *sock, int port, char *ip, int type); 77static int init_server_long(int *sock, int port, char *ip, int type);
78static int do_accept(int acc_sock, int *sock, char **host); 78static int do_accept(int acc_sock, int *sock);
79 79
80int 80int
81init_client(int *sock, char *host, char *port, int type, int af) 81init_client(int *sock, char *host, char *port, int type, int af)
@@ -131,11 +131,10 @@ init_client(int *sock, char *host, char *port, int type, int af)
131 131
132int 132int
133do_server(int port, int type, int *ret, 133do_server(int port, int type, int *ret,
134 int (*cb) (char *hostname, int s, unsigned char *context), 134 int (*cb)(int s, unsigned char *context),
135 unsigned char *context, int naccept) 135 unsigned char *context, int naccept)
136{ 136{
137 int sock; 137 int sock;
138 char *name = NULL;
139 int accept_socket = 0; 138 int accept_socket = 0;
140 int i; 139 int i;
141 140
@@ -148,15 +147,14 @@ do_server(int port, int type, int *ret,
148 } 147 }
149 for (;;) { 148 for (;;) {
150 if (type == SOCK_STREAM) { 149 if (type == SOCK_STREAM) {
151 if (do_accept(accept_socket, &sock, &name) == 0) { 150 if (do_accept(accept_socket, &sock) == 0) {
152 shutdown(accept_socket, SHUT_RD); 151 shutdown(accept_socket, SHUT_RD);
153 close(accept_socket); 152 close(accept_socket);
154 return (0); 153 return (0);
155 } 154 }
156 } else 155 } else
157 sock = accept_socket; 156 sock = accept_socket;
158 i = (*cb) (name, sock, context); 157 i = cb(sock, context);
159 free(name);
160 if (type == SOCK_STREAM) { 158 if (type == SOCK_STREAM) {
161 shutdown(sock, SHUT_RDWR); 159 shutdown(sock, SHUT_RDWR);
162 close(sock); 160 close(sock);
@@ -227,13 +225,13 @@ init_server(int *sock, int port, int type)
227} 225}
228 226
229static int 227static int
230do_accept(int acc_sock, int *sock, char **host) 228do_accept(int acc_sock, int *sock)
231{ 229{
232 int ret;
233 struct hostent *h1, *h2; 230 struct hostent *h1, *h2;
234 static struct sockaddr_in from; 231 static struct sockaddr_in from;
235 socklen_t len; 232 socklen_t len;
236/* struct linger ling; */ 233 char *host = NULL;
234 int ret;
237 235
238 redoit: 236 redoit:
239 237
@@ -249,47 +247,34 @@ do_accept(int acc_sock, int *sock, char **host)
249 perror("accept"); 247 perror("accept");
250 return (0); 248 return (0);
251 } 249 }
252/* 250
253 ling.l_onoff=1;
254 ling.l_linger=0;
255 i=setsockopt(ret,SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling));
256 if (i == -1) { perror("linger"); return(0); }
257 i=0;
258 i=setsockopt(ret,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
259 if (i == -1) { perror("keepalive"); return(0); }
260*/
261
262 if (host == NULL)
263 goto end;
264 h1 = gethostbyaddr((char *) &from.sin_addr.s_addr, 251 h1 = gethostbyaddr((char *) &from.sin_addr.s_addr,
265 sizeof(from.sin_addr.s_addr), AF_INET); 252 sizeof(from.sin_addr.s_addr), AF_INET);
266 if (h1 == NULL) { 253 if (h1 == NULL) {
267 BIO_printf(bio_err, "bad gethostbyaddr\n"); 254 BIO_printf(bio_err, "bad gethostbyaddr\n");
268 *host = NULL;
269 /* return(0); */
270 } else { 255 } else {
271 if ((*host = strdup(h1->h_name)) == NULL) { 256 if ((host = strdup(h1->h_name)) == NULL) {
272 perror("strdup"); 257 perror("strdup");
273 close(ret); 258 close(ret);
274 return (0); 259 return (0);
275 } 260 }
276 261
277 h2 = gethostbyname(*host); 262 h2 = gethostbyname(host);
278 if (h2 == NULL) { 263 if (h2 == NULL) {
279 BIO_printf(bio_err, "gethostbyname failure\n"); 264 BIO_printf(bio_err, "gethostbyname failure\n");
280 close(ret); 265 close(ret);
281 free(*host); 266 free(host);
282 return (0); 267 return (0);
283 } 268 }
284 if (h2->h_addrtype != AF_INET) { 269 if (h2->h_addrtype != AF_INET) {
285 BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n"); 270 BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
286 close(ret); 271 close(ret);
287 free(*host); 272 free(host);
288 return (0); 273 return (0);
289 } 274 }
290 } 275 }
291 276
292 end: 277 free(host);
293 *sock = ret; 278 *sock = ret;
294 return (1); 279 return (1);
295} 280}