Bugzilla – Attachment 2536 Details for
Bug 1213
ssh-keyscan exits in mid-way
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
zap more fatal() calls
keyscan-nofatal2.diff (text/plain), 7.63 KB, created by
Damien Miller
on 2015-01-28 22:09:44 AEDT
(
hide
)
Description:
zap more fatal() calls
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2015-01-28 22:09:44 AEDT
Size:
7.63 KB
patch
obsolete
>Index: dispatch.c >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/dispatch.c,v >retrieving revision 1.23 >diff -u -p -r1.23 dispatch.c >--- dispatch.c 19 Jan 2015 20:07:45 -0000 1.23 >+++ dispatch.c 28 Jan 2015 11:07:41 -0000 >@@ -135,6 +135,18 @@ ssh_dispatch_run_fatal(struct ssh *ssh, > { > int r; > >- if ((r = ssh_dispatch_run(ssh, mode, done, ctxt)) != 0) >- fatal("%s: %s", __func__, ssh_err(r)); >+ if ((r = ssh_dispatch_run(ssh, mode, done, ctxt)) != 0) { >+ switch (r) { >+ case SSH_ERR_CONN_CLOSED: >+ logit("Connection closed by %.200s", >+ ssh_remote_ipaddr(ssh)); >+ cleanup_exit(255); >+ case SSH_ERR_CONN_TIMEOUT: >+ logit("Connection to %.200s timed out while " >+ "waiting to read", ssh_remote_ipaddr(ssh)); >+ cleanup_exit(255); >+ default: >+ fatal("%s: %s", __func__, ssh_err(r)); >+ } >+ } > } >Index: opacket.c >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/opacket.c,v >retrieving revision 1.1 >diff -u -p -r1.1 opacket.c >--- opacket.c 19 Jan 2015 19:52:16 -0000 1.1 >+++ opacket.c 28 Jan 2015 11:07:41 -0000 >@@ -253,8 +253,20 @@ packet_read_seqnr(u_int32_t *seqnr) > u_char type; > int r; > >- if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr))) >- fatal("%s: %s", __func__, ssh_err(r)); >+ if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr)) != 0) { >+ switch (r) { >+ case SSH_ERR_CONN_CLOSED: >+ logit("Connection closed by %.200s", >+ ssh_remote_ipaddr(active_state)); >+ cleanup_exit(255); >+ case SSH_ERR_CONN_TIMEOUT: >+ logit("Connection to %.200s timed out while " >+ "waiting to read", ssh_remote_ipaddr(active_state)); >+ cleanup_exit(255); >+ default: >+ fatal("%s: %s", __func__, ssh_err(r)); >+ } >+ } > return type; > } > >@@ -274,4 +286,13 @@ packet_close(void) > { > ssh_packet_close(active_state); > active_state = NULL; >+} >+ >+void >+packet_process_incoming(const char *buf, u_int len) >+{ >+ int r; >+ >+ if ((r = ssh_packet_process_incoming(active_state, buf, len)) != 0) >+ fatal("%s: %s", __func__, ssh_err(r)); > } >Index: opacket.h >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/opacket.h,v >retrieving revision 1.1 >diff -u -p -r1.1 opacket.h >--- opacket.h 19 Jan 2015 19:52:16 -0000 1.1 >+++ opacket.h 28 Jan 2015 11:07:41 -0000 >@@ -44,6 +44,7 @@ void packet_restore_state(void); > void packet_set_connection(int, int); > int packet_read_seqnr(u_int32_t *); > int packet_read_poll_seqnr(u_int32_t *); >+void packet_process_incoming(const char *buf, u_int len); > #define packet_set_timeout(timeout, count) \ > ssh_packet_set_timeout(active_state, (timeout), (count)) > #define packet_connection_is_on_socket() \ >@@ -86,8 +87,6 @@ int packet_read_poll_seqnr(u_int32_t *) > ssh_packet_read(active_state) > #define packet_read_expect(expected_type) \ > ssh_packet_read_expect(active_state, (expected_type)) >-#define packet_process_incoming(buf, len) \ >- ssh_packet_process_incoming(active_state, (buf), (len)) > #define packet_get_int64() \ > ssh_packet_get_int64(active_state) > #define packet_get_bignum(value) \ >Index: packet.c >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/packet.c,v >retrieving revision 1.203 >diff -u -p -r1.203 packet.c >--- packet.c 20 Jan 2015 23:14:00 -0000 1.203 >+++ packet.c 28 Jan 2015 11:07:41 -0000 >@@ -1302,26 +1302,22 @@ ssh_packet_read_seqnr(struct ssh *ssh, u > break; > } > } >- if (r == 0) { >- logit("Connection to %.200s timed out while " >- "waiting to read", ssh_remote_ipaddr(ssh)); >- cleanup_exit(255); >- } >+ if (r == 0) >+ return SSH_ERR_CONN_TIMEOUT; > /* Read data from the socket. */ > do { > cont = 0; > len = roaming_read(state->connection_in, buf, > sizeof(buf), &cont); > } while (len == 0 && cont); >- if (len == 0) { >- logit("Connection closed by %.200s", >- ssh_remote_ipaddr(ssh)); >- cleanup_exit(255); >- } >+ if (len == 0) >+ return SSH_ERR_CONN_CLOSED; > if (len < 0) >- fatal("Read from socket failed: %.100s", strerror(errno)); >+ return SSH_ERR_SYSTEM_ERROR; >+ > /* Append it to the buffer. */ >- ssh_packet_process_incoming(ssh, buf, len); >+ if ((r = ssh_packet_process_incoming(ssh, buf, len)) != 0) >+ return r; > } > free(setp); > return r; >@@ -1775,7 +1771,7 @@ ssh_packet_read_poll_seqnr(struct ssh *s > * together with packet_read_poll. > */ > >-void >+int > ssh_packet_process_incoming(struct ssh *ssh, const char *buf, u_int len) > { > struct session_state *state = ssh->state; >@@ -1785,14 +1781,15 @@ ssh_packet_process_incoming(struct ssh * > state->keep_alive_timeouts = 0; /* ?? */ > if (len >= state->packet_discard) { > if ((r = ssh_packet_stop_discard(ssh)) != 0) >- fatal("%s: %s", __func__, ssh_err(r)); >- cleanup_exit(255); >+ return r; > } > state->packet_discard -= len; >- return; >+ return 0; > } > if ((r = sshbuf_put(ssh->state->input, buf, len)) != 0) >- fatal("%s: %s", __func__, ssh_err(r)); >+ return r; >+ >+ return 0; > } > > int >Index: packet.h >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/packet.h,v >retrieving revision 1.64 >diff -u -p -r1.64 packet.h >--- packet.h 19 Jan 2015 20:30:23 -0000 1.64 >+++ packet.h 28 Jan 2015 11:07:41 -0000 >@@ -90,7 +90,7 @@ void ssh_packet_read_expect(struct s > int ssh_packet_read_poll(struct ssh *); > int ssh_packet_read_poll1(struct ssh *, u_char *); > int ssh_packet_read_poll2(struct ssh *, u_char *, u_int32_t *seqnr_p); >-void ssh_packet_process_incoming(struct ssh *, const char *buf, u_int len); >+int ssh_packet_process_incoming(struct ssh *, const char *buf, u_int len); > int ssh_packet_read_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p); > int ssh_packet_read_poll_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p); > >Index: ssh-keyscan.c >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/ssh-keyscan.c,v >retrieving revision 1.96 >diff -u -p -r1.96 ssh-keyscan.c >--- ssh-keyscan.c 20 Jan 2015 23:14:00 -0000 1.96 >+++ ssh-keyscan.c 28 Jan 2015 11:07:41 -0000 >@@ -301,8 +301,10 @@ tcpconnect(char *host) > memset(&hints, 0, sizeof(hints)); > hints.ai_family = IPv4or6; > hints.ai_socktype = SOCK_STREAM; >- if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) >- fatal("getaddrinfo %s: %s", host, ssh_gai_strerror(gaierr)); >+ if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) { >+ error("getaddrinfo %s: %s", host, ssh_gai_strerror(gaierr)); >+ return -1; >+ } > for (ai = aitop; ai; ai = ai->ai_next) { > s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); > if (s < 0) { >Index: ssherr.c >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/ssherr.c,v >retrieving revision 1.1 >diff -u -p -r1.1 ssherr.c >--- ssherr.c 30 Apr 2014 05:29:56 -0000 1.1 >+++ ssherr.c 28 Jan 2015 11:07:41 -0000 >@@ -125,6 +125,10 @@ ssh_err(int n) > return "KRL file has invalid magic number"; > case SSH_ERR_KEY_REVOKED: > return "Key is revoked"; >+ case SSH_ERR_CONN_CLOSED: >+ return "Connection closed"; >+ case SSH_ERR_CONN_TIMEOUT: >+ return "Connection timed out"; > default: > return "unknown error"; > } >Index: ssherr.h >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/ssherr.h,v >retrieving revision 1.1 >diff -u -p -r1.1 ssherr.h >--- ssherr.h 30 Apr 2014 05:29:56 -0000 1.1 >+++ ssherr.h 28 Jan 2015 11:07:41 -0000 >@@ -73,6 +73,8 @@ > #define SSH_ERR_BUFFER_READ_ONLY -49 > #define SSH_ERR_KRL_BAD_MAGIC -50 > #define SSH_ERR_KEY_REVOKED -51 >+#define SSH_ERR_CONN_CLOSED -52 >+#define SSH_ERR_CONN_TIMEOUT -53 > > /* Translate a numeric error code to a human-readable error string */ > const char *ssh_err(int n);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1213
:
1961
|
1969
|
2000
|
2005
|
2008
|
2016
|
2018
|
2021
|
2057
|
2197
|
2533
|
2536
|
2537
|
2540