summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-09-18 08:16:38 +0000
committerDamien Miller <djm@mindrot.org>2020-09-18 18:17:59 +1000
commit52a03e9fca2d74eef953ddd4709250f365ca3975 (patch)
treeefbbbd05846e3d3353e59e18c8f7cafbcb86cc5b
parentdc098405b2939146e17567a25b08fc6122893cdf (diff)
upstream: handle multiple messages in a single read()
PR#183 by Dennis Kaarsemaker; feedback and ok markus@ OpenBSD-Commit-ID: 8570bb4d02d00cf70b98590716ea6a7d1cce68d1
-rw-r--r--ssh-agent.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/ssh-agent.c b/ssh-agent.c
index d24a63089..e1fd1f3f6 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-agent.c,v 1.263 2020/08/27 01:06:18 djm Exp $ */ 1/* $OpenBSD: ssh-agent.c,v 1.264 2020/09/18 08:16:38 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -852,8 +852,10 @@ send:
852} 852}
853#endif /* ENABLE_PKCS11 */ 853#endif /* ENABLE_PKCS11 */
854 854
855/* dispatch incoming messages */ 855/*
856 856 * dispatch incoming message.
857 * returns 1 on success, 0 for incomplete messages or -1 on error.
858 */
857static int 859static int
858process_message(u_int socknum) 860process_message(u_int socknum)
859{ 861{
@@ -907,7 +909,7 @@ process_message(u_int socknum)
907 /* send a fail message for all other request types */ 909 /* send a fail message for all other request types */
908 send_status(e, 0); 910 send_status(e, 0);
909 } 911 }
910 return 0; 912 return 1;
911 } 913 }
912 914
913 switch (type) { 915 switch (type) {
@@ -951,7 +953,7 @@ process_message(u_int socknum)
951 send_status(e, 0); 953 send_status(e, 0);
952 break; 954 break;
953 } 955 }
954 return 0; 956 return 1;
955} 957}
956 958
957static void 959static void
@@ -1042,7 +1044,12 @@ handle_conn_read(u_int socknum)
1042 if ((r = sshbuf_put(sockets[socknum].input, buf, len)) != 0) 1044 if ((r = sshbuf_put(sockets[socknum].input, buf, len)) != 0)
1043 fatal("%s: buffer error: %s", __func__, ssh_err(r)); 1045 fatal("%s: buffer error: %s", __func__, ssh_err(r));
1044 explicit_bzero(buf, sizeof(buf)); 1046 explicit_bzero(buf, sizeof(buf));
1045 process_message(socknum); 1047 for (;;) {
1048 if ((r = process_message(socknum)) == -1)
1049 return -1;
1050 else if (r == 0)
1051 break;
1052 }
1046 return 0; 1053 return 0;
1047} 1054}
1048 1055